//<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 MenuOnMouseMove(oEvent)
{
	if (moMenu) 
	{
		if (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.id)
			//if (src.className)
			{
				if (src.id.toUpperCase().indexOf("MENU") >= 0)
				//if (src.className.toUpperCase().indexOf("MENU") >= 0) 
				{
					// If we're currently waiting to hide the menu, stop it
					if (moMenu.hiding) 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
				moMenu.HideAllMenus();
		  }
		  catch(e){}
		}
	}
}

// Called when the mouse moves over a menu and shows the sub-menu              		
function MenuItemOver(oEvent, sId, sChildMenuId)
{
	try
	{
		// Instantiate a menu for the object the mouse is over
		var oMenu = new Menu(sId);
		// Instantiate a child menu object and set it to the global current menu item
		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 top and left offsets til for DIV, TABLE, TBODY and TR recursively for each parent
		// until we reach the top or an absolutely positioned element
		do
		{	
			iOffsetLeft += oElement.offsetLeft;
			iOffsetTop += oElement.offsetTop;
			oElement = oElement.offsetParent;
		}
		while (oElement.offsetParent != moMenu.parentElement.offsetParent);// && oElement.currentStyle && oElement.currentStyle.position != "absolute");
		// Set the offsets
		moMenu.offsetTop = iOffsetTop;
		moMenu.offsetLeft = iOffsetLeft;
		// Show the child menu
		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 LeafMenuItemOver(oEvent, sParentId)
{
	try
	{
		// Create a menu for the parent
		moMenu = new Menu(sParentId);
		// Make a timeout call to hide it's children
		moMenu.HideChildren();
	}
	catch(e) {}
}

// For a horizontal menu item, shows its sub-menu
function TopMenuItemOver(oEvent, sId, sChildMenuId)
{
	try
	{
		moMenu.CancelTimerAction();
		// Instantiate a menu for the object the mouse is over
		var oMenu = new Menu(sId);
		
		// Instantiate a child menu object and set it to the global var
		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 + 10, iOffsetTop = oElement.offsetHeight + 5;
		// 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
		oElement = oElement.parentElement;
		do
		{
			iOffsetTop += oElement.offsetTop;
			iOffsetLeft += oElement.offsetLeft;
			oElement = oElement.offsetParent;
		}
		while (oElement.offsetParent != moMenu.parentElement.offsetParent);// && oElement.currentStyle && oElement.currentStyle.position != "absolute");
//		while (oElement && oElement.currentStyle && oElement.currentStyle.position != "absolute");
		// Set the offsets
		moMenu.offsetTop = iOffsetTop;
		moMenu.offsetLeft = iOffsetLeft;				
			
		// Show the child menu
		moMenu.Show();
	}
	catch(e){}
}

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

// Called by klixo_xml_menu.js - customised for specific user
function RemoveSpecificMenus(element)
{
	var badmenus = new Array('PAGE MENU XML', 'HTML MENUS LEFT', 'Whakatane Freenet', 'How Freenet works', 'Pre School Facilities', 'Primary Schools', 'Secondary Schools', 'Tertiary and Adult Education');
	// Strings that if contained anywhere in menu are removed
	var badmenucontains = new Array('KML');
	// 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].innerHTML == badmenus[k])
				{
					if (GetAgentType() == mlMSIE)
					{
						// 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;
					}
					else if (GetAgentType() == mlFIREFOX)
					{
						element.childNodes[0].deleteRow(i);
						removed = true;
					}
				}
				if (removed) break;
			}
			if (removed) break;
			// See if the content matches anything in the contains list
			for (var k = 0; k < badmenucontains.length; k++)
			{
				// See if the link contains this word
				if (links[j].innerHTML.indexOf(badmenucontains[k]) != -1)
				{
					if (GetAgentType() == mlMSIE)
					{
						// 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;
					}
					else if (GetAgentType() == mlFIREFOX)
					{
						element.childNodes[0].deleteRow(i);
						removed = true;
					}
				}
				if (removed) break;
			}
			if (removed) break;
		}
		if (removed)
		{
			i--;
			removed = false;
		}
	}
}

//</script>
