// Browser & Platform Variables
var platform = navigator.platform.substr(0,3);
var browser = navigator.appName;
var shortVersion = navigator.appVersion.substr(0,1);
var longVersion = navigator.appVersion;
var userAgent = navigator.userAgent;

//ripped from the ultimate browser sniffer
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;


// Variables needed for Rollovers
var finished = 'yes';
var over = 'no';

var styleSheetElement;
var oldElement;
var mainMenu = 'none';
var subOne = 'none';
var subTwo = 'none';
var subElement;
var oldSub;
var initial = 0;
var currentTop;
var lastDisplayedMenu;
currentMenus = new Array(2)
lastDisplayed = new Array(2)
var subLevels = 3;
var beenCalled;

var menuOffset = 0;
var contentWidth = 800;

//var availWidth = screen.availWidth;
//alert("Width: " + document.body.clientWidth);

// adjust left edge of pop-up menus for Safari browsers
if ((is_safari)) {
	function getStartLeft() {
		if((retVal = ((document.body.clientWidth - contentWidth) / 2) + 8) > 0) {
			return retVal;
		} else {
			return 0;
		}
	}
}
else {
	function getStartLeft() {
		if((retVal = ((document.body.clientWidth - contentWidth) / 2)) > 0) {
			return retVal;
		} else {
			return 0;
		}
	}
}

//799EC7

// function that turns on the main nav graphics as well as the menus
function menuOn(menu0, menu1, menu2) {
	// Make sure the page has loaded
	if (finished == 'yes') {
	
		//gather the names of all the menus that you want on into the currentMenus Array
		for (var i = 0; i < subLevels; i++) {
			eval('currentMenus[' + i + '] = menu' + i + ';');
		}

		// set over to show that the user is now over a menu
		over = 'yes';
		
		// check to see if the user is on a non wc3 css compliant browser(i.e Netscape4.x
		if ((browser == 'Netscape') && (shortVersion < 5)) {
		
			// This section of code is executed for non wc3 css compliant browsers
			
			// Execute the following if this is not the first time this function has been called
			if (beenCalled == 'yes')  {
				// Loop used to turn on all menus held within the currentMenus array
				for (var i = 0; i < subLevels; i++) {
					
					if((lastDisplayed[i]) && (lastDisplayed[i] != 'none')) {
						if ((i == 0) && (menu0 != lastDisplayed[0]) || (i != 0)) { 
							// Turn off any currently displayed menu
							eval('document.' + lastDisplayed[i] + 'Menu.visibility = "hidden"');	
							//eval('document.' + lastDisplayed[i] + 'Link.background-color = "none"');	
							//document.images[currentMenus[i]].src = eval(currentMenus[i] + 'Off.src');
						}
					}
				}
			}
			
			// Loop used to turn on all menus held within the currentMenus array
			for (var i = 0; i < subLevels; i++) {
				if(currentMenus[i] != 'none') {
	
					// Turn on the menu(s) which need now need to be displayed
					eval('document.' + currentMenus[i] + 'Menu.left = menuOffset + ' + getStartLeft() + ' + "px"');
					//eval('document.' + currentMenus[i] + 'Link.background-color = "#799EC7"');
					eval('document.' + currentMenus[i] + 'Menu.visibility = "visible"');
					//document.images[currentMenus[i]].src = eval(currentMenus[i] + 'On.src');
				}
				
				// set lastDisplayed Array to hold names of menus turned on for use next time function is called
				lastDisplayed[i] = currentMenus[i];
			}
		}
		else {
			
			// This section of code is executed for wc3 css compliant browsers
			
			// Execute the following if this is not the first time this function has been called
			if (beenCalled == 'yes')  {
			
				// Loop used to turn on all menus held within the currentMenus array
				for (var i = 0; i < subLevels; i++) {
					
					if((lastDisplayed[i]) && (lastDisplayed[i] != 'none')) {
						if ((i == 0) && (menu0 != lastDisplayed[0]) || (i != 0)) { 
							
							// These lines gather the menu element which we want to access
							lastDisplayedMenu = lastDisplayed[i] + 'Menu';
							oldElement = document.getElementById(lastDisplayedMenu);
							
							// Turn off any currently displayed menu
							oldElement.style.visibility = "hidden";	
							
							//eval('document.images[lastDisplayed[i]].src = ' + lastDisplayed[i] + 'Off.src');
							//lastLink = lastDisplayed[i] + 'Link';
							//oldMenuLink = document.getElementById(lastLink);
							//oldMenuLink.style.background = "none";
						}
					}
				}
			}
			
			// Loop used to turn on all menus held within the currentMenus array
			for (var i = 0; i < subLevels; i++) {
				if(currentMenus[i] != 'none') {
				
					// These lines gather the menu element which we want to access
					layerName = currentMenus[i] + 'Menu';
					
					styleSheetElement = document.getElementById(layerName);	
					
					// Turn on the menu(s) which need now need to be displayed	
					//eval('document.images[currentMenus[i]].src = ' + currentMenus[i] + 'On.src');		
					styleSheetElement.style.left = eval('menuOffset') + getStartLeft() + "px";
					styleSheetElement.style.visibility = "visible";
					
					//newLink = currentMenus[i] + 'Link';
					//linkElement = document.getElementById(newLink);
					//linkElement.style.background = "#799EC7";
				}
				
				// set lastDisplayed Array to hold names of menus turned on for use next time function is called
				lastDisplayed[i] = currentMenus[i];	
			}	
		}
		beenCalled = 'yes';
	}
}


// Timer function that is run to give the user time to get to the menu from the button
function overChecker(menu0, menu1, menu2) {
	// alert('overchecker');
	if ((over == 'yes') && (finished == 'yes')) {
	
		//gather the names of all the menus that you want on into the currentMenus Array
		for (var i = 0; i < subLevels; i++) {
			eval('lastDisplayed[' + i + '] = menu' + i + ';');
		}
		over = 'no';
		setTimeout("menuOff()", 900);
	}
}

// function that turns off the main nav graphics as well as the menus
function menuOff() {
	
	if (over == 'no')  {
			
		if ((browser == 'Netscape') && (shortVersion < 5)) {
			for (var i = 0; i < subLevels; i++) {
				if((lastDisplayed[i]) && (lastDisplayed[i] != 'none')) {
				
				// Turn off any currently displayed menu
				eval('document.' + lastDisplayed[i] + 'Menu.visibility = "hidden"');	
				//eval('document.' + lastDisplayed[i] + 'Link.background-color = "none"');
				//document.images[lastDisplayed[i]].src = eval(lastDisplayed[i] + 'Off.src');
				}
			}
		}
		else {
			// upMenu();
			for (var i = 0; i < subLevels; i++) {
				if((lastDisplayed[i]) && (lastDisplayed[i] != 'none')) {
					// These lines gather the menu element which we want to access			
					lastDisplayedMenu = lastDisplayed[i] + 'Menu';
					// alert(lastDisplayedMenu);
					oldElement = document.getElementById(lastDisplayedMenu);
					//eval('document.images[lastDisplayed[i]].src = ' + lastDisplayed[i] + 'Off.src');		
					// Turn off any currently displayed menu
					oldElement.style.visibility = "hidden";	
					
					//lastLink = lastDisplayed[i] + 'Link';
					//oldMenuLink = document.getElementById(lastLink);
					//oldMenuLink.style.background = "none";
					
				}
			}
		}
	}	
}