var openMenuTimeout;
var closeMenuTimeout;
var isPrdMenuOpen = false;
var isPrdSubMenuOpen = false;
var currentSubMenu = "";
var previousSubMenu = "";

function showMenu(whichMenu,whichSubMenu,whichCat)
{
    isPrdMenuOpen = true;
    clearTimeout(closeMenuTimeout);
    if(whichCat != null)
    {
		document.getElementById(whichCat).style.backgroundImage = "url(/images/nav/prdNav_on.gif)";
		document.getElementById(whichCat).style.color = "#ff0000";
    }
    if(whichMenu != null)
    {
		document.getElementById('prdSubNav').style.visibility = "visible";
    }
    if(whichSubMenu != null)
    {
		isPrdSubMenuOpen = true;
		document.getElementById(whichSubMenu).style.visibility = "visible";
		currentSubMenu = whichSubMenu;
    }
    else if(whichSubMenu == null)
    {
		currentSubMenu = "";
    }
}

function hideMenu(whichMenu, whichSubMenu, whichCat)
{
	if((whichMenu != null) && (whichSubMenu != null) && (whichCat != null))
	{
	//	alert(whichMenu + " : " + whichSubMenu + " : " + whichCat);
		isPrdMenuOpen = false;
		closeMenuTimeout = setTimeout("closeMenu('" + whichMenu + "','" + whichSubMenu + "','" + whichCat + "')", 50);
		setTimeout("closeSubMenu('" + whichSubMenu + "','" + whichCat + "')", 5);
	}
	else if((whichMenu != null) && (whichSubMenu == null) && (whichCat != null))
	{
//		alert('xox');
		isPrdMenuOpen = false;
		closeMenuTimeout = setTimeout("closeMenu('" + whichMenu + "', null ,'" + whichCat + "')", 50);
		closeCat(whichCat);
	}
	else if((whichMenu != null) && (whichSubMenu == null) && (whichCat == null))
	{
//		alert('xoo');
		isPrdMenuOpen = false;
		closeMenuTimeout = setTimeout('closeMenu(\'' + whichMenu + '\')', 100);
	}
	else if((whichMenu == null) && (whichSubMenu != null) && (whichCat != null))
    {
//		alert('oxx');
		previousSubMenu = whichSubMenu;
	    setTimeout("closeSubMenu('" + whichSubMenu + "','" + whichCat + "')", 5);
    }
	else if((whichMenu == null) && (whichSubMenu != null) && (whichCat == null))
	{
//		alert('oxo');
		previousSubMenu = whichSubMenu;
	    setTimeout("closeSubMenu('" + whichSubMenu + "')", 5);
	}
	else if((whichMenu == null) && (whichSubMenu == null) && (whichCat != null))
	{
	//	alert('oox');
		currentSubMenu = "";
		if(previousSubMenu != "")
		{
			setTimeout("closeSubMenu('" + previousSubMenu + "')", 5);
		}
		closeCat(whichCat);
	}
	else
	{
	//	alert('ooo');
		currentSubMenu = "";
		if(previousSubMenu != "")
		{
			setTimeout("closeSubMenu('" + previousSubMenu + "')", 5);
		}
	}
	
}

function closeMenu(whichMenu, whichSubMenu, whichCat)
{
	if(!isPrdMenuOpen)
	{
		if(document.getElementById('prdSubNav').style.visibility == "visible")
		{
			document.getElementById('prdSubNav').style.visibility = "hidden";
		}
		if(previousSubMenu != "")
		{
			document.getElementById(previousSubMenu).style.visibility = "hidden";
		}
		if((whichSubMenu != null) && (document.getElementById(whichSubMenu).style.visibility == "visible"))
		{
			document.getElementById(whichSubMenu).style.visibility = "hidden";
		}
		previousSubMenu = "";
		
		if(whichCat != null)
		{
			closeCat(whichCat);
		}		
	}
}

function closeSubMenu(whichSubMenu, whichCat)
{
	if(currentSubMenu != whichSubMenu)
	{
		if(document.getElementById(whichSubMenu).style.visibility == "visible")
		{
			document.getElementById(whichSubMenu).style.visibility = "hidden";
		}
		previousSubMenu = "";
		
		if(whichCat != null)
		{
			closeCat(whichCat);
		}
	}
}

function closeCat(whichCat)
{
	if(whichCat != null)
		{
			document.getElementById(whichCat).style.backgroundImage = "url(/images/nav/prdNav_off.gif)";
			document.getElementById(whichCat).style.color = "#666666";
		}
}

function closeMenus()
{
	if(previousSubMenu != "")
	{
		document.getElementById(previousSubMenu).style.visibility = "hidden";
	}
	if(currentSubMenu != "")
	{
		document.getElementById(currentSubMenu).style.visibility = "hidden";
	}
	document.getElementById('prdSubNav').style.visibility = "hidden";
}

window.onunload = closeMenus;