var submenuId = false;
var hideTimeoutId = false;

function showSubmenu( id ) {
	if ( submenuId == id ) {
		holdSubmenu();
	} else {
		finishHideSubmenu();
	}
	submenuId = id;
	obj = document.getElementById( id );
	obj.style.display = 'block';
}

function hideSubmenu() {
	hideTimeoutId = setTimeout( 'finishHideSubmenu()', 1 );
}

function holdSubmenu() {
	if ( !hideTimeoutId ) {
		return;
	}
	clearTimeout( hideTimeoutId );
}

function finishHideSubmenu() {
	if ( !submenuId ) {
		return;
	}
	if ( hideTimeoutId ) {
		clearTimeout( hideTimeoutId );
	}
	obj = document.getElementById( submenuId );
	obj.style.display = 'none';
	hideTimeoutId = false;
}

function setSubmenuPosition( id ) {
	pos = findPos( document.getElementById( id + '_pos' ) );
	obj = document.getElementById( id );
	obj.style.left = pos[0] + 'px';
	obj.style.top = pos[1] + 'px';
}


/* code from: http://www.quirksmode.org/js/findpos.html */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
				curleft += obj.offsetLeft;
				curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
