// 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;

// 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;


// function that turns on the main nav graphics as well as the menus
function menuOn(menu0, menu1, menu2) {
// alert(menu0 + ' ' + menu1);
	// 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"');	
						}
					}
				}
			}
			
			// 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.visibility = "visible"');
				}
				
				// 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";	
						}
					}
				}
			}
			
			// 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		
					styleSheetElement.style.visibility = "visible";
					
				
				}
				
				// 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()", 500);
	}
}

// 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"');	
				}
			}
		}
		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);
							
					// Turn off any currently displayed menu
					oldElement.style.visibility = "hidden";	
				}
			}
		}
	}	
}




// Image replace On Function	
function On(pic) {
	if (document.images) { 
		if ((browser == 'Netscape') && (shortVersion < 5)) 
		{
			document.images[pic].src = eval(pic + 'On.src');
		}
		else
		{
			eval('document.images[pic].src = ' + pic + 'On.src');
		}
	}
}
        

// Image replace Off Function	
function Off(pic) {     
	if(document.images) {
		if ((browser == 'Netscape') && (shortVersion < 5)) 
		{
			document.images[pic].src = eval(pic + 'Off.src');
		}
		else
		{
			eval('document.images[pic].src = ' + pic + 'Off.src');
		}
	}	
}

// Pop-up window function
function windowOpener(url, picWidth, picHeight, scrolling) {
	demoWindow=eval("window.open(url,'newWin','menubar=no,resizable=no,scrollbars="+scrolling+",toolbar=no,height="+picHeight+",width="+picWidth+"')");
}

// Page Changer function
function pageChanger(location) {
	window.opener.location= location;
	window.close();
}
