/** menus **/

function Menus()
{
}

Menus.activeElement = null;
Menus.srcElement = null;
Menus.shadowElement = null;
Menus.hider = null;

Menus.prototype.mouseOver = function(element)
{
    if( (element == Menus.activeElement) || (element == Menus.activeSrc) || (element == Menus.shadowElement) ) {
		if( Menus.hider != null ) {
		    clearTimeout( Menus.hider );
		    Menus.hider = null;
		}
		return;
    }

    if( Menus.activeElement != null ) {
		if( Menus.hider != null )
		    clearTimeout( Menus.hider );
		Menus.hider = null;
		this.finalCleanup();
    }

    var subId = element.getAttribute( "subid" );
    var child = document.getElementById( "sub_" + subId );

    if( !child  ) return;

    var pos = getPageCoords( element );

    child.style.left = pos.x + "px";
    child.style.top = (pos.y + 39) + "px";
    child.style.width = (element.offsetWidth - 14) + "px";
    child.style.display = "block";
    Menus.activeElement = child;
    Menus.srcElement = element;
    
    Menus.shadowElement = document.createElement( "DIV" );
    Menus.shadowElement.style.position = "absolute";
    Menus.shadowElement.style.background = "#89c0f9";
    Menus.shadowElement.style.zIndex = 88;
	Menus.shadowElement.style.left = (pos.x - 20) + "px";
	Menus.shadowElement.style.top = (pos.y - 8) + "px";
	Menus.shadowElement.style.width = (element.offsetWidth + 40) + "px";
	Menus.shadowElement.style.height = "334px";
	Menus.shadowElement.style.display = "block";
	Menus.shadowElement.style.opacity = "0.85";
	Menus.shadowElement.style.filter = "alpha(opacity=85)";
	
	if( Menus.shadowElement.style.setAttribute )
		Menus.shadowElement.style.setAttribute( "-moz-opacity", "0.85" );

	document.body.appendChild( Menus.shadowElement );
	
	setEventHandler( Menus.shadowElement, "mouseover", function() { menu.mouseOver( Menus.shadowElement ); } )
	setEventHandler( Menus.shadowElement, "mouseout", function() { menu.mouseOut( Menus.shadowElement ); } )
}

Menus.prototype.mouseOut = function(element)
{
    if( Menus.hider != null ) return;
    if( Menus.activeElement == null ) return;

    Menus.hider = setTimeout( this.finalCleanup, 800 );
}

Menus.prototype.finalCleanup = function()
{
    if( Menus.activeElement != null ) Menus.activeElement.style.display = "none";
    if( Menus.shadowElement != null ) {
    	document.body.removeChild( Menus.shadowElement );
    	Menus.shadowElement = null;
    }
    Menus.hider = null;
    Menus.srcElement = null;
    Menus.activeElement = null;
}
