//Manage the header menu

var navActiveTab=null; // flag for the top nav, value: ID of the selected element
var navHoverTab=null;


// Move the background of the top nav to match the situation
function moveTopNav(height) {   jQuery('#navTop ul').css('background-position', '45px '+height+'px'); }

// Reset the menu elements to off position
function resetTopNav () {   moveTopNav(-216); }

function menuTopRollover(navOver)
{
    navHoverTab = jQuery(navOver).attr('id');  //Get the ID of the tab hovered
    //console.log('Tab active: ' + navActiveTab);
    //console.log('Tab rolled over: ' + navHoverTab);
	
	switch(navHoverTab)
    {
        case 'navParisHippiques':   if(navActiveTab=='navParisSportifs')    moveTopNav(-36);
                                    else if(navActiveTab=='navPoker')       moveTopNav(-72);
                                    else                                    moveTopNav(0);
                                    break;
        case 'navParisSportifs':    if(navActiveTab=='navParisHippiques')   moveTopNav(-36);
                                    else if(navActiveTab=='navPoker')       moveTopNav(-144);
                                    else                                    moveTopNav(-108);
                                    break;
        case 'navPoker':            if(navActiveTab=='navParisHippiques')     moveTopNav(-72);
                                    else if(navActiveTab=='navParisSportifs') moveTopNav(-144);
                                    else                                      moveTopNav(-180);
                                    break;
        default:                    resetTopNav ();
                                    break;
    }
}

function menuTopRollout()
{
   	if (navActiveTab == "navParisHippiques") moveTopNav(0);
   	else if (navActiveTab == "navParisSportifs") moveTopNav(-108);
   	else if (navActiveTab == "navPoker") moveTopNav(-180);
    else resetTopNav();
    navHoverTab=null;
}

// Initiate the actions on the top menu
function iniateMenuTop()
{
    // ROLLOVER
    jQuery('#navTop ul li a').hover(
        function(){ menuTopRollover( jQuery(this) ); },
        function(){ menuTopRollout();  }
    );

    menuTopRollout();
}
