/*
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 currentTab = document.getElementById("tab" + menuID);
		var currentMenu = 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++) {
			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 -20px" : "0px 0px";
			}
		}

		var leftPos = findPosX(currentTab);
		var topPos = findPosY(currentTab);
		currentMenu.style.left = leftPos + 'px';
		currentMenu.style.top = (topPos + 20) + 'px';
	}
}

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;
}