//
// Menu navigation
//

var ns4;
var ie4;
var ns6;

NUM_MAIN_MENUS = 6;
NUM_SUB_MENUS = 6;
NUM_SUB_SUB_MENUS = 12;

var currentMenu = "";

function isBrowser(b,v)
{
	/*
	** Check if the current browser is compatible
	**  b  browser name
	**  v  version number (if 0 don't check version)
	** returns true if browser equals and version equals or greater
	*/
	browserOk = false;
	versionOk = false;
	
	browserOk = (navigator.appName.indexOf(b) != -1);
	if (v == 0) versionOk = true;
	else  versionOk = (v <= parseInt(navigator.appVersion));
	return browserOk && versionOk;
}


// Test for which browser
if (isBrowser('Netscape', 4)) ns4 = true;
if (document.all) ie4 = true;
if ((document.getElementById) && (!document.all)) ns6 = true;
if (ns6 == true) ns4 = false;

// Number of seconds since last menu clear:
var menusCleared = 0;
// Number of seconds of idle time before clearing menus:
var MENU_START_TIME = 6;

function checkClearMenus()
{
	if (menusCleared > 0) {
		menusCleared--;
		if (menusCleared == 0) {
			clearAll(currentMenu);
		}
	}
}

function InitMenus(path, curMenu)
{
	// Save this for clearing purposes:
	currentMenu = curMenu;
}

var windowTimerFunc = window.setInterval("checkClearMenus()", 1000);

function showLayer(which)
{
	if (ie4) {
		document.all[which].style.visibility = "visible";
	}
	if (ns6) {
		document.getElementById(which).style.visibility = "visible";
	}
	if (ns4) {
		document.layers[which].visibility = "show";
	}
}

function hideLayer(which)
{
	if (ie4) {
		document.all[which].style.visibility = "hidden";
	}
	if (ns6) {
		document.getElementById(which).style.visibility = "hidden";
	}
	if (ns4) {
		document.layers[which].visibility = "hide";
	}
}

function hideAllSubMenus()
{
	for (i = 0;  i < NUM_SUB_MENUS;  i++) {
		hideLayer("submenu_" + i);
	}
}

function hideAllSubSubMenus()
{
	for (i = 0;  i < NUM_SUB_SUB_MENUS;  i++) {
		hideLayer("subsubmenu_" + i);
	}
}

function clearAll(menuNum)
{
	hideAllSubMenus();
	hideAllSubSubMenus();
	menusCleared = 0;
}

function clearAllWithSubmenu(menuNum)
{
	hideAllSubMenus();
	hideAllSubSubMenus();
	menusCleared = 0;
}

function showSubMenu(menuNum)
{
	// First, unhilite the other menus and hide the sub-menus:
	clearAllWithSubmenu(menuNum);
	menusCleared = MENU_START_TIME;
	
	// Show the selected sub-menu:
	showLayer("submenu_" + menuNum);
}

function showSubSubMenu(menuNum)
{
	// First, unhilite the other menus and hide the sub-menus:
	hideAllSubSubMenus();
	menusCleared = MENU_START_TIME;
	
	// Show the selected sub-menu:
	showLayer("subsubmenu_" + menuNum);
}

function newImage(arg) 
{
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() 
{
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages(path) {
	//if (document.images) {
		nav0_over = newImage(path + "images/nav0_over.png");
		nav1_over = newImage(path + "images/nav1_over.png");
		nav2_over = newImage(path + "images/nav2_over.png");
		nav3_over = newImage(path + "images/nav3_over.png");
		nav4_over = newImage(path + "images/nav4_over.png");
		nav5_over = newImage(path + "images/nav5_over.png");
		go_over = newImage(path + "images/go_on.gif");
		preloadFlag = true;
	//}
}

