﻿function SetupNavigation() {
    var level1CurrentItem = $("");
    var level2CurrentItem = $("");

    $("ul#navigation > li").mouseenter(function () {
        level1CurrentItem.clearQueue().stop();
    });

    $("ul#navigation > li > a").mouseenter(function () {
        var li = $(this).parent();
        level1CurrentItem.hide();
        level2CurrentItem.hide();
        level1CurrentItem = li.children("ul").show().clearQueue().stop();
    });

    $("ul#navigation > li").mouseleave(function () {
        var li = $(this);
        li.children("ul").delay(1000).fadeOut(1);
    });

    $("ul#navigation > li > ul > li").mouseenter(function () {
        level2CurrentItem.clearQueue().stop();
    });

    $('ul#navigation > li > ul > li > a').mouseenter(function () {
        var li = $(this).parent();
        level2CurrentItem.hide();
        level2CurrentItem = li.children("ul").clearQueue().stop();
        if (li.children("ul").length > 0)
            $("div#navLower_outer").slideDown(200, function () { level2CurrentItem.show(); });
        else
            $("div#navLower_outer").slideUp(200);

    });

    $("ul#navigation > li > ul").mouseleave(function () {
        level2CurrentItem.hide();
        $('div#navLower_outer').slideUp(200);
    });

    $('ul#navigation > li > ul > li').mouseleave(function () {
        var li = $(this);
        li.children("ul").delay(1000).fadeOut(1);
    });
}


function FadeOut(elem) {
    return setTimeout(function () { elem.fadeOut(); }, 1000);
}
