var hideTimer = null;
var startTime = new Date();
var activeMenu = null;

function findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

function show(divName) {
	var obj = findObj(divName);
	if(obj) {
		obj.style.visibility = "visible";
	}
}

function hide(divName) {
	var obj = findObj(divName);
	if(obj) {
		obj.style.visibility = "hidden";
	}
}

function rolledOut() {
	lmStartTimeout();
}

function keepActive() {
	if(hideTimer) clearTimeout(hideTimer);
}

function lmStartTimeout() {
	startTime = new Date();
	hideTimer = setTimeout("hideSubmenu()", 500);
}
function hideSubmenu() {
	if(activeMenu != null) {
		activeMenu.style.visibility = "hidden";
		showPophide();
	}
	if(hideTimer) clearTimeout(hideTimer);
}

function reallyHideSubmenu() {
	if(activeMenu != null) {
		activeMenu.style.visibility = "hidden";
		showPophide();
	}
	if(hideTimer) clearTimeout(hideTimer);
}

function showSubmenu(menuName) {
	if(activeMenu != null) {
		reallyHideSubmenu();
	}
	var item = findObj(menuName);
	item.style.visibility = "visible";
	activeMenu = item;
	hidePophide();
}

function hidePophide() {
	messageBox("Hiding pophide");
	var pophide = findObj("pophide");

	if(pophide != null) {
		pophide.style.visibility = "hidden";
	}
}

function showPophide() {
	messageBox("Showing pophide");
	var pophide = findObj("pophide");
	if(pophide != null) {
		pophide.style.visibility = "visible";
	}
}

function positionMenu(menuName, item) {
	var xitem = menuName + "_pos";
	var x = findPosX(xitem);
	var y = findPosY(xitem);
	x += 5;
	y += 16;
	doposition(item, x, y);
}

function doposition(menu, x, y) {
	menu.style.top = y;
	menu.style.left = x;
}


function messageBox(mess) {
	var debugarea = findObj("debug");
	if(debugarea) {
		//debugarea.innerHTML = mess;
	}
}