/*
nav.js
DHTML Navigation
Requires 'useragent.js'
v2.3.1 - 2004/07/15
*/

var MTO; // menu Timeout

// global boolean value that indicates whether the script is allowed to perform its menu rollover effects
// ie. this should be set to false when a nav item is clicked so that no other menu actions are fired while the new page is being loaded (fixes a problem in Firefox)
var allowActions = true; 

function clrMTO () {
	clearTimeout(MTO);
}

function setMenu (menuID, showSubmenu) {
	var ua = new uaSniffer();
	var s = "";
	clrMTO();
	if (ua.isCool) {
		var selectedTab = document.getElementById("tab" + menuID);
		var selectedMenu = document.getElementById("menu" + menuID);

		// loop through all the defined navigation menus and set each to the correct visibility and background image position
		for (var i = 0; i < menuArr.length; i++) {
			var currentTab = document.getElementById("tab" + menuArr[i]);
			if(currentTab != null){
				if(currentTab.className.indexOf("selected") == -1){
					currentTab.style.backgroundColor = "#fff";
					currentTab.style.color = "#333";
	
					if(currentTab.className != null && currentTab.className.indexOf("hasChildren") > -1){
						currentTab.style.backgroundImage = "url(/_images/common/nav_primary_item_arrow_off.gif)";
					}
				}
			}

			if(currentTab.className != null && currentTab.className.indexOf("hasChildren") > -1){
				document.getElementById("menu" + menuArr[i]).style.visibility = (menuArr[i] == menuID && showSubmenu) ? "visible" : "hidden";
			}
			//if(menuArr[i] != defaultMenu){
			//	document.getElementById("tab" + menuArr[i]).style.backgroundPosition = (menuArr[i] == menuID) ? "0px -25px" : "0px 0px";
			//}
		}

		if(selectedTab != null){
			var leftPos = findPosX(selectedTab);
			var topPos = findPosY(selectedTab);
			selectedMenu.style.left = leftPos + 'px';
			selectedMenu.style.top = (topPos + 25) + 'px';

			selectedTab.style.backgroundColor = "#010005";
			if(selectedTab.className != null && selectedTab.className.indexOf("hasChildren") > -1){
				selectedTab.style.backgroundImage = "url(/_images/common/nav_primary_item_arrow_on.gif)";
			}
			selectedTab.style.color = "#fff";
		}
	}
}

function showMenu (tab) {
	var menuID = tab.id.substr(3);
	clrMTO();
	if(allowActions){
		MTO = setTimeout("setMenu('" + menuID + "', true)",100);
	}
}

function showDefMenu () {
	clrMTO();
	if(allowActions){
		MTO = setTimeout("setMenu('" + defaultMenu + "', false)",1000);
	}
}

function setProductFamily (menuID) {
	var ua = new uaSniffer();
	if (ua.isCool) {
		document.getElementById("familymenu" + menuID).className = "selected";
	}	
}

function navClicked(){
	allowActions = false;
}

function setHeaderWidth () {
	document.getElementById("header").style.width = String(document.getElementById("content").offsetWidth) + "px";
}


function init () {
	//document.getElementById("tab" + defaultMenu).style.backgroundPosition = "0px -42px";
	//document.getElementById("tab" + defaultMenu).style.color = "#B76F44";
	//setMenu(defaultMenu, false);
}

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;
}