<!--
//MAIN HEADER MENUS v1.5
//Script parses URLs and finds the best match and makes corrisponding tab active and subnav default.
//Script provides hover functionality for I.E.
//Script applies "last" style sheet the the last <LI> of the subnav.

function navMenus()
{
	var menuRootId = "nav_menu"; //Configure this to the ID of the root <UL> of the navigation
	
	//Make sure the menu root ID variable has been set
	if(!menuRootId){
		alert("menuRootId variable must be set");
		return;
	}
	
	//Make sure this ID exists.
	if(!document.getElementById(menuRootId))
	{
		alert("No ID matching \""+menuRootId+"\" has been found.");
		return;
	}
	
	var menuRoot = document.getElementById(menuRootId);
	
	//Make sure ID is set on a <UL> tag
	if(menuRoot.nodeName != "UL"){
		alert("\""+menuRootId+"\" must be an ID attribute on a <UL> tag");
		return;
	}
	
	//Make sure <UL> tag has <LI> tags
	if(menuRoot.getElementsByTagName("li").length < 1){
		alert("<UL> tag must have at least one <LI> tag");
		return;
	}
	
	
	//For section fronts we match current menus by URL
	if(sectionCurrent == "FRONTPAGE" || sectionCurrent == "ANE")
	{
		var docURL = document.URL;
		//var docURL = "http://10.0.1.100/section/CUTAWAY"; //Comment this out in production.
		var menuLInkArray = menuRoot.getElementsByTagName("a");
		var matchedArray = new Array();
		
		//Make the correct menu current based on the page's URL
		for (var i=0;i<menuLInkArray.length;i++)
		{
			var menuHREF = menuLInkArray[i];
			var docURLArray = docURL.split(menuHREF);
	
			if(docURLArray.length > 1)
			{
				var matchedIndex = docURLArray[1].length;
				matchedArray[matchedIndex] = menuLInkArray[i];
			}
		}
			
		// If there are no matches exit
		if(matchedArray.length < 1)
		{
			menuLInkArray[0].parentNode.parentNode.className = "active";
		}
		
		for (var i=0;i<matchedArray.length;i++)
		{
			if(matchedArray[i])
			{
				if(matchedArray[i].parentNode.parentNode.parentNode.parentNode.id == menuRootId)
				{
					matchedArray[i].className = "active";
					matchedArray[i].parentNode.parentNode.parentNode.className = "active";
					//For other scripts we determine the active top level section
					var sectionTopCurrentNode = matchedArray[i].parentNode.parentNode.parentNode.getElementsByTagName("a");
					sectionTopCurrent = sectionTopCurrentNode[0].innerHTML.toLowerCase();
					break;
				}
				else
				{
					matchedArray[i].parentNode.parentNode.className = "active";
					//For other scripts we determine the active top level section
					sectionTopCurrent = matchedArray[i].innerHTML.toLowerCase();
					break;
				}
			}
		}
	}
	
	//For articles we match based by "profile" from Saxotech
	else
	{
		var docURL = sectionCurrent.toLowerCase(); //document.URL;
		var menuLInkArray = menuRoot.getElementsByTagName("a");
		
		//Make the correct menu current based on the page's URL
		for (var i=0;i<menuLInkArray.length;i++)
		{
			var menuHREF = menuLInkArray[i].getAttribute("href").toLowerCase();
			var isMatch = menuHREF.match(docURL);
	
			if(isMatch)
			{
				menuLinkNode = menuLInkArray[i];
				break;
			}
		}
		
		// If there are no matches set home as active
		if(!isMatch)
		{
			menuLInkArray[0].parentNode.parentNode.className = "active";
		}
		
		else
		{
			if(menuLinkNode.parentNode.parentNode.parentNode.parentNode.id == menuRootId)
			{
				menuLinkNode.className = "active";
				menuLinkNode.parentNode.parentNode.parentNode.className = "active";
				//For other scripts we determine the current top level section
				var sectionTopCurrentNode = menuLinkNode.parentNode.parentNode.parentNode.getElementsByTagName("a");
				sectionTopCurrent = sectionTopCurrentNode[0].innerHTML.toLowerCase();
			}
			else
			{
				menuLinkNode.parentNode.parentNode.className = "active";
				//For other scripts we determine the active top level section
				sectionTopCurrent = menuLinkNode.innerHTML.toLowerCase();
			}
		}
	}
	
	//alert(sectionTopCurrent);
		
	/////////////////////////////////////////////
	
	//Sets the last <LI> tag class to last
	//Get the <UL> elements (subnavs)
	menuULArray = menuRoot.getElementsByTagName("UL");
	
	//Get the last <LI> element for every <UL> element
	for (var i=0;i<menuULArray.length;i++)
	{
		menuLIArray = menuULArray[i].getElementsByTagName("LI")
		var lastLI = menuLIArray[menuLIArray.length-1];
		//alert(menuLIArray[menuLIArray.length-1].innerHTML);
		
		lastLI.className = "last";
	
	
	}

	///////////////////////////////////////////////
	//If browser is not IE, exit
	if(navigator.appName != "Microsoft Internet Explorer")
	{
		//alert(navigator.appName);
		return;
	}
	
	var menuLIArray = menuRoot.getElementsByTagName("li");
	
	//alert(x+"\n"+menuLIArray[0].innerHTML);
	
	for (var i=0;i<menuLIArray.length;i++)
	{
		//Determine the level of the menu.
		var menuLevel = 0;
		var parentNodeObject = menuLIArray[i].parentNode;
		
		while(parentNodeObject.id != menuRootId)
		{
			if(parentNodeObject.nodeName == "UL")
			{
				if(parentNodeObject.id == menuRootId)
				{
				menuLevel++;
				break;
				}
				
				menuLevel++;
			}
			parentNodeObject = parentNodeObject.parentNode;
		}
		
		//Apply rollovers to first level menus
		if(menuLevel == 0)
		{
			menuLIArray[i].onmouseover = function()
			{
				menuOver(this);
			}
			
			menuLIArray[i].onmouseout = function()
			{
				menuOut(this);
			}
		}
		//Apply rollovers to second level menus
		if(menuLevel == 1)
		{
			menuLIArray[i].onmouseover = function()
			{
				menuSubOver(this);
			}

			menuLIArray[i].onmouseout = function()
			{
				menuOut(this);
			}
		}
	}
}

