var mnuActive=false;
var mnuButtonActive=false;
var mnuActiveName='';
var mnuButtonName='';

var hideTimeout;
var layer2Hide;

function timeOut(hide){
	hideTimeout = window.setTimeout(hide, 500);
	layer2Hide = hide;
}

function clearTime(){
	window.clearTimeout(hideTimeout);
}

function hideLayer() {
	deactivateOpen();
}

function activate(theLayer, theObject)
{
	if(layer2Hide == "hideLayer()") window.clearTimeout(hideTimeout);

	deactivateOpen();
	mnuActive = true;
	mnuActiveName = theLayer;
	mnuButtonActive = true;
	mnuButtonName = theObject
	var coords = getPageCoords(theObject);
    document.getElementById(theLayer).style.visibility="visible";
    document.getElementById(theLayer).style.left = coords.x
	document.getElementById(theLayer).style.top = coords.y
}

function deactivateOpen()
{
	if (mnuButtonActive) {
		mnuButtonActive = false;
		mnuButtonName = '';
	}
	if (mnuActive) {
		theLayer = mnuActiveName;
		document.getElementById(theLayer).style.visibility="hidden";
		mnuActive = false;
		mnuActiveName = '';
	}
}

function deactivate(theLayer,theObject,theEvent)
{
	document.getElementById(theLayer).style.visibility="hidden";
	if (mnuButtonActive) {
		mnuButtonActive = false;
		mnuButtonName = '';
	}
}

function getPageCoords (elementId) {
  var coords = {x: 0, y: 0}
  var element;
  var height;
  element = document.getElementById(elementId);
  height = element.offsetHeight;
//  while (element) {
    coords.x += element.offsetLeft;
    coords.y += element.offsetTop;
//    element = element.offsetParent;
//  }
  coords.y = coords.y + height -1;
  coords.x = coords.x -1;
  return coords;
}

