var displayTime = 0;
var lastMenu = 0;
var layerTimer;
var opac = 0;
var curMenu = 0;
var agt = navigator.userAgent.toLowerCase();
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));

//browser detection
var browserType

if (document.all) { browserType = "IE" } //ie
else if (document.getElementById){ browserType = "NS6" } //ns6: mozilla, firefox
else if (document.layers) { browserType = "NS4" } //ns4


function showMenu(sltMenu) {
	displayTime = 0;
	opac = 0;
	curMenu = sltMenu;
	
	
	if (is_ie && formPage)
	{
		//hide form elements that interfere with the menu
		eval("document.getElementById('ddPID').style.visibility ='hidden'");				
	}
			
		
	if((document.getElementById(sltMenu).style.visibility == 'visible')  && (sltMenu == lastMenu))
	{
		clearTimeout(layerTimer);
		return;
	}
	
	// hide menus that do not need to be shown before displaying the new menu
	// Note: do not hide any menus if the current selected menu (sltmenu) is equivalent to the last selected menu 
	// or if it is a menu on the third level
	if(sltMenu != lastMenu && lastMenu != 0 && sltMenu != "menu1a" && sltMenu != "menu4a")
	{
		eval("document.getElementById('" + lastMenu + "').style.visibility ='hidden'");
	}
		
	// display new menu
	fadeIn();
	
	lastMenu = sltMenu;			// store the current selected menu so that we can hide it later
	clearTimeout(layerTimer);	// reset the timer since we want the current menu to be displayed for the full specified time
	
	return;
}

function hideMenu(menuId) {

		if(displayTime < 1) { // This code causes 1 increment of the below 500 ms to occur before hidding anything
			displayTime++;
		}
		else { // hide all menus
			
			eval("document.getElementById('" + menuId + "').style.visibility = 'hidden'");	
			
			displayTime = 0;
			opac = 0;
			
		
			if (is_ie && formPage){
				//hide form elements that interfere with the menu
				eval("document.getElementById('ddPID').style.visibility ='visible'");				
			}
	
			
		}
		layerTimer=setTimeout("hideMenu('"+menuId+"')", 200); // call hideMenu again after 500 ms have gone by
}

function resetTimer() {
	displayTime = 0;
	clearTimeout(layerTimer);
}

// adds fade in effect to the displaying of the div tag
function fadeIn() {
	eval("document.getElementById('" + curMenu + "').style.visibility = 'visible'");
	if(opac < 96){
		opac+=32;
		eval("document.getElementById('" + curMenu + "').style.filter='alpha(opacity = " + opac + ")'");
		setTimeout('fadeIn()', 1);
	}
}