function menuOver(menuLI)
{
	//If no sub navigation exit the function
	if(menuLI.getElementsByTagName("UL").length < 1)
	{
		return;
	}
	
	//Show the sub navigation
	var subNavArray = menuLI.getElementsByTagName("UL");
	subNavArray[0].style.display = "block";
}

function menuSubOver(menuLI)
{
	//If no sub navigation exit the function
	if(menuLI.getElementsByTagName("UL").length < 1)
	{
		return;
	}
	
	var subNavArray = menuLI.getElementsByTagName("UL");
	
	//Set this to the amount of li margin used in css
	var navMargin = -8;
	
	//We have to position sub sub nav for I.E.
	if(menuLI.clientWidth)
	{
	subNavArray[0].style.marginLeft = "-"+(menuLI.clientWidth-(navMargin))+"px";
	}
	else if(menuLI.offsetWidth)
	{
	subNavArray[0].style.marginLeft = "-"+(menuLI.offsetWidth-(navMargin))+"px";
	}
	
	subNavArray[0].style.display = "block";
}

function menuOut(menuLI)
{
	//If no sub navigation exit the function
	if(menuLI.getElementsByTagName("UL").length < 1)
	{
		return;
	}
	
	//Hide the menu's sub navigation
	var subNavArray = menuLI.getElementsByTagName("UL");
	subNavArray[0].style.display = "none";
	
	//Show the active menu's sub navigation	
	if(menuLI.className == "active")
	{
		subNavArray[0].style.display = "block";
	}
}
-->