dom = (document.getElementById) ? (true) : (false);
ie = (document.all) ? (true) : (false);
ie4 = ie && !dom;
nn4 = (document.layers) ? (true) : (false);

visible = (nn4) ? ('show') : ('visible');
hidden = (nn4) ? ('hide') : ('hidden');

var container_id = new Array();
var count = -1;
var timer = 0;

function mouseOver(id, a, containerId)
{
	if (timer) {
		clearTimeout(timer);
		timer = 0;
	}

	// Close containers till current or till container to open.
	while (count > -1) {
		if ((container_id[count] == id) || (container_id[count] == containerId)) {
			break;
		}
		hideNow(container_id[count]);
		count--;
	}

	// Open new popup.
	var open;
	if (!id) return;
	if (dom) open = document.getElementById(id);
	else if (ie4) open = document.all[id];
	else if (nn4) open = document.layers[id];

	if (!open) return;
	if (!nn4) open = open.style;

	if (a) {
		open.left = menuLeft(id, a) + "px"; 
		open.top = menuTop(id, a) + "px";
	}
	open.visibility = visible;

	if (container_id[count] != id) {
		count++;
		container_id[count] = id;	
	}
}

function mouseOut()
{	
	timer = setTimeout('hideAll()', 200);
}

function hideNow(id)
{
	var hide;
	if (!id) return;
	if (dom) hide = document.getElementById(id);
	else if (ie4) hide = document.all[id];
	else if (nn4) hide = document.layers[id];

	if (!hide) return;
	if (!nn4) hide = hide.style;

	hide.visibility = hidden;
}

function hideAll()
{
	while (count > -1) {
		hideNow(container_id[count]);
		count--;
	}
	timer = 0;
}

function menuLeft(id, a) 
{
	if (nn4) return document.layers['x' + id].pageX;
	else {
		var pos = a.offsetLeft - 170;
		while (a.offsetParent != null) {
			a = a.offsetParent;
			pos += a.offsetLeft;
			if (a.tagName == 'BODY') break;
		}
		return pos;
	}
}

function menuTop(id,a) 
{
	if (nn4) return document.layers['x' + id].pageY - 10;
	else {
		var pos = a.offsetTop;
		while (a.offsetParent != null) {
			a = a.offsetParent;
			pos += a.offsetTop;
			if (a.tagName == 'BODY') break;
		} 
		return pos - 10;
	}
}

