menuOut = "";

$(document).ready(function () {
    $('#main-menu-container ul a').hover(function () {
        menuHover = Right($(this).attr("id"), 1);
        if (menuOut != "" && menuOut != menuHover) {
            $('#sub-menu-wrapper').stop().animate({ bottom: -66 }, 200, function () { hideMenus(); liftMenu(menuHover); });
        } else {
            liftMenu(menuHover);
        }
    }, function () {
        //collapseMenu();
    });

    $('#menu-collapser').hover(function () {
        $(this).css("visibility", "hidden");
        collapseMenu();
    });

    function liftMenu(menuToShow) {
        menuOut = menuToShow;
        $('#sub-menu-' + menuToShow).css("visibility", "visible");
        $('#sub-menu-wrapper').animate({ bottom: 0 }, 200, function () { $('#menu-collapser').css("visibility", "visible"); });
    }

    function collapseMenu() {
        $('#sub-menu-wrapper').stop().animate({ bottom: -66 }, 150, function () { hideMenus(); menuOut = ""; });
    }

    function hideMenus() {
        $('div .sub-menu').css("visibility", "hidden"); 		// Sostituire con un ciclo for per incrementare velocità !
    }

});
