function menu_show_aux(parent, child){
	var p = document.getElementById(parent);
	var c = document.getElementById(child);

	var top	= (c["menu_position"] == "y") ? p.offsetHeight-1 : 0;
	var left = (c["menu_position"] == "x") ? p.offsetWidth+2 : 0;

	for (; p; p = p.offsetParent){
		top	+= p.offsetTop;
		left += p.offsetLeft;
	}

	c.style.position = "absolute";
	c.style.top	= top+'px';
	c.style.left = left+'px';
	c.style.visibility = "visible";
}

function menu_show(){
	var p = document.getElementById(this["menu_parent"]);
	var c = document.getElementById(this["menu_child" ]);

	menu_show_aux(p.id, c.id);
	clearTimeout(c["menu_timeout"]);
}

function menu_hide(){
	var p = document.getElementById(this["menu_parent"]);
	var c = document.getElementById(this["menu_child" ]);

	c["menu_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 100);
}

function menu_click(){
	var p = document.getElementById(this["menu_parent"]);
	var c = document.getElementById(this["menu_child" ]);

	if (c.style.visibility != "visible") menu_show_aux(p.id, c.id);
	else c.style.visibility = "hidden";
	return false;
}

function menu_attach(parent, child, showtype, position, cursor){
	var p = document.getElementById(parent);
	var c = document.getElementById(child);

	p["menu_parent"] = p.id;
	c["menu_parent"] = p.id;
	p["menu_child"] = c.id;
	c["menu_child"]	= c.id;
	p["menu_position"] = position;
	c["menu_position"] = position;

	c.style.position = "absolute";
	c.style.visibility = "hidden";

	if (cursor != undefined) p.style.cursor = cursor;

	switch (showtype){
		case "click":
			p.onclick = menu_click;
			p.onmouseout = menu_hide;
			c.onmouseover = menu_show;
			c.onmouseout = menu_hide;
			break;
		case "hover":
			p.onmouseover = menu_show;
			p.onmouseout = menu_hide;
			c.onmouseover = menu_show;
			c.onmouseout = menu_hide;
			break;
	}
}

