/*
** CONSTANTS
*/

var SHOW_DELAY = 200;  // delay between mouseover and show the menu
var HIDE_DELAY = 400;  // delay before hiding the menu
browser = '';

/*
** GLOBALS
*/

var hideTimer = null;
var showTimer = null;
var currentMenuId = null;

function showMenu(id)
{
	clearHideTimer();
	if (currentMenuId) _showMenu(id);
	else
	{
		showTimer = setTimeout("_showMenu('" + id + "')", SHOW_DELAY);
	}
}

function _showMenu(id)
{
	
	if (currentMenuId && id != currentMenuId)
	{
		_hideMenu(currentMenuId);
	}
	currentMenuId = id;

	document.getElementById(id + "-title").className="on";
	var menuElement = document.getElementById(id + "-list");
	var maskElement = document.getElementById(id + "-mask");
	
	menuElement.style.display='block';
	maskElement.style.display='block';

	if (browser == "Internet Explorer")
	{
		// make an iframe to mask the pop-up menus in ie/win
		var iframe = getIframeShim();
		iframe.style.width = menuElement.offsetWidth;
	  iframe.style.height = menuElement.offsetHeight;
	  iframe.style.top = menuElement.style.top;
	  iframe.style.left = menuElement.style.left;
	  iframe.style.zIndex = menuElement.style.zIndex - 1;
	  iframe.style.display = "block";
	  menuElement.parentNode.appendChild(iframe);
	}
		  
}

function hideMenu(id)
{
	if (!currentMenuId) document.getElementById(id + "-title").className=null;
	clearShowTimer();
	hideTimer = setTimeout("_hideMenu('" + id + "')", HIDE_DELAY);
}

function _hideMenu(id)
{
	document.getElementById(id + "-title").className=null;
	currentMenuId = null;

	var menuElement = document.getElementById(id + "-list");
	var maskElement = document.getElementById(id + "-mask");

	menuElement.style.display='none';
	maskElement.style.display='none';

	if (browser == "Internet Explorer")
	{
		var iframe = getIframeShim();
		menuElement.parentNode.removeChild(iframe);
		iframe.display="none";
	}
}

function clearHideTimer() {
    if (hideTimer) clearTimeout(hideTimer);
    hideTimer = null;
    //hideFlag = false;
}

function clearShowTimer() {
    if (showTimer) clearTimeout(showTimer);
    showTimer = null;
    //hideFlag = false;
}

var __iframe_shim = null;
function getIframeShim()
{
	if (!__iframe_shim)
	{
		var iframe = document.createElement("iframe");
		iframe.id = "iframe-shim";
		iframe.src = "javascript:false";
		iframe.scrolling="no";
		iframe.style.position="absolute";
		iframe.style.display="none";
		__iframe_shim = iframe;	
	}
	return __iframe_shim;
}

function DEBUG(msg)
{
	ta = document.getElementById('debug');
	ta.value += msg + "\n";
}
