var tO = null				// time-out variable, must be declared for Netscape 6
var currentlyOn = ""		// set to menu number when menu is turned on, used to ensure visibility of one menu at a time.
var menuDelay = 800			// Represents menu visibility lag time in milliseconds
var blLeftPosnMod = 10		// Sets left margin for highlight and backdrop layers
//var menuItemWidth = 160		// Sets width of backdrop, Should match width of navHighLight as specified in the style sheet
var menuItemHeight = 15		// Sets height increment of backdrop
var startingTop = 85		// Sets the distance from the top to begin drawing the navigation layers
var startingLeft = 207		// Sets the distance from the left to begin drawing the navigation layers
var imgIdPrefix = "nav"

//Specify the number of menus under each category
var menuCat = new Array();
menuCat[0] = 2;
menuCat[1] = 9;
menuCat[2] = 2;
menuCat[3] = 2;
menuCat[4] = 6;

//Set increments by which to space the menus from each other horizontally
var menuPosnVals = new Array(); 
menuPosnVals[0] = 0;
menuPosnVals[1] = 132;
menuPosnVals[2] = 45;
menuPosnVals[3] = 102;
menuPosnVals[4] = 80;

var navLyrs = new Array();
for(i = 0; i < menuCat.length; i++){
	navLyrs[i] = new Array(menuCat[i]);
}

//Creates an array of objects for each Menu under each Category
for(i = 0; i < navLyrs.length; i++){
	thsArray = navLyrs[i];
	for(j = 0; j < thsArray.length; j++){
		thsArray[j] = eval("document." + dotall + getel + "navMenu" + i + "Layer" + j + dotstyle);
	}	
}

//Grabs backdrop and highlight layers as objects
var backLite = eval("document." + dotall + getel + "highLightLayer" + dotstyle);
var backDrop = eval("document." + dotall + getel + "backDropLayer" + dotstyle);

//Keeps the current menu on and closes previously open menus immediately
function clearTo(wMenu){
	if(tO != null){
		clearTimeout(tO);
			if(currentlyOn != wMenu){
				triggerNavOff(currentlyOn);
		}
	}
}

//Delays shutting menu off to give the user time to select an option
//Also turns off highlight layer
function delayedOff(wMenu){
	if(backLite){
		backLite.visibility = "hidden";
	}
	tO = setTimeout("triggerNavOff(" + wMenu + ")", menuDelay);
}

//Turns the menus on
function triggerNavOn(wMenu,wid){
		clearTo(wMenu);
		backDropOn(wMenu,wid);
		thsMenu = navLyrs[wMenu];
		for(i = 0; i < thsMenu.length; i++){
			thsMenu[i].visibility = "visible";
		}
		currentlyOn = wMenu;
		imgId = imgIdPrefix;
		imgId += wMenu;	
		swap(imgId,navOn,wMenu);
}

//Turns the menus and backdrop off.  Only called by other functions.
function triggerNavOff(wMenu){
	thsMenu = navLyrs[wMenu];
	for(i = 0; i < thsMenu.length; i++){
		if(isIE && !isIE4){ //initializes filters
			backDrop.filter = "alpha(opacity=70)";
		}
		thsMenu[i].visibility = "hidden"; 
		backDrop.visibility = "hidden";		
		backLite.visibility = "hidden";
	}
	imgId = imgIdPrefix;
	imgId += wMenu;	
	swap(imgId,navOff,wMenu);	
}

//Positions, sizes and turns on backdrop.  Only called by other functions.
function backDropOn(wMenu,wid){
	getMenu = navLyrs[wMenu];
	rightHeight = getMenu.length * menuItemHeight;
	if(isNav4){
		topVal = getMenu[0].top;
		leftVal = getMenu[0].left;
	} else if(isIE){
		topVal = getMenu[0].pixelTop
		leftVal = getMenu[0].pixelLeft;		
	} else if(isGecko){
		topVal = getMenu[0].top
		leftVal = getMenu[0].left
	}
	bdTop = parseInt(topVal);
	bdLeft = parseInt(leftVal) - blLeftPosnMod;
	backDrop.top = bdTop;
	backDrop.left = bdLeft;
	backDrop.width = wid;
	backDrop.height = rightHeight;
	if(isNav4){
		backDrop.clip.width = wid;
		backDrop.clip.height = rightHeight;
	}
	if(isIE && !isIE4){ //initializes filters
		backDrop.filter = "alpha(opacity=70)";
	}
	backDrop.visibility = "visible";		
}

//Positions and turns on highlight layer.  
function liteItUp(wMenu,wLayer,wid){
	clearTo(wMenu)
	ltLayer = eval("navLyrs[" + wMenu + "][" + wLayer + "]");
	if(isNav4){
		topVal = ltLayer.top;
		leftVal = ltLayer.left;
	} else if(isIE){
		topVal = ltLayer.pixelTop
		leftVal = ltLayer.pixelLeft;		
	} else if(isGecko){
		topVal = ltLayer.top
		leftVal = ltLayer.left
	}
	blTop = parseInt(topVal);
	blLeft = parseInt(leftVal) - blLeftPosnMod;
	backLite.top = blTop;
	backLite.left = blLeft;
	backLite.width = wid;
	if(isNav4){
		backLite.clip.width = wid;
	}
	backLite.visibility = "visible";
}

//Positions the menu item layers on the screen in accordance with values specified above
//Overrides any inline positioning of the layers
//Must be called at the end of the document to work in some browsers
function positionMenus(){
	nextTop = startingTop
	nextLeft = startingLeft;
	for(i = 0; i < menuPosnVals.length; i++){
		currentMenu = navLyrs[i];
		nextLeft = nextLeft + menuPosnVals[i];
		for(j = 0; j < currentMenu.length; j++){ 
			nextTop = nextTop + menuItemHeight;
			currentMenu[j].left = nextLeft;
			currentMenu[j].top = nextTop;			
		}
		nextTop = startingTop
	}
}