var submenu_timeout;
var active_menu;
var active_submenu;

function findObjPos( obj ) {
	if( obj.offsetParent ) {
		var pos = new Object();
		pos.left = pos.top = 0;

		do {
			pos.left += obj.offsetLeft;
			pos.top  += obj.offsetTop;
		} while( obj = obj.offsetParent );

		return pos;
	}
}

function showSubMenu( a, id ) {
	doTheHide();
	clearHide();
	
	var sub = document.getElementById( 'submenu_' + id );
	active_menu = a;
	active_submenu = sub;
	
	if( sub ) {
		var pos = findObjPos( a );
		
		if( $.browser.msie ) {
			var diff = -2;
		} else {
			var diff = -3;
		}
		a.style.borderBottom = '0';
		sub.style.top = pos.top + a.offsetHeight + diff + 2 + 'px';
		sub.style.left = pos.left + 20 + 'px';
		sub.style.zIndex = '9999';
		sub.style.display = 'block';
		
		if( sub.offsetWidth < a.offsetWidth ) {
			sub.style.width = a.offsetWidth + 'px';
		}
	}
}

function clearHide() {
	window.clearTimeout( submenu_timeout );
}

function doTheHide() {
	if( active_menu && active_submenu ) {
		active_submenu.style.display = 'none';
	}
}

function hideSubMenu() {
	submenu_timeout = window.setTimeout( 'doTheHide();', 10 );
}
