var main;
var mainIndex;
var subIndex;
var mainDiv;
var delayId = 0;
var showCurrentNavId = 0;
var showCurrentNavDelay = 1500; // miliseconds before we revert back to our current nav
var showRollOverDelay = 250; // miliseconds before we show rollovers on main nav
var imageID;
var imageIndex;
var origMM_sr; // array
var tempMainNavIndex;

function navInit(){
	main = document.getElementById("main").value;
	mainIndex = document.getElementById("mainIndex").value;
	subIndex = document.getElementById("subIndex").value;
	// display the correct submenu
	swapDiv("menu" + mainIndex, false);
	setStickyNav();
}
// highlight the correct images to match our current section
function setStickyNav(){
	mainDiv = document.getElementById(main);
	
	mainDiv.src = "images/menu" + mainIndex + "selected.gif";
	if (subIndex){
		var subDiv = document.getElementById("menu" + mainIndex + "btn" + subIndex);
		subDiv.src = "images/menu" + mainIndex + "btn" + subIndex + "selected.gif";
	}
	
}

function delayRollOver(imgID, imgIndex){
	
	imageID = imgID;
	imageIndex = imgIndex;
	clearTimeout(delayId);
	delayId = setTimeout ("showRollOver()", showRollOverDelay);
}

function showRollOver(){
	clearTimeout(delayId);
	clearTimeout(showCurrentNavId);
	rollOutNonCurrentNav(); 
	MM_swapImgRestore();
	MM_swapImage(imageID,"","images/menu" + imageIndex + "over.gif",1); 
	swapDiv("menu" + imageIndex,false);
}

function killDelayAndRestore(){
	clearTimeout(delayId);
	clearTimeout(showCurrentNavId);
	showCurrentNavId = setTimeout ("showCurrentNav()", showCurrentNavDelay); 
	
}

function subNavOut(){
	clearTimeout(showCurrentNavId);
	showCurrentNavId = setTimeout ("showCurrentNav()", showCurrentNavDelay); 
	MM_swapImgRestore();
}
function subNavOver(mainNavIndex,subNavIndex){
	clearTimeout(showCurrentNavId);
	// if we've moved to a new section, make sure to reset the old one
	if (tempMainNavIndex != mainNavIndex){
		tempMainNavIndex = mainNavIndex;
		origMM_sr = document.MM_sr;
		
	}
	
	
	MM_swapImage("menu" + mainNavIndex + "btn" + subNavIndex,"","images/menu" + mainNavIndex + "btn" + subNavIndex + "over.gif",1);
}

function rollOutNonCurrentNav(){
	mainDiv.src = "images/menu" + mainIndex + "off.gif";
	if (origMM_sr){
		MM_swapImage(origMM_sr[0].id,"","images/menu" + tempMainNavIndex + "off.gif",1); 
		origMM_sr = null;
	} 
}

function showCurrentNav(){
	clearTimeout(showCurrentNavId);
	MM_swapImgRestore();
	rollOutNonCurrentNav();
	mainDiv.src = "images/menu" + mainIndex + "selected.gif";
	swapDiv("menu" + mainIndex,false);
}