// 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 to Print out Font Class Styles For All Browsers

function fontStyles() {
	document.write('<style type="text/css">\n')
	for (var i = 0; i < pageStyles.length; i++) {
		for (var j = 0; j < eval('pageStyles[' + i + '].length;'); j++) {
			if(pageStyles[i][j]) {
				if(j==0) {
					document.write('.' + pageStyles[i][j] + ' { ');
				} else if (j==1) {
					document.write('color : ' + pageStyles[i][j] + '; ');
				} else if(j==2) {
					var fontSize = pageStyles[i][j];
					newSize =Number(fontSize);
					if (platform == 'Mac') {
						if (((browser == 'Microsoft Internet Explorer') && (longVersion != '4.0 (compatible; MSIE 5.0; Macintosh; I; PPC)')) || ((browser == 'Netscape') && (shortVersion < 5))) {
							newSize = newSize + 3;
						} else if ((browser == 'Netscape') && (shortVersion < 7)) {
							// newSize = newSize + 2;
						} 
					}
					document.write('font : ' + newSize + 'pt');
				} else if(j==3) {
					document.write('/' + pageStyles[i][j] + '');
				} else if(j==4) {
					document.write(' ' + pageStyles[i][j] + '');
				} else if(j==5) {
					document.write('; text-decoration : ' + pageStyles[i][j] + '; ');
				} else if(j==6) {
					document.write('font-weight : ' + pageStyles[i][j] + '; ');
				} else if(j==7) {
					document.write('background-color : ' + pageStyles[i][j] + '; ');
				} else if(j==8) {
					document.write('padding: ' + pageStyles[i][j] + '; ');
				}
			}
		}
		document.write('}\n\n');
	}
	document.write('</style>\n\n');
	return true;	
}


fontStyles();


racingOn = new Image();
racingOn.src = "/images/nav_1_over.jpg";
racingOff = new Image();
racingOff.src = "/images/nav_1.jpg";

eventsOn = new Image();
eventsOn.src = "/images/nav_2_over.jpg";
eventsOff = new Image();
eventsOff.src = "/images/nav_2.jpg";

newsOn = new Image();
newsOn.src = "/images/nav_3_over.jpg";
newsOff = new Image();
newsOff.src = "/images/nav_3.jpg";

galleryOn = new Image();
galleryOn.src = "/images/nav_4_over.jpg";
galleryOff = new Image();
galleryOff.src = "/images/nav_4.jpg";

linksOn = new Image();
linksOn.src = "/images/nav_5_over.jpg";
linksOff = new Image();
linksOff.src = "/images/nav_5.jpg";

// 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"');
							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.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');
						}
					}
				}
			}
			
			// 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";
					eval('document.images[currentMenus[i]].src = ' + 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];	
			}	
		}
		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()", 300);
	}
}

// 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"');	
				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";	
				}
			}
		}
	}	
}


// Image replace On Function	
function on(pic) {
	eval('document.images[pic].src = ' + pic + 'On.src');
}
        

// Image replace Off Function	
function off(pic) {
	eval('document.images[pic].src = ' + pic + 'Off.src');
}
