
/**
 * Functions use to show and hide dropdown menus.<b> 
 **/
 
var menuShowing = null;
var timer = "";
var okayToClose = true;
var autoClose = true;
var yOffset = 0;

function showFakeDrop(id, objPos, xOff, yOff){

	if (document.getElementById)
	{
		if (menuShowing == id){
		    hideMenuShowing();
		} else {
			if (!ie){
			  xOff = xOff + 2;
			  yOff = yOff + -2;
			}
			autoClose = false;
			showVMenuXY(id, objPos, xOff, yOff);
		}
	}
}

function showVMenu(id, objPos){showVMenuXY(id, objPos, 0, 0);}
function showVMenuXY(id, objPos, xOff, yOff)
{

	if (document.getElementById)
	{
		var x = 0;
		var y = 0;
		yOffset = yOff;
		okayToClose = false
		
		resetTimer();
		
		if (menuShowing != null)
			hideMenuShowing();
		menuShowing = id;

		x = getElementLeft(objPos) + xOff;
		y = getElementBottom(objPos) + yOff;
				
		setElementProperty(id, 'display', 'block');
		setElementProperty(id, 'left', x + "px");
		setElementProperty(id, 'top', y + "px");
	}
}

function showHMenu(id, objPos){showHMenuXY(id, objPos, 0, 0);}
function showHMenuXY(id, objPos, xOff, yOff)
{

	if (document.getElementById)
	{
		var x = 0;
		var y = 0;
		yOffset = yOff;
		okayToClose = false
		
		resetTimer();
		
		if (menuShowing != null)
			hideMenuShowing();
		menuShowing = id;

		x = getElementRight(objPos) + xOff;
		y = getElementTop(objPos) + yOff;
				
		setElementProperty(id, 'display', 'block');
		setElementProperty(id, 'left', x + "px");
		setElementProperty(id, 'top', y + "px");
	}
}

function hideMenuShowing()
{
	setElementProperty(menuShowing, 'display', 'none');
	menuShowing = null;
}

function menuClose()
{
	var callFunction = "okayToClose = true";
	timer = window.setTimeout(callFunction, 0);
}

function getMousePosition(event)
{
	var x, y;
	
	if (window.event)
	{
		y = window.event.clientY;
		x = window.event.clientX;
		if (document.documentElement && document.documentElement.scrollTop)
			y+=document.documentElement.scrollTop;
		else 
			y+=document.body.scrollTop;
	} 
	else 
	{
		y = event.pageY;
		x = event.pageX;
	}

	var inside;
	if ( menuShowing != null)
	{
		inside = insideMenu(menuShowing, x, y);
		if (!inside && okayToClose == true && autoClose == true)
			hideMenuShowing();
		if (inside )
		{
			okayToClose = true;
			resetTimer();
		}
	}
}

function doMouseDown(event){

	if (menuShowing != null && autoClose == false){
	
		var x, y;
	
		if (window.event)
		{
			y = window.event.clientY;
			x = window.event.clientX;
			if (document.documentElement && document.documentElement.scrollTop)
				y+=document.documentElement.scrollTop;
			else 
				y+=document.body.scrollTop;
		} 
		else 
		{
			y = event.pageY;
			x = event.pageX;
		}
	
	    if (insideMenu(menuShowing, x, y)){
			window.setTimeout(hideMenuShowing, 500);
		} else
			hideMenuShowing();
	}
		
}

function insideMenu(id, mouseX, mouseY)
{
	if ( (id != null) 
	    && (mouseX >= getElementLeft(id)) 
	       && (mouseX <= getElementRight(id)) 
	           && (mouseY >= (getElementTop(id) - (yOffset + 20))) 
	              && (mouseY <= getElementBottom(id)) )
	{
		return true;
	} 
	else 
		return false;
}

function resetTimer()
{
	window.clearTimeout(timer);
}

window.onload = function() 
{
	document.onmousemove = getMousePosition;
	document.onmousedown = doMouseDown;
}

