var cur_menu;

function close_menu(menu) {
    if (menu == cur_menu) cur_menu = null;

    if ($('.menu', menu).length) {
        $(".menu", menu).hide();
    }

    $(menu).removeClass("current");
};

function check_for_close_menu() {
    if (cur_menu) close_menu(cur_menu);
}

$(document).ready(function() {
    $("body").click(check_for_close_menu);

    $("#top_bar li.nav").hover(
        function() {
            $("a", this).blur();

            if (cur_menu) {
                if (cur_menu == this) return true;

                close_menu(cur_menu);
            }

            cur_menu = this;

            $(this).addClass("current");
            $(".menu", this).show();

            return false;
        }, function() { close_menu(this); }
    );
});
