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( $j.browser.msie ) {
			var diff = -2;
		} else {
			var diff = -3;
		}
		a.style.borderBottom = '0';
		/*sub.style.top = pos.top + a.offsetHeight + diff + 'px';
		sub.style.left = pos.left + 'px';*/
		sub.style.top = pos.top + 'px';
		sub.style.left = pos.left + a.offsetWidth - 40 + diff + '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';
	}
	doTheSubHide();
}

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


var subsubmenu_timeout;
var active_subsubmenu;

function showSubSubMenu( a, id ) {
	doTheSubHide();
	clearSubHide();
	clearHide();
	
	var sub = document.getElementById( 'subsubmenu_' + id );
	active_subsubmenu = sub;
	
	if( sub ) {
		var pos = findObjPos( a );
		
		if( $j.browser.msie ) {
			var diff = -2;
		} else {
			var diff = -3;
		}
		a.style.borderBottom = '0';
		/*sub.style.top = pos.top + a.offsetHeight + diff + 'px';
		sub.style.left = pos.left + 'px';*/
		sub.style.top = pos.top + 'px';
		sub.style.left = pos.left + 42 + a.offsetWidth - 40 + diff + 'px';
		sub.style.zIndex = '9999';
		sub.style.display = 'block';
		
		if( sub.offsetWidth < a.offsetWidth ) {
			sub.style.width = a.offsetWidth + 'px';
		}
	}
}

function clearSubHide() {
	window.clearTimeout( subsubmenu_timeout );
	window.clearTimeout( submenu_timeout );
}

function doTheSubHide() {
	if( active_submenu && active_subsubmenu ) {
		active_subsubmenu.style.display = 'none';
	}
}

function hideSubSubMenu() {
	hideSubMenu();
	subsubmenu_timeout = window.setTimeout( 'doTheSubHide();', 10 );
}


var subsubsubmenu_timeout;
var active_subsubsubmenu;

function showSubSubSubMenu( a, id ) {
	//doTheSubSubHide();
	//clearSubSubHide();
	//clearSubHide();
	doTheSubSubHide();
	
	var sub = document.getElementById( 'subsubsubmenu_' + id );
	active_subsubsubmenu = sub;
	
	if( sub ) {
		var pos = findObjPos( a );
		
		if( $j.browser.msie ) {
			var diff = -2;
		} else {
			var diff = -3;
		}
		
		a.style.borderBottom = '0';
		sub.style.top = a.offsetTop + 'px';
		sub.style.left = a.offsetWidth - 4 - diff + 'px';
		
		sub.style.zIndex = '9999';
		sub.style.display = 'block';
		
		if( sub.offsetWidth < a.offsetWidth ) {
			sub.style.width = a.offsetWidth + 'px';
		}
	}
}

function clearSubSubHide() {
	window.clearTimeout( subsubsubmenu_timeout );
	//window.clearTimeout( subsubmenu_timeout );
	//window.clearTimeout( submenu_timeout );
}

function doTheSubSubHide() {
	if( active_subsubsubmenu ) {
		active_subsubsubmenu.style.display = 'none';
	}
}

function hideSubSubSubMenu() {
	//hideSubSubMenu();
	subsubsubmenu_timeout = window.setTimeout( 'doTheSubSubHide();', 10 );
}
