
var ie4 = document.all;
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all; 

//alert(ie4 + ", " + ns4 + ", " + ns6 );
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;
}

var _tid = 0;
var _mname = '';

function hideMenu() {
	clearTimeout(_tid);
	_tid = 0;
	/*
	name = 'menu' + n;
	v = document.getElementById(name);
	*/
	v = document.getElementById(_mname);
	if(v)
		v.style.display = 'none';
	_mname = '';
}

function killTimer() {
	clearTimeout(_tid);
	_tid = 0;
}

function startTimer() {
	_tid = setTimeout(hideMenu, 1000);
}

function showMenu(n) {
	hideMenu();
	name = 'menua' + n;
	
	a = document.getElementById(name);
	x = findPosX(a);
	y = findPosY(a);

	// Get the page height
	bd = document.getElementsByTagName('body');
	b = bd[0];
	
	// Display the menu in the right location
	_mname = 'menu' + n;
	v = document.getElementById(_mname);

	nodes = v.childNodes;
	ct = 0;
	for(i=0; i<nodes.length; i++) {
		if(nodes[i].nodeType == 1) { // an element
			nodes[i].onmouseover = Function("killTimer();");
			nodes[i].onmouseout = Function("startTimer();");
			ct++;
		}
	}

	yp = y;
	if(ie4) {
		yp+=15;
		x+=10;
	}
	yp = yp - (17*ct) - 3;

	v.style.display = 'block';
	v.style.left = x+ 'px';
	v.style.top = yp + 'px';
	

	// Hide the menu after a timeout	
	_tid = setTimeout(hideMenu, 2000);

}

