$(document).ready(function(){
	$("#navigation li").hover(
		function(){ $("ul", this).fadeIn("fast"); }, 
		function() { } 
	);
	if (document.all) {
		$("#navigation li").hoverClass ("sfHover");
	}
	
	$("#map div").mouseover(function(){
		doShowNavigation = false;
		showNavigation(this.id)
	});
	$("#map ul").mouseover(function(){
		doShowNavigation = true;
	});
	$("#map div").mouseout(function(){
		doShowNavigation = false;
		hideNavigation("ul"+this.id)
	});
	$("#map ul").mouseout(function(){
		doShowNavigation = false;
		hideNavigation(this.id)
	});
	
	$("#topnavigation li").mouseover(function(){
		$(this).next().children().css("background-image","none");
	  	if ($(this).attr("class")!="first") {
			$(this).children().css("background-image","none");		
		}
	})
	$("#topnavigation li").mouseout(function(){
	  	if ($(this).attr("class")!="active") {
			$(this).next().children().css("background-image","url(/ISBD/wGlobal/layout/images/bg_navigation.gif)");
			if (($(this).attr("class")!="first" && $(this).attr("class")!="first active") && $(this).prev().attr("class")!="active") {
				$(this).children().css("background-image","url(/ISBD/wGlobal/layout/images/bg_navigation.gif)");
			}
		}
	})
	$("#topnavigation li.active").next().children().css("background-image","none");
	
	$("#sitemap ul ul li").click(function() {
		if (!$(this).hasClass("nochildren")) {
			$(this).children("ul").toggle();
			if ($(this).attr("class").indexOf("closed")>-1) {
				$(this).removeClass("closed");
				$(this).addClass("open");
			}else{
				$(this).removeClass("open");
				$(this).addClass("closed");
			}
			setSitemapHeight()
			$(".wglPortlet").css("overflow", "visible");
		}
		return false;
	});
	$("#sitemap ul ul li a").click(function() {
		location.href=$(this).attr("href");
	});
	
	if (document.getElementById("history") && !document.forms["frmContent"]) {
		loadHistoryYear('1961');			
	}
	$("#history td a").click(function() {
		loadHistoryYear($(this).text().trim());
	});
});

$.fn.hoverClass = function(c) {
	return this.each(function(){
		$(this).hover( 
			function() { $(this).addClass(c);  },
			function() { $(this).removeClass(c); }
		);
	});
};

function setSitemapHeight() {
	//sitemapHeight = $(".sitemap1").height()+$(".sitemap2").height()+15;
	/*if ($(".sitemap3").height()>sitemapHeight) {
		sitemapHeight = $(".sitemap3").height();
	}		
	if ($(".sitemap4").height()>sitemapHeight) {
		sitemapHeight = $(".sitemap4").height();;
	}*/
	var intHeightLeft 	= $("#sitemapLeft").height();
	var intHeightRight 	= $("#sitemapRight").height();
	sitemapHeight = (intHeightLeft <= intHeightRight ) ?intHeightRight : intHeightLeft;	
	$("#sitemap").height(sitemapHeight);
}

//var doShowNavigation = false;
function showNavigation(div) {
	doShowNavigation = true;
	window.setTimeout(function(){
		showShowNavigation(div)
	},100);
}
function showShowNavigation(div) {
	$("#map ul").hide();
	if (doShowNavigation) {
		$("#ul"+div).show();
		$("#ul"+div+"2").show();
	}
}
function hideNavigation(div) {
	doShowNavigation = false;
	window.setTimeout(function(){
		hideHideNavigation(div)
	},100);
}
function hideHideNavigation(div) {
	if (!doShowNavigation) {
		$("#map ul").hide();
	}
}

function addBookmark() {
	if (window.sidebar) { 
		window.sidebar.addPanel(document.title, location.href,""); 
	} else if( document.all ) {
		window.external.AddFavorite( location.href, document.title);
	} else if( window.opera && window.print ) {
		return true;
	}
}


function loadHistoryYear(year) {
	$.ajax({ 
	type: "GET",
	url: '../../aboutus/history/years/'+year+'.php',
	success: function(text)
	{ 
		$("#historyyear").html(text);
	}
	});
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

