//	Javascript show and hide the menus defined for most common browsers.

 var formPage 
 //on pages where a select box interferes with the javascript menus, this value is set to true 
 formPage = false 
 
var displayTime = 0;
var lastNav = 0;
var layerTimer;
var opac = 0;
var curNav = 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 showNav(sltNav, which) {
	var tweakXposition = 0;
	var tweakYposition = 0;
	displayTime = 0;
	opac = 0;	
	
	curNav = sltNav;
	
	
	if (is_ie && formPage){
		//hide form elements that interfere with the menu
		eval("document.getElementById('ddPID').style.visibility ='hidden'");				
	}
			
		
	if((document.getElementById(sltNav).style.visibility == 'visible')  && (sltNav == lastNav)) {
		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(sltNav != lastNav && lastNav != 0) {

		eval("document.getElementById('" + lastNav + "').style.visibility ='hidden'");

		//hide 2nd level menus that link to a 3rd level menu
		//eval("document.getElementById('menu1').style.visibility ='hidden'");
	}
	//get position of the originating anchor tag in order to solidify the positioning menus for non-IE browsers.
	if(which != 0) {
		varcoords = getAnchorPosition(which);
		
		//add minor positional tweak for non-IE browser
		if(browserType != "IE") {
			tweakXposition = 0;
		}
		eval("document.getElementById('" + sltNav + "').style.left = varcoords.x + 180 + tweakXposition");
		eval("document.getElementById('" + sltNav + "').style.top = varcoords.y - 1");	
	}
	else
		varcoords = 0;
		
	// display new menu
	fadeIn();
	
	lastNav = sltNav;			// 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 hideNav(divid,timerlength) {

		if(displayTime < 1) { // This code causes 1 increment of the below 500 ms to occur before hiding anything
			displayTime++;
		}
		else { // hide all menus
			//eval("document.getElementById('content-nav-sub-region-us').style.visibility ='hidden'");
			eval("document.getElementById(divid).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("hideNav('"+ divid +"',"+timerlength+")", 200); // call hideNav 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() {
//alert(curNav);
	eval("document.getElementById('" + curNav + "').style.visibility = 'visible'");
	if(opac < 96){
		opac+=32;
		eval("document.getElementById('" + curNav + "').style.filter='alpha(opacity = " + opac + ")'");
		setTimeout('fadeIn()', 1);
	}
}
