﻿var obj = null;

$(document).ready(function() {
    $('.menu > li').hover(function() {
        //
        //Si un menu est affiché, on le cache pour n'afficher que celui qui est survolé
        //
        if (obj) {
            obj.find('ul').fadeOut('fast');
            obj = null;
        }
        //
        //Réalignement du dernier menu sur le bord droit pour ne pas sortir du cadre en 1024px
        //
        var x = $(window).width() - ($(this).position().left + $(this).find('ul').width());
        if (x < 0)
            $(this).find('ul').css("marginLeft", (-1) * ($(this).find('ul').width() - ($(this).width() + 1)));
            
        //
        //Affiche le sous menu
        //
        $(this).find('ul').fadeIn('fast');
    },
    function() {
        //
        //Lors du mouseout
        //
        obj = $(this);
        setTimeout("checkHover()", 200); // on définit que le menu disparait au bout de 2 secondes non survolées
    });
});

//
//Cache le menu
//
function checkHover() {
    if (obj)
        obj.find('ul').slideToggle('fast');
}