/** menus **/

function Menus()
{
}

Menus.activeElement = null;
Menus.activeFog = null;
Menus.hider = null;
Menus.rolledTitle = null;

var intId = 0;
var posi = 517;
var title = null;
var roll = false;
var end = true;

Menus.prototype.mouseOver = function(element)
{
    if( (element == Menus.activeElement) || (element == Menus.activeSrc) || (element == Menus.activeFog) ) {
		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 );
    var foggy = document.getElementById( "fog_" + subId );
    var top = document.getElementById( "divTop" );
    title = document.getElementById( "divTitle" );

    if( !child  || !foggy) return;
    
    if( Menus.activeElement != null )
    	this.finalCleanup();

    var pos = getPageCoords( element );
    var posTop = getPageCoords( top );
    var posTitle = getPageCoords( title );
    var dim = element.offsetWidth / 2;
    
    var offX = pos.x - 80 + dim;
    if (offX < posTop.x)
    	offX = posTop.x-1;
    if (offX > (posTop.x+800))
    	offX = posTop.x+641;
    	
    foggy.style.left = offX + "px";
    foggy.style.top = (pos.y + 45) + "px";
    foggy.style.display = "block";

   	child.style.left = offX + "px";
  	child.style.top = (pos.y + 45) + "px";
    child.style.display = "block";
    
    if((offX+180) > posTitle.x && !roll)
    {
    	end = true;
   		this.rollTitle();	
   	}
   	if(offX <(posTitle.x+280) && !roll)  
   	{
   		end = false;
   		this.rollTitle();
   	}
    
    Menus.rolledTitle = title;
    Menus.activeElement = child;
    Menus.activeFog = foggy;

}

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.activeFog != null ) {
    	Menus.activeFog.style.display = "none";
    }
    
 /*   if( Menus.rolledTitle != null){
	   
   
    } */
    
    Menus.hider = null;
    Menus.activeElement = null;
    Menus.rolledTitle = null;
}

Menus.prototype.rollTitle = function()
{
	if(posi>500 && end)
	{
		roll=true;
		posi = 517;
		intId = window.setInterval(function(){ if(posi>50){posi-=48; title.style.left=posi+"px";}else{window.clearInterval(intId); roll=false; end=false; title.style.left="44px" } }, 40);
	}
	
	if(posi<60 && !end)
	{
		roll=true;
		posi = 44;
		intId = window.setInterval(function(){ if(posi<510){posi+=48; title.style.left=posi+"px";}else{window.clearInterval(intId); roll=false; end=true; title.style.left="517px" } }, 40);
	}
}
