// Navigation Menu JavaScript Document
var IE = false;
if (navigator.appName == "Microsoft Internet Explorer") {
	IE = true;
}
var menuTimeoutUntilHide;
var menuAboutToHide;
var menuOrientation;

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"; 
		if(elem.className == "menuBarItem") {
			menuBarItem.style.backgroundColor = menuHoverBackgroundColor;
			menuBarItem.style.backgroundImage = menuHoverBackgroundImage;
			menuBarItem.style.color = menuHoverColor;
			menuBarItem.getElementsByTagName("a")[0].style.color = menuHoverColor;
		}
		//menuBarItem.getElementsByTagName("span")[0].style.color = menuColor;
		
		
		//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";
		}
		var HideRoutine = "document.getElementById('" + subMenuId + "').style.visibility='hidden';"
		if(elem.className == "menuBarItem") {
			HideRoutine += "unHighlight(document.getElementById('" + menuBarItemId + "'));"
		}
		menuTimeoutUntilHide = setTimeout(HideRoutine, 1); 
		menuAboutToHide = subMenuId;
		
		//resume slideshow
		slideshowPause=false;
		
	}
	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;
		if(menuOrientation == "vert")  {
			y = y + elem.offsetHeight;
			x = x - 2*menuBorderSize;
			//document.getElementById(subMenuId).style.width = elem.offsetWidth +"px";
			document.getElementById(subMenuId).style.borderTop = "none";
		} else if(menuOrientation == "horiz") {
			x = x + elem.offsetWidth;
			y = y - menuBorderSize;
			document.getElementById(subMenuId).style.borderLeft = "none";
			//make sure the menu shows up, (if any is below the bottom of the window then flip the menu

		}
		if(IE) {
			y = y + 1;	
			x = x + 2;		
		}
		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) {
	if(elem.className == "menuBarItem") {
		elem.style.backgroundColor = menuHoverBackgroundColor;
		elem.style.backgroundImage = menuHoverBackgroundImage;
		elem.style.color = menuHoverColor;
		try{
		elem.getElementsByTagName("a")[0].style.color = menuHoverColor;
		} catch(e){}
	} else {
		elem.style.backgroundColor = menuSubItemHoverBackgroundColor;
		elem.style.color = menuSubItemHoverColor;
		try{
		elem.getElementsByTagName("a")[0].style.color = menuSubItemHoverColor;
		} catch(e){}
	}
}
function unHighlight(elem) {
	if(elem.className == "menuBarItem") {
		elem.style.backgroundColor = "transparent";
		elem.style.backgroundImage = "none";
		elem.style.color = menuColor;
		elem.getElementsByTagName("a")[0].style.color = menuColor;
	} else {
		elem.style.backgroundColor = menuSubItemBackgroundColor;
		elem.style.color = menuSubItemColor;
		try{
		elem.getElementsByTagName("a")[0].style.color = menuSubItemColor;
		} catch(e){}
	}
}
function hideOtherMenus(menuLength,skipMenu) {
	for(i=1;i<=menuLength;i++)  {
		if(i != skipMenu) {
			popupMenu(document.getElementById("menuBarItem:"+i), false, false);
		}
	}
}


