//<script>
// (c)2006 Klixo Ltd. All rights reserved

// Function to test if the mouse is still over some part of the menu. If not, 
// hide the menu
function kxMenuOnMouseMove(oEvent)
{
	if (okxMenuMgr) 
	{
		if (okxMenuMgr.moMenu) if (okxMenuMgr.moMenu.hidden) return;
		// Get the source of the mouse move
		var src = oEvent.srcElement;
		// See if what we're hovering over or any parent has a class name of menu
		while (src)
		{
			// Yep, menu element
			if (src.className)
			{
				// Need to check for both styles
				if (src.className.indexOf("kxMenu") >= 0)
				{
					// If we're currently waiting to hide the menu, stop it
					if (okxMenuMgr.moMenu.hiding) okxMenuMgr.moMenu.CancelTimerAction();
					// Quit
					return;
				}
			}
			// See if the parent element is a menu item
			src = src.parentElement;
		}
		// Not over a menu item
		switch (oEvent.srcElement.tagName)
		{
		case "A":
		  break;
		case "AREA":
		  break;
		default:
		  try
		  {
				// Hide the menu
				okxMenuMgr.moMenu.HideAllMenus();
		  }
		  catch(e){}
		}
	}
}

// Called when the mouse moves over a menu and shows the sub-menu              		
function kxMenuItemOver(oEvent, sId, sChildMenuId)
{
	try
	{
		// Instantiate a menu for the object the mouse is over
		var oMenu = new kxMenu(sId);
		// Instantiate a child menu object and set it to the global current menu item
		okxMenuMgr.moMenu = oMenu.CreateChild(sChildMenuId);
		// Get the left and top offsets for the menu
		var oElement = oEvent.srcElement;
		// Get the TR entry 
		while (oElement && oElement.tagName != "TR") oElement = oElement.parentElement;
		// Set the offset to the width of the TR element
		var iOffsetLeft = oElement.offsetWidth, iOffsetTop = 0;
		// Now add the offsets left and top until we reach the table
		do
		{	
			iOffsetLeft += oElement.offsetLeft;
			iOffsetTop += oElement.offsetTop;
			oElement = oElement.offsetParent;
		}
		while (oElement && oElement.tagName.toUpperCase() != "DIV");
		// Set the offsets
		okxMenuMgr.moMenu.offsetTop = iOffsetTop;
		okxMenuMgr.moMenu.offsetLeft = iOffsetLeft;				
		// Show the child menu
		okxMenuMgr.moMenu.Show();
	}
	catch(e){}
}

// Called when the mouse moves over a leaf menu (i.e. one that has no
// sub-menus) and hides all its parent's child menus. 
function kxLeafMenuItemOver(oEvent, sParentId)
{
	try
	{		
		oEvent.srcElement.parentElement.className = "kxHighlight";
		// Create a menu for the parent
		okxMenuMgr.moMenu = new kxMenu(sParentId);
		// Make a timeout call to hide it's children
		okxMenuMgr.moMenu.HideChildren();
	}
	catch(e) {}
}

// For a horizontal menu item, shows its sub-menu
function kxTopMenuItemOver(oEvent, sId, sChildMenuId)
{
	try
	{
		// Instantiate a menu for the object the mouse is over
		var oMenu = new kxMenu(sId);
		
		// Instantiate a child menu object and set it to the global var
		okxMenuMgr.moMenu = oMenu.CreateChild(sChildMenuId);
		// Get the left and top offsets for the menu
		var oElement = oEvent.srcElement;
		// Get the TR entry 
		while (oElement && oElement.tagName != "TD") oElement = oElement.parentElement;
		// Set the left offset to the left of the TD and top to the height of the TD
		var iOffsetLeft = oElement.offsetLeft - 1, iOffsetTop = oElement.offsetHeight;
		oElement = oElement.parentElement;
		// Now add top and left offsets for DIV, TABLE, TBODY and TR recursively for each parent
		// until we reach the top or an absolutely positioned element
		do
		{
			iOffsetTop += oElement.offsetTop;
			iOffsetLeft += oElement.offsetLeft;
			oElement = oElement.offsetParent;
		}
		while (oElement && oElement.tagName.toUpperCase() != "DIV");
		// Set the offsets
		okxMenuMgr.moMenu.offsetTop = iOffsetTop;
		okxMenuMgr.moMenu.offsetLeft = iOffsetLeft;				
			
		// Show the child menu
		okxMenuMgr.moMenu.Show();
	}
	catch(e){}
}

// When a menu item is deselected, stop any further action
function kxMenuItemOut()
{
	try
	{
		// Stop the sub-menu from being displayed
	  okxMenuMgr.moMenu.CancelTimerAction();
	}
	catch(e){}
}

function kxLeafMenuItemOut(oEvent)
{
	oEvent.srcElement.parentElement.className = "kxUnhighlight";
	kxMenuItemOut();
}

// Called by klixo_xml_menu.js - customised for specific user
function kxRemoveSpecificMenus(element)
{
	var badmenus = new Array('PAGE MENU XML', 'HTML MENUS LEFT', 'Newsletter');
	// Get all the menu's table's rows
	var rows = element.getElementsByTagName('TR');
	var removed = false;
	// Look at each row in turn
	for (var i = 0; i < rows.length; i++)
	{
		// Get all the row's links
		var links = rows[i].getElementsByTagName('A');
		// Look at each link in turn
		for (var j = 0; j < links.length; j++)
		{
			// See if the content matches anything we're trying to remove
			for (var k = 0; k < badmenus.length; k++)
			{
				// See if it's something we want to remove
				if (links[j].innerText == badmenus[k])
				{
					// Yep, remove the row
					rows[i].removeNode(true);
					// Ensure we start at the next node which is now indexed to the same row
					removed = true;
				}
				if (removed) break;
			}
			if (removed) break;
		}
		if (removed)
		{
			i--;
			removed = false;
		}
	}
}

//</script>

