var mastertabvar= new Array();
var vSelectedMenu //the root ID only of menus, promos, feedbk, news, franchises, contact
var oSelectedMenu //the object representing the global menu element selected
var oSubMenuMENU //the submenu object to show within the oSubMenuBar
var oSubMenuBar //the whole-bar object, not just a menu within
var oMousedOverMenu, vMouseOutParent
var	vRootVariable //are we in (null) or out of (1) the "default.htm" root dir

//Preload images -- doesn't work as well as just putting them, display none, in the body of a page.
// clipped


function initialize(){
	var globalmenuid = "nav_global";
	//get collection of DIVs in nav_global
	var aLI = document.getElementById(globalmenuid).getElementsByTagName("div"); 
	var vID; //used to form the id of the submenus
	var numbsubmenus = aLI.length;
	var y = 0; //for the array index, below.
	var isRel, vRel
	for (var i=0; i<numbsubmenus; i++){
		isRel = (aLI[i].getAttribute("rel") == "undefined" || aLI[i].getAttribute("rel") == null) ? false : true;
		if (isRel == true){ //DIV's if it is indicated to have a submenu (indicated by including a rel attribute)
			vRel = aLI[i].getAttribute("rel")
			mastertabvar[y]=("dv_sub_" + vRel); //store ids of submenus of tab menu
			y = y + 1;
			//with each addtion to the mastertabvar object array, length gets longer.
			aLI[i].getElementsByTagName("a")[0].onmouseover = function () {showsubmenu(this.id);} // Assigne id of the anchor tag, which matches its rel attribute.
		} //end if rel
	} //end for
//NOTE: not indicating a submenu by leaving out the REL breaks the script because closeall() expects something.  Easier to simply comment out the content of the secondary-nav table.	
} //end function

function fRootVariable(x){ //x = parent id of body rel.
	var vRootVariable = null;
	switch (x)
	{
//		case "feedbk":
//			vRootVariable = null;
//			break;
		case "franchises":
			vRootVariable = null;
			break;
		case "contact":
			vRootVariable = null;
			break;
		case "feedbk":
			vRootVariable = 2;
			break;
		default:
			vRootVariable = 1;
	}
	return vRootVariable;
}

function swapoutbackground(who, what, calling){ //This function is used instead of hover in css because of IE6.
	//Second param = 0 | 1 for default | selected.
//alert("swapoutbackground called by " + calling);		
	var vDiv = "dv_" + who;
	var oWho = document.getElementById(vDiv);
	var vWhat, vBackground, vSubdir
	if(vSelectedMenu && vRootVariable != null){ //vRootVariable (set in SetZone) indicates whether you're in the root or a deeper directory.
		vSubdir = "../"; 
	}else{
		vSubdir = ""
	}
	if(vRootVariable == 2){vSubdir = "http://www.jimbobcreative.com/slims/";}

	if(what==0){
		vWhat = "glbl_menu_" + who + "_default.gif"
	}else{
		vWhat = "glbl_menu_" + who + "_selected.gif"
	}
	vBackground = eval('"url(' + vSubdir + 'images/' + vWhat + ') top center no-repeat\";');
	//surface(vDiv);  // z-index swapping not needed.
	oWho.style.background = vBackground;
}

function SetZone(){
	//Set page zone selection
	vSelectedMenu = document.getElementById("wrapper").parentNode.getAttribute("rel"); // the BODY rel, which should always be the zone name.  The body CLASS = the subpage ID.
	if(vSelectedMenu == "default"){ //homepage?
		vSelectedMenu = null;
		// .style.visibility = "hidden";
		return;
	}
	var submenuID = "dv_sub_" + vSelectedMenu; 
	var vZindex = "dv_" + vSelectedMenu;
	oSelectedMenu = document.getElementById(vZindex);
	oSubMenuMENU = document.getElementById(submenuID);
	oSubMenuBar = document.getElementById("subnav_container");
	oSubMenuBar.style.visibility = "visible";
	//Set SELECTED state of parent, global nav element
	vRootVariable = fRootVariable(vSelectedMenu); //Set the global variable indicating the dir level.
	swapoutbackground(vSelectedMenu, 1, "SetZone");
	//Show the submenu related to the selected global nav element
	oSubMenuMENU.style.display = "block";
}

var iStart = 10;
function surface(dv) {//changes the z-index of the GLOBAL, parent element to be the top-most.
//	var dvLayer = "dv_" + dv;
	iStart++
  document.getElementById(dv).style.zIndex = iStart;
  //LATER: reset all the zindexs back to some beginning threshhold when a max has been reached.
}

function closeall(x){
	//Then re-show the one that corresponds to whose global nav item SELECTED.
	//All but index page have mouseout with value of 1 to indicate there is a sub-menu to re-display.
	closeallFromSubroutines();
	if(x){//If there is a selected menu, however, turn it back on.  Activated only on MouseOut of the phantom zones. In the mouseout segments of ~index pages have 1 for a argument, else blank.
		//x: 0 = close all, 1 = restaur selected menu.  0 is used from the subroutines.
		if(vSelectedMenu){
			oSubMenuMENU.style.display = "block";
			swapoutbackground(vSelectedMenu, 1,'closeall, if global selected');
			oMousedOverMenu = null;
			vMouseOutParent = null;
		}
	} 
}
function closeallFromSubroutines(x){
	if(oMousedOverMenu){
		oMousedOverMenu.style.display = "none";
		//Return background image to _default.
		swapoutbackground(vMouseOutParent, 0, 'closeallFromSubroutines');
		oMousedOverMenu = null; //the parent global nav element OBJECT moused over
		vMouseOutParent = null; //only the ID of the above.
		//vID gets transformed to dv_parentid (dv_vID)
	}
}

function showsubmenu(parentid){
	//This is assigned to all the Global Navigation links.
	//parentid = id of anchor tag, which is the "root" id.
	var oParent = document.getElementById(parentid);
	var subid = "dv_sub_" + parentid;
	var dvbackground
	if(oMousedOverMenu){
		if(vMouseOutParent != vSelectedMenu){//Don't un-select the zone's global selection
			swapoutbackground(vMouseOutParent,0,'showsubmenu');
		}
	}
	vMouseOutParent = parentid;
	
	//hide any open menus
	if(oSubMenuMENU){oSubMenuMENU.style.display = "none";} //There is no oSubMenuMENU when starting on the HP.
	closeallFromSubroutines();
	//Parent (global-element) mouseover color
	swapoutbackground(parentid, 1,'showsubmenu'); //will be transformed to: dv_parentid
	vMouseOutParent = parentid;
	
	//show the submenu whose parent was just moused over
	var oSubMenuToOpen = document.getElementById(subid);
	//record the global variable: the menu is showing.
	oMousedOverMenu = oSubMenuToOpen
//	surface(divid); //changes the z-index of the GLOBAL, parent element to be the top-most.
//	oSubMenuBar.style.visibility = "visible";
	oSubMenuToOpen.style.display = "block";
 }

var d = new Date(); //write in the footer for the copyright year.
//document.write(d.getFullYear());