var good2go = false			// Initializes variable for menu go-ahead check

var navLyrs = new Array();
for(i = 0; i < menuInventory.length; i++){
	navLyrs[i] = new Array(menuInventory[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);

//Powers image rollovers
function swap(imgName,imgArray,imgNum){
	document[imgName].src = imgArray[imgNum].src;
}

//Keeps the current menu on and closes previously open menus immediately
function clearTo(wMenu){
	if(good2go == true){
		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(good2go == true){
		if(backLite){
			backLite.visibility = "hidden";
		}
		tO = setTimeout("triggerNavOff(" + wMenu + ")", menuDelay);
	}
}

//Turns the menus on 
//Optional Parameter: wLen = integer representing desired menu width in pixels
function triggerNavOn(wMenu,wLen){
	if(good2go == true){
		clearTo(wMenu);
		cMenu = "lnav" + wMenu;
		swap(cMenu,lnavOn,wMenu);
		if(wLen){
			if(isNav4){
				backLite.clip.width = wLen;
			} else {
				backLite.width = wLen;
			}
		}
		backDropOn(wMenu,wLen);
		thsMenu = navLyrs[wMenu];
		for(i = 0; i < thsMenu.length; i++){
			thsMenu[i].visibility = "visible";
		}
		currentlyOn = wMenu;
	}
}

//Turns the menus and backdrop off.  Only called by other functions.
function triggerNavOff(wMenu){
	if(good2go == true){
		cMenu = "lnav" + wMenu;
		swap(cMenu,lnavOff,wMenu);
		thsMenu = navLyrs[wMenu];
		for(i = 0; i < thsMenu.length; i++){
			if(isIE && !isIE4){ //initializes filters
				backDrop.filter = "alpha(opacity=100)";
			}
			thsMenu[i].visibility = "hidden"; 
			backDrop.visibility = "hidden";		
			backLite.visibility = "hidden";
			if(isNav4){
				backLite.clip.width = menuItemWidth;
			} else {
				backLite.width = menuItemWidth;
			}		
		}
	}
}

//Positions, sizes and turns on backdrop.  Only called by other functions.
function backDropOn(wMenu,wLen){
	getMenu = navLyrs[wMenu];
	if(wMenu!=0)
		rightHeight = getMenu.length * menuItemHeight;
	else
		rightHeight = (getMenu.length * menuItemHeight) + 10;
	if(isNav4){
		topVal = getMenu[0].top;
		leftVal = getMenu[0].left;
	} else if(isIE){
		topVal = getMenu[0].pixelTop
		leftVal = getMenu[0].pixelLeft;		
	} else if(isDOM){
		topVal = getMenu[0].top
		leftVal = getMenu[0].left
	} 
	bdTop = parseInt(topVal);
	bdLeft = parseInt(leftVal) - blLeftPosnMod;
	backDrop.top = bdTop;
	backDrop.left = bdLeft;
	if(wLen){
		backDrop.width = wLen;
	} else {
		backDrop.width = blWidth;
	}
	backDrop.height = rightHeight + hlTopPosnMod;
	if(isNav4){
		if(wLen){
			backDrop.clip.width = wLen;
		} else {
			backDrop.clip.width = blWidth;
		}
		backDrop.clip.height = rightHeight + hlTopPosnMod;
	}
	if(isIE && !isIE4){ //initializes filters
		backDrop.filter = "alpha(opacity=100)";
	}
	backDrop.visibility = "visible";		
}

//Positions and turns on highlight layer.  
function liteItUp(wMenu,wLayer){
	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(isDOM){
		topVal = ltLayer.top
		leftVal = ltLayer.left
	}
	blTop = parseInt(topVal) + hlTopPosnMod;
	blLeft = parseInt(leftVal) - hlLeftPosnMod;
	backLite.top = blTop;
	backLite.left = blLeft;
	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 < navLyrs.length; i++){
		currentMenu = navLyrs[i];
		for(j = 0; j < currentMenu.length; j++){
			if(i==0 && j==1)
				nextTop = nextTop + menuItemHeight + 10;
			else
				nextTop = nextTop + menuItemHeight;
			currentMenu[j].left = nextLeft;
			currentMenu[j].top = nextTop;			
		}
		nextTop = startingTop + (menuPosnVal * (i + 1));
	}
	good2go = true;
}
