var timeout	= 500, timer = null, menuitem = null;


function get_x(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 get_y(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;
}



function show_dropdown(id) {	
	stop_timer();
	if (menuitem) 
		menuitem.style.visibility = 'hidden';
	menuitem = document.getElementById(id);
	anchor = document.getElementById(id + "-anchor");
	menuitem.style.top = (get_y(anchor)+anchor.offsetHeight) + "px";
	menuitem.style.left = get_x(anchor) + "px";
	menuitem.style.visibility = 'visible';
}

function hide_dropdown() {
	if (menuitem)
		menuitem.style.visibility = 'hidden';
}

function start_timer() {
	timer = window.setTimeout(hide_dropdown, timeout);
}

function stop_timer() {
	if (timer) {
		window.clearTimeout(timer);
		timer = null;
	}
}

document.onclick = hide_dropdown; 

