/*
Navigation menu functions
Copyright © 2006 Metitek Web Solutions

If you wish to use these functions please
consider making a donation of USD 20 for
this development work.  Thank you.

Contact:  info -at- metitek.com		*/

function getWindowHeight()
{
	// this function handles IE's non-compatibility with the ECMAscript standard
	
	var nWinHeight = 0;
	if(typeof(window.innerHeight) == 'number')
	{
		//Non-IE
		nWinHeight = window.innerHeight;
	}
	else if(document.documentElement && (document.documentElement.clientHeight))
	{
		//IE 6+ in 'standards compliant mode'
		nWinHeight = document.documentElement.clientHeight;
	}
	else if(document.body && (document.body.clientHeight))
	{
		//IE 4 compatible
		nWinHeight = document.body.clientHeight;
	}
	return nWinHeight;
}

function adjcolumns()
{
	// adjust the two column heights to match the window

	oLeftcol = document.getElementById("leftcolumn");
	if(oLeftcol != null)
	{
		var nMaxHeight = getWindowHeight();

		oLeftcol.style.height = nMaxHeight + "px";
		var nLHeight = oLeftcol.offsetHeight;

		oRightcol = document.getElementById("rightcolumn");
		if(oRightcol != null)
		{
			oRightcol.style.height = 'auto';
			var nRHeight = oRightcol.offsetHeight;
			
			if(nRHeight > nMaxHeight)
			{
				nMaxHeight = nRHeight;
			}
			
			if(nLHeight < nMaxHeight)
			{
				oLeftcol.style.height = nMaxHeight + "px";
			}
			if(nRHeight < nMaxHeight)
			{
				oRightcol.style.height = nMaxHeight + "px";
			}
			window.onresize = adjcolumns;
		}
	}
}

function mmv(oBtn)
{
	// mouseover appearance
	oBtn.style.backgroundColor = btn_bg_hover;
	oBtn.style.borderColor = btn_border_hover;
}

function mmvNode(e,oBtn,strID)
{
	// mousedown appearance
	oBtn.style.backgroundColor = btn_bg_hover;

	// show submenu
	if(strID.length > 0)
	{
		oElem = document.getElementById(strID);
		if(oElem != null)
		{
			if(g_arrTimerID[strID] == null)
			{
				g_arrTimerID[strID] = -1;
			}
			else if(g_arrTimerID[strID] != -1)		// if submenu is waiting to close, cancel it
			{
				clearTimeout(g_arrTimerID[strID]);
				g_arrTimerID[strID] = -1;
			}
			oElem.style.visibility = "visible";	// make the menu visible
		}
	}
}

function mmt(oBtn)
{
	// mouseout, set appearance to normal
	oBtn.style.backgroundColor = btn_bg;
	oBtn.style.borderColor = btn_border;
}

var g_arrTimerID = new Array();
var g_CloseMenuTimerDelay = 500;

function mmtNode(e,oBtn,strID)
{
	// mouseout, set appearance to normal
	mmt(oBtn);
	
	// hide submenu
	if(strID.length > 0)
	{
		// set a timer to hide the submenu
		g_arrTimerID[strID] = setTimeout("closeMenuID('" + strID + "')", g_CloseMenuTimerDelay);
	}
}

function mmd(e,oBtn,strURL)
{
	// mousedown appearance
	oBtn.style.backgroundColor = btn_bg;
	oBtn.style.borderColor = btn_border_down;
	oBtn.style.padding = "5px 4px 3px 6px";
	
	// navigate to new page
	if(strURL.length > 0)
	{
		self.location.href = strURL;
	}

	// stop the event from propagating up
	if (!e) var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation) e.stopPropagation();
}

function mmu(oBtn)
{
	// mouseup, set appearance to same as mouseover
	mmv(oBtn);
	oBtn.style.padding = "4px 5px";		// adjust padding after mousedown
}

function closeMenuID(strID)
{
	// close any open submenus of this node, by ID
	var oElem = document.getElementById(strID);
	if(oElem != null)
	{
		closeNode(oElem);
	}
}

function closeNode(oElement)
{
	// close any open submenus of this node
	if((oElement.nodeType == 1) && (oElement.nodeName == "DIV"))
	{
		if(oElement.hasChildNodes())
		{
			// iterate through the child nodes and if there's a submenu Node, close it recursively
			var oChildNodeList = oElement.childNodes;
			var nI = 0;
			for(nI = 0; nI < oChildNodeList.length; ++nI)
			{
				var oChildNode = oChildNodeList[nI];
				if((oChildNode.nodeType == 1) && (oChildNode.nodeName == "DIV"))
				{
					var strClass = oChildNode.getAttribute("class");
					if((strClass != null) && (strClass != "") && (strClass.indexOf("menu-item") != -1) && (strClass.indexOf("container") != -1) )
					{
						// this is a menu Node DIV element
						// find the first DIV child
						var oSubmenu = oChildNode.firstChild;
						while((oSubmenu.nodeType != 1) || (oSubmenu.nodeName != "DIV")) oSubmenu = oSubmenu.nextSibling;
						strClass = oSubmenu.getAttribute("class");
						if((strClass != null) && (strClass != "") && (strClass.indexOf("submenu") != -1) )
						{
							// submenu node, close it recursively
							closeNode(oSubmenu);
						}
					}
				}
			}
		}

		// hide the node
		oElement.style.visibility = "hidden";
	}
}

