// Navigation Menu JavaScript Document
var IE = false;
if (navigator.appName == "Microsoft Internet Explorer") {
	IE = true;
}
var menuTimeoutUntilHide;
var menuAboutToHide;
var NavItemColor = '#000000';
var NavItemHoverColor = '#FFFFFF';
var NavItemHoverBackgroundColor = '#626469';
var NavItemHoverBackgroundImage = 'url(/images/navoverbg.gif)';
function popupMenu(elem, show, align)
{	
	subMenuId = "menuItem:"+elem.getAttribute("id").split(":")[1];
	menuBarItemId = "menuBarItem:"+elem.getAttribute("id").split(":")[1];
	menuBarItem= document.getElementById(menuBarItemId);
	var menu = document.getElementById(subMenuId); 
	if(show) {
		if(IE)  {
				var iframe = document.getElementById("magicIFrame");
				iframe.style.zIndex = "1";
				iframe.style.visibility = "visible";
		}
		menu.style.visibility = "visible"; 
		
		menuBarItem.style.color = NavItemHoverColor;
		menuBarItem.getElementsByTagName("a")[0].style.color = NavItemHoverColor;
		menuBarItem.style.backgroundColor = NavItemHoverBackgroundColor;
		menuBarItem.style.backgroundImage = NavItemHoverBackgroundImage;
		
		//Since this site also has a slide show we need to pause it
		slideshowPause=true;
		
		//if there is currently a timeout for the popup to hide clear it so it won't flicker
		//but only if it is the same menu
		if(subMenuId == menuAboutToHide)
		{
			clearTimeout(menuTimeoutUntilHide);
		}
	}
	else {
		if(IE)  {
				var iframe = document.getElementById("magicIFrame");
				iframe.style.zIndex = "-1";
				iframe.style.visibility = "hidden";
		}
		menuTimeoutUntilHide = setTimeout("document.getElementById('" + subMenuId + "').style.visibility='hidden';document.getElementById('" + menuBarItemId + "').style.backgroundColor='';", 1); 
		menuAboutToHide = subMenuId;
		
		//resume slideshow
		slideshowPause=false;
		
		menuBarItem.style.color = NavItemColor;
		menuBarItem.getElementsByTagName("a")[0].style.color = NavItemColor;
		menuBarItem.style.backgroundColor = 'transparent';
		menuBarItem.style.backgroundImage = 'none';
		
	}
	if(align) {
		var parent = elem;
		var x = 0;
		var y = 0;
		//var trace = "";
		while(parent != document.body)	{
			//trace +=  parent.tagName + "(" + parent.offsetLeft + "," + parent.offsetTop + ")" + "\n";
			x = x + parent.offsetLeft;
			y = y + parent.offsetTop;
			parent = parent.offsetParent;
		}
		x = x + parent.offsetLeft;
		y = y + parent.offsetTop;
		//x = x + elem.offsetWidth + 2;
		y = y + elem.offsetHeight;
		//menu.style.padding = "5px";
		menu.style.left = x -1 + "px";
		menu.style.top = y + "px";
		if(IE)  {
				var iframe = document.getElementById("magicIFrame");	
				iframe.style.top = menu.style.top;
				iframe.style.left = menu.style.left;
				iframe.style.width = menu.offsetWidth;
				iframe.style.height = menu.offsetHeight;
		}
	}
}

function highlight(elem) {
	elem.style.backgroundColor = NavItemHoverBackgroundColor;
	elem.style.color = NavItemHoverColor;
	elem.getElementsByTagName("a")[0].style.color = NavItemHoverColor;
}
function unHighlight(elem) {
	elem.style.backgroundColor = 'transparent';
	elem.style.color = NavItemColor;
	elem.getElementsByTagName("a")[0].style.color = NavItemColor;
}
function hideOtherMenus(menuLength,skipMenu) {
	for(i=1;i<=menuLength;i++)  {
		if(i != skipMenu) {
			popupMenu(document.getElementById("menuBarItem:"+i), false, false);
		}
	}
}