/*----------------------------------------------------------------
Javascript in this file is used to render (Show/Hide) the popup
submenus.
The javascript in this file is called from an XSL template called
"raw-level2-non-selected" in file main-menu.xsl
Ahmad Abu-Raddad 03-April-2005
---------------------------------------------------------------- */

var nCancelId = 0;
var blnKeepMenu = false;
var objCurrentMenu = null;
//This variable represents the time duration
// before the submenu fades out in milliseconds
var TIME_TO_HIDE_MENU = 0;

//Returns the Y coordinate of the popping submenu
function getSubMenuTopPosition(objMainMenu)
{
	return (findPosY(objMainMenu))
}

//Returns the X coordinate of the popping submenu
function getSubMenuLeftPosition(objMainMenu)
{		
	return (findPosX(objMainMenu) - objMainMenu.offsetWidth + 5); 
}

//This function can be used to return the X position of any html object in the page
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;
}

//This function can be used to return the Y position of any html object in the page
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 setActiveMenu(menu)
{
	blnKeepMenu = true;
	window.clearTimeout(nCancelId);
}

//This function is responsible for showing the submenu (popping it up)
function showMenu(parentMenu,subMenu)
{
	window.clearTimeout(nCancelId);
	if (objCurrentMenu != null && subMenu != objCurrentMenu)
		realHideMenu();	
	
	
	subMenu.style.top = getSubMenuTopPosition(parentMenu); 
	subMenu.style.left = getSubMenuLeftPosition(parentMenu); 
	
	subMenu.style.display = "inline";	
		
	blnKeepMenu = true;
	objCurrentMenu = subMenu;
}

//This function is responsible for hiding the submenu
function hideMenu()
{
	blnKeepMenu = false;
	nCancelId = window.setInterval("realHideMenu()",TIME_TO_HIDE_MENU);
}
function realHideMenu()
{
	if (!blnKeepMenu)
	{
		window.clearTimeout(nCancelId);
		objCurrentMenu.style.display = "none";
		objCurrentMenu = null;
	}
}

/*----------------------------------------------------------------
End Rendering the popup sub menues
Ahmad Abu-Raddad 03-April-2005
---------------------------------------------------------------- */