var mastertabvar= new Array();
var oSelectedMenu //company, clients, process, contact

function initialize(){
	var globalmenuid = "ul_global";
	//get collection of LIs in ul_global
	var aLI = document.getElementById(globalmenuid).getElementsByTagName("li"); 
	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){ //LI's if it is indicated to have a submenu (indicated by including a rel attribute)
			vRel = aLI[i].getAttribute("rel")
			mastertabvar[y]=("td_" + 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 SetZone(){
	//Set page zone selection
	vParentID = document.getElementById("wrapper").parentNode.getAttribute("rel"); // the BODY rel, which should always be the zone name.  The body CLASS = the subpage ID.
	if(vParentID == "default"){ //homepage?
		oSelectedMenu = null;
		return;
	}
	var submenuID = "td_" + vParentID;
	oSelectedMenu = document.getElementById(submenuID);
	oSelectedMenu.style.display = "block";
	MouseOutParams(vParentID);
}

function showsubmenu(parentid){
	//This was assigned to all the Global Navigation links.
	var oParent = document.getElementById(parentid);
	var subid = "td_" + parentid;

	//hide any open menus
	closeall();
	
	//show the one that was just moused over
	var oSubMenuToOpen = document.getElementById(subid);
	oSubMenuToOpen.style.display = "block";
	//mouseover color
	if(oSelectedMenu && (oSubMenuToOpen.id != oSelectedMenu.id)){
		oParent.style.color = "#ffcc33";
	}
	/* To accommodate one-off structure for extra long sub-navigation. */
	MouseOutParams(parentid)
}
function MouseOutParams(parentid){
	var oOutLeft, oOutTop, oOutBottom, oOutRight;
	oOutLeft = document.getElementById('out_left').style;
	oOutTop = document.getElementById('out_top').style;
	oOutBottom = document.getElementById('out_bot').style;
	oOutRight = document.getElementById('out_right').style;
		
	if(parentid == 'process'){
		oOutBottom.width = "597px"; 
		oOutBottom.left = "-203px";
		oOutTop.width = "597px"; 
		oOutTop.left = "-203px";
		oOutLeft.left = "-208px";
		oOutRight.left = "397px";
	}else{
		oOutBottom.width = "402px"; 
		oOutBottom.left = "-2px";
		oOutTop.width = "402px"; 
		oOutTop.left = "-2px";
		oOutLeft.left = "-9px";
		oOutRight.left = "402px";
	}
}

function closeall(x){
	//Idea is to 1) closeall submenus and 2) re-show the one that corresponds to whose global nav item is being moused over.
	//All but index page have mouseout with value of 1 to indicate there is a sub-menu to re-display.
	var oParent
	var vID, oGlobalMenuItem, vMouseOutParams
	for (var i=0; i<5;i++){ //removed ref to length of mastertabvar array.
		//Loop thru all global submenus.
		//hide submenu
		document.getElementById(mastertabvar[i]).style.display="none";

		//Remove hover state from parent
		vID = mastertabvar[i].substr(3);
		oGlobalMenuItem = document.getElementById(vID);
		document.getElementById(vID).style.color="";
	}
	if(x){
		if(oSelectedMenu){
			oSelectedMenu.style.display = "block";
			vMouseOutParams = oSelectedMenu.id.substr(3);
			MouseOutParams(vMouseOutParams);
		}
	} 
}
