$(document).ready(function() {

    // Check if image src is empty and then remove
    $('img').each(function() {
        var testing = $(this).attr("src");
        if (!testing) {
            $(this).remove();
        }
    });

    $('#contentRight').each(function() {
        $(this).find(".rightBox:not(.rightBoxNoJs):last").addClass("last");
    });
    
    $('.sectorsAndSections').each(function() {
    $(this).find(".headDetails:nth-child(4), .headDetails:nth-child(5), .headDetails:nth-child(6)").addClass("space");
    });
    
    // Temporary
    $(".fIPDetails li:nth-child(3), .boxRight li:nth-child(3)").addClass('last');
    // Temporary end


    //min side dropdown
    var topnav = $('#master div.topnav'),
		loginBox = $('#loginBox .loginBox').slideUp(0),
		topnavLinks = topnav.find('> ul > li'),
		mypageLi = topnavLinks.filter('.mypageNoLogedIn');

    mypageLi.find('> a').toggle(
		function() {
		    $(this).addClass('selected');
		    loginBox.slideDown(300);
		},
		function() {
		    $(this).removeClass('selected');
		    loginBox.slideUp(300);
		});


    // Topnav slide up/down
    topnavLinks.filter(':not(.mypage)')
		.each(function() {
		    $(this).attr('h', $(this).find('> div').height());
		    $(this).find('> div').height(0);
		})
		.hover(
			function() {
			    var elm = $(this).addClass('hover');
			    elm.find('> div').stop(true, true).animate({
			        height: elm.attr('h')
			    }, 240).show();
			},
			function() {
			    var elm = $(this).removeClass('hover');
			    elm.find('> div').stop(true, true).animate({
			        height: 0
			    }, 240).hide();
			}
		);
	
	var $fields = loginBox.find('input[type=password]');	
	$fields.bind('keypress', function(e) {
		var code = (e.keyCode ? e.keyCode : e.which);
		if(code == 13) { //Enter keycode
			if ( $fields.eq(0).val() != '' && $fields.eq(1).val() != '' )
			{
				// Do submit when fields isn't empty
				SslLogin();
			}
		}
	});


    //	ieMenusHack();
    var menuOpenIdPrev = "MenuNeverHasBeenOpenedBefore";

    $(".btnMenuToggle").hover(function() {
        $(this).addClass("btnMenuToggleHover");
    }, function() {
        $(this).removeClass("btnMenuToggleHover");
    });

    $("#topMenuDiv > ul >li").hover(
      function() {

      },
      function() {
          $(this).removeClass("mover");
          if ($.browser.msie) {
              $("#selToYou").css({ visibility: "visible" })
              $("#selQuickAccess").css({ visibility: "visible" })
          }
      }
);

    $(".btnMenuToggle").mouseover(function() {
        if ($(this).parent().is(":has(ul)")) {
            $(this).parent().addClass("mover");
            if ($.browser.msie) {
                $("#selToYou").css({ visibility: "visible" })
                $("#selQuickAccess").css({ visibility: "visible" })
                if ($(this).parent().parent().attr("id") == "topSubMenu1") {
                    $("#selToYou").css({ visibility: "hidden" })
                    $("#selQuickAccess").css({ visibility: "visible" })
                } else {
                    $("#selToYou").css({ visibility: "visible" })
                    $("#selQuickAccess").css({ visibility: "hidden" })
                }
            }
        }
    })




    try {
        $('.boxContentTxt1 p, .boxContentTxt2 p, .boxContentTxt3 p').equalHeight();
    }
    catch (e) {
    }
    var qs = document.location.search;
    if (qs.indexOf('?iframeSrc=') > -1) {
        if (qs.indexOf('?iframeSrc=current') == -1) {
            resizeIframe('externalFrame');
            LoadIFrame(qs.replace('?iframeSrc=', ''));
        }
        else {
            resizeIframe('externalFrame');
            LoadIFrame($('a.iframe')[0].href);
        }
    }

    $('a.iframe').click(function() {
        if (document.location.pathname == '/') {
            document.location.href = this.href;
        }
        else {
            resizeIframe('externalFrame');
            LoadIFrame($(this).attr('href'));
        }

        return false;
    });


    iFrameExternal = document.getElementById('externalFrame');

    if (iFrameExternal != null) {
        heightLeftContent = $("#leftContent").height();
        heightContentLeft = $("#contentLeft").height();

        //		alert(heightLeftContent + "  " + heightContentLeft)

        if (heightLeftContent < heightContentLeft) {
            $("#externalFrame").css({ marginLeft: "230px" });
        }
        //		$("#externalFrame").
    } else {
    }

    //	alert($("#externalFrame").index());
    /*	
    if($("externalFrame")){
    alert("yupii");
    }else{
    alert("ioi")	
    }
    */

	$('#facebookStudentsFeed').fbWall({
		id: '125728577441733',
		accessToken: 'AAAC7gAoWDQ0BAOZCvALBj10m2uDmZCk5xkfxZBiriMHcJZBl8eKAwPylZCzHE6VoL5XeozuwS0wfQYOK9qpJxJfyRW2WyQQ0ZD',
		showGuestEntries: true,
		showComments: true,
		max: 5,
		timeConversion: 24
	});

});

function LoadIFrame(url)
{
	try {
//		$('div#content').children().css({display: 'none'});
//		$('iframe#externalFrame').css({display: 'block'});
//		$('iframe#externalFrame')[0].src = url;
		
		if($('#contentRight')[0]){
		//debugger;
			$('#contentRight').css({display: 'none'});
			$('iframe#externalFrame')[0].style.width = $('div#content').width() - 30 + 'px';
		}
		if($('#resultsList')[0]){$('#resultsList').css({display: 'none'});}
		if($('#content h1')[0]){$('#content h1').css({display: 'none'});}
		if($('#teaserLine')[0]){$('#teaserLine').css({display: 'none'});}
		$('iframe#externalFrame')[0].src = url;
		$('iframe#externalFrame').css({display : 'block'});
	}
	catch(e) {
	}
}

function resizeIframe(id)
{
	var height = $('div#leftContent').height();
	if($('iframe#externalFrame')[0] && height)
	    {$('iframe#externalFrame')[0].style.height = height + 'px';}
}



