jQuery(document).ready(function () {
    var $ = jQuery;
    var top_levels = $('#menu>ul>li');
    
    var all_popouts = [];
    var show_popout = function (which) {
        // show popout menu immediately
        $(all_popouts).closest('li').removeClass('showing');
        $(which).closest('li').addClass('showing');
    };
    var hide_popout = function (which) {
        // hide popout menu immediately
        $(which).closest('li').removeClass('showing');
    };
    
    top_levels.each(function () {
        if ($(this).children('ul').size() == 0)
        {
            return;
        }
        $(this).hover(
            function (e) {
                top_levels.removeClass('showing');
                $(this).addClass('showing');
            },
            function (e) {
                $(this).removeClass('showing');
            }
        );
        var sub_levels = $(this).children('ul').children('li');
        sub_levels.each(function () {
            if ($(this).children('div').size() == 0)
            {
                return;
            }
            var this_popout = $(this).children('div');
            all_popouts.push(this_popout);
            $(this).hover(
                function (e) {
                    show_popout(this_popout);
                },
                function (e) {
                    hide_popout(this_popout);
                }
            );
        });
    });


    if (jQuery.browser.msie && (jQuery.browser.version <= 6))
    {
        DD_belatedPNG.fix('#menu li a, #menu li a span, #menu .menu3 div');
    }
});