/*
 * window.contentId is the variable to be used by Belo to specify the location
 * in the site.
 * The home page should have a null contentId
 */
window.contentId = null;

window.activeTop = null;
window.activeSub = null;
window.activeLi = null;
window.hideTimeout = null;
window.currentTopNav = null;
window.hoverTimeout = 300; // change this value to set the hover timeout

	function highlightNavigation()
	{		
		var hierarchy = new Array();
		hierarchy.push(window.contentId);
		currentPage = window.contentId;
		
		// if the element is not found, return		
		if(pageArray[currentPage] == null)
		{
			return;
		}
		
		while (pageArray[currentPage] != 'null')
		{
			hierarchy.push(pageArray[currentPage]);
			currentPage = pageArray[currentPage];
		}
						
		var topNavElem = document.getElementById("topNav" + hierarchy[hierarchy.length - 1]);
		topNavElem.className = "topNav_on";
		window.activeTop = topNavElem;
		window.currentTopNav = topNavElem;	
	}

	function findPosX(obj)
	{
		var curleft = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x)
			curleft += obj.x;
		return curleft;
	}
	
	function findPosY(obj)
	{
		var curtop = 0;
		if (obj.offsetParent)
		{
			while (obj.offsetParent)
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y)
			curtop += obj.y;
		return curtop;
	}	

	function showSubNav(parentId, childId, force)
	{		
		if(force == 1) 
		{			
			hideSubNav();			
		}
		else if(window.activeTop != null) return;
		window.clearInterval(window.hideTimeout);
		window.hideTimeout = null;
		
		var subNav = document.getElementById(childId);
		var parent = document.getElementById(parentId);
		parent.className = "topNav_on";		
		window.activeTop = parent;
		if(subNav != null)
		{
			var parent_bottom = findPosY(parent) + parent.offsetHeight;
			var parent_x_position = findPosX(parent);
			if(isIE)
			{
				subNav.style.left = parent_x_position + "px";
				subNav.style.top = parent_bottom - 8 + "px";				
			}
			else
			{									
				subNav.style.left = parent_x_position + "px";
				subNav.style.top = parent_bottom - 7 + "px";				
			}
			subNav.style.visibility="visible";			
			window.activeSub = subNav;
		}
		
	}
	
	
	function hideSubNav()
	{
		window.clearInterval(window.hideTimeout);
		window.hideTimeout = null;
		
		if (window.activeTop != null)
		{
			window.activeTop.className = "topNav";
			window.activeTop = null;
		}
		if (window.activeSub != null)
		{
			window.activeSub.style.visibility="hidden";
			window.activeSub = null;
		}
		
		// return to current page highlight if one is specified
		if(window.currentTopNav != null)
		{
			window.currentTopNav.className = "topNav_on";
			window.activeTop = window.currentTopNav;
		}
	}
	
	// highlights a subnav list item on mouseover
	function highlightSubnavLi(divObj)
	{
		window.clearInterval(window.hideTimeout);
		window.hideTimeout = null;

		if(window.activeLi != null)
		{
			window.activeLi.className = "";
		}
		divObj.className = "onLink";
		window.activeLi = divObj;	
	}
	
	// removes highlight from the subnav list item
	function deHighlightSubnavLi(divObj)
	{
		divObj.className = "";
		window.activeLi = null;		
	}
	
	function startHideTimeout()
	{
		window.clearInterval(window.hideTimeout);
		window.hideTimeout = null;
		window.hideTimeout = window.setInterval("hideSubNav()", window.hoverTimeout);
	}
