// <script>
function show_at(item, child)
{
	var p = document.getElementById(item);
	var c = document.getElementById(child);

	p.className = "active";

	var top	= (c["at_position"] == "y") ? p.offsetHeight+1 : 0;
	var left = (c["at_position"] == "x") ? p.offsetWidth+1 : 0;

	for (; p; p = p.offsetParent)
	{
		if (p.style.position != 'absolute')
		{
			left += p.offsetLeft;
			top	+= p.offsetTop;
		}
	}

	c.style.position	 = "absolute";
	c.style.top				 = top +'px';
	c.style.left			 = left+'px';
	c.style.visibility = "visible";
}

function hide(item, child)
{
	document.getElementById(item).className = "item";
	document.getElementById(child).style.visibility = "hidden";
}

function show_at_p()
{
	c = document.getElementById(this["at_child"]);
	show_at(this.id, c.id);
	clearTimeout(c["at_timeout"]);
}

function show_at_c()
{
	p = document.getElementById(this["at_parent"]);
	show_at(p.id, this.id);
	clearTimeout(this["at_timeout"]);
}

function hide_p()
{
	c = document.getElementById(this["at_child"]);
	c["at_timeout"] = setTimeout("hide('"+this.id+"', '"+c.id+"')", 50);
}

function hide_c()
{
	p = document.getElementById(this["at_parent"]);
	this["at_timeout"] = setTimeout("hide('"+p.id+"', '"+this.id+"')", 50);
}

function attach_at(item, child, position)
{
	p = document.getElementById(item);
	c = document.getElementById(child);

	p["at_child"]		 = c.id;
	c["at_parent"]	 = p.id;
	c["at_position"] = position;

	p.onmouseover = show_at_p;
	c.onmouseover = show_at_c;
	p.onmouseout	= hide_p;
	c.onmouseout	= hide_c;
}

function menu_build_x(item, child, position)
{
	document.getElementById(item).className = "item";

	document.write('<div class="vert_menu" id="'+item+'_child">');

	var n = 0;
	for (var i in child)
	{
		if (i == '-')
		{
			document.getElementById(item).href = child[i];
			continue;
		}

		if (typeof child[i] == "object")
		{
			document.write('<a class="item" id="'+item+'_'+n+'">'+i+'</a>');
			menu_build_x(item+'_'+n, child[i], "x");
		}
		else document.write('<a id="'+item+'_'+n+'" href="'+child[i]+'">'+i+'</a>');
		n++;
	}

	document.write('</div>');

	attach_at(item, item+"_child", position);
}

function make_menu(menu)
{
	for (var i in menu)
		menu_build_x(i, menu[i], "y");
}
