// menuthing for shiar.js
// 2003.XI.13 by Shiar
// rewritten on 2004.IV.11 by Shiar

// seems to work on moz and opera7
// (retest the above statement)

var sub     = document.getElementById ? document.getElementById('submenu') : null; //submenu element
var suby; //original position
var item    = null; //selected item
var timeout = null; //event to remove submenu

function change(thisitem, txt) {
	if (!sub) return;
	enter(); gone(); //remove previous
	item = thisitem; //select new

	sub.innerHTML = txt;

	if (!suby) suby = sub.offsetTop - sub.parentNode.offsetTop;
	sub.style.top = suby + item.offsetTop; //reposition

	item.style.background = '#600'; //highlight (and keep it so, unlike css hover)
	if (txt) sub.style.visibility = 'visible'; //show menu
}

function enter() {
	if (timeout) clearTimeout(timeout);
}

function leave() {
	enter(); //overwrite previous
	timeout = setTimeout('gone()', 700); //hide after 0.7s
}

function gone() {
	if (item) item.style.background = '#000'; //restore previous
	if (sub) sub.style.visibility = 'hidden'; //remove previous submenu
}

