//Global Variables
var ishm_menu_state = 0;
var ishm_arrMenuTables = new Array();
var ishm_arrTimeoutIDs = new Array();
var ishm_offsetLeft = 6;
var ishm_offsetTop = 3;

function ishm_mouseOutMenu()
{
	ishm_menu_state = ishm_menu_state - 1;
	var intTimeout = setTimeout("ishm_hideAllMenus()", 500);
	ishm_arrTimeoutIDs[ishm_arrTimeoutIDs.length] = intTimeout;
}

function ishm_hideAllMenus()
{
	if (ishm_menu_state > 0) return;
	
	for (var i = 0; i < ishm_arrMenuTables.length; i++)
	{
		var menu = document.getElementById(ishm_arrMenuTables[i]);
		if (menu) 
		{
			menu.style.display = "none";
			menu.style.visibility = "hidden";
		}
	}
}

//this function depends on recursive calling of ishm_loopThroughParentMenu
function ishm_hideNonParentMenus(parentMenuID)
{
	var oFocusedMenu;
	var oArrayMenu;
		
	//loop through all the visible items in the array.
	strMessage = "Count: " + ishm_arrMenuTables.length + "<br>";
	for (var i = 0; i < ishm_arrMenuTables.length; i++)
	{
		var blnIsParent = false;
		oFocusedMenu = document.getElementById(parentMenuID);
		oArrayMenu = document.getElementById(ishm_arrMenuTables[i]);
		
		if (oArrayMenu != null) {
			//check id of all parentMenuID object's parent nodes
			while (oFocusedMenu != null)
			{
				if (oFocusedMenu.id == oArrayMenu.id) 
				{
					blnIsParent = true;
					break;
				}
				oFocusedMenu = oFocusedMenu.parentNode;
			}
		}
			
		//if no match then hide
		if (! blnIsParent && oArrayMenu != null)
		{
			oArrayMenu.style.display = "none";
			oArrayMenu.style.visibility = "hidden";
		}
	}
}

function ishm_isMenuInArray(childMenuID)
{
	for (var i = 0; i < ishm_arrMenuTables.length; i++)
	{
		if (childMenuID == ishm_arrMenuTables[i]) return true;
	}
	return false;
}

function ishm_mouseOverMenu(parentMenu, childMenuID, position)
{			
	ishm_menu_state = ishm_menu_state + 1;
	
	//add to menu array
	if (! ishm_isMenuInArray(childMenuID)) ishm_arrMenuTables[ishm_arrMenuTables.length] = childMenuID;
	
	//hide all unrelated menus
	ishm_hideNonParentMenus(parentMenu.id);
	
	//clear all existing timeouts
	for (var i = 0; i < ishm_arrTimeoutIDs.length; i++)
	{
		clearTimeout(ishm_arrTimeoutIDs[i]);
	}
	
	//show child object
	var childMenu = document.getElementById(childMenuID);
	
	if (childMenu != null)
	{
		childMenu.style.display = "";
		childMenu.style.visibility = "visible";
		childMenu.style.position = "absolute";
		
		if (position == "vertical")
		{
			childMenu.style.left = parentMenu.offsetWidth;
			childMenu.style.top = 0 + ishm_offsetTop;
			
			//if window.event then check the position vs. the edge of the window
			// window.event is w3c - if you don't support it, we'll need browser specific code
			// else S.O.L.
			if (window.event)
			{
				var visibleWidth = parseInt(window.outerWidth ? window.outerWidth - 9 : document.body.clientWidth, 10);						
				var iPosition = event.clientX - event.offsetX + parentMenu.offsetWidth + childMenu.offsetWidth;
				if (iPosition > visibleWidth)
				{
					//childMenu.style.left = 0 - childMenu.offsetWidth;//parseInt(childMenu.style.left, 10) - (parentMenu.offsetWidth + childMenu.offsetWidth);
					//alert("offsetWidth " + childMenu.offsetWidth + "\n left " + childMenu.clientWidth);
					childMenu.style.left = (0 - childMenu.offsetWidth);// + //	parseInt(childMenu.style.paddingLeft) + parseInt(childMenu.style.paddingRight);
					
					
				}
			}
			else
			{
				//add browser specific code later if neccessary
			}
		}
		else if (position == "horizontal")
		{
			childMenu.style.left = 0 + ishm_offsetLeft;
			childMenu.style.top = parentMenu.offsetHeight;
			
			//reset width if too narrow
			if (childMenu.offsetWidth < parentMenu.offsetWidth)
				childMenu.style.width = parentMenu.offsetWidth;
		}
	}
}

