$(document).ready(function() {
    menu = $('#OliveMenu');
    //var menuH = $('LI.top:first', menu).height();
    var menuH = 25;
    //var menuW = $('LI.top:first', menu).width()-3;
    $('LI.top', menu).each(function() {
        var menuW = $(this).width()-3;
        var subH = $('>UL LI', this).length*menuH;
        /*
        var subH = 0;        
        $('>UL LI', this).each(function() {
        });
        console.log('------------');
        */
        var subH = $('>UL LI', this).length*menuH;
        $(">UL", this).width(menuW).height(subH+10);
    });
    $('LI.top', menu).hover(
        function() { 
            if ($(this).attr('mode') == 'on') {
                $(this).addClass('hover').attr('mode', 'off');
                $(">UL", this).slideDown(450);
            }
        },
        function() {
            if ($(this).attr('mode') == 'off') {
                $(this).removeClass('hover'); 
                $(">UL", this).slideUp(350, function() {
                    $(this).parent().attr('mode', 'on'); 
                });
            }
        }
    );
    
    /*        
    $('LI.top[mode=on]', menu).mouseenter(function() { 
        //$('LI.top', menu).attr('mode', 'on');
        //$(this).attr('mode', 'off').addClass('hover');
        $(this).addClass('hover').attr('mode', 'off');
        $(">UL", this).slideDown(450);
    })
    
    $('LI.top', menu).mouseleave(function() {
        $(this).removeClass('hover'); 
        $(">UL", this).stop(true, true).slideUp(350, function() { 
            $(this).parent().attr('mode', 'on'); 
        });
    });
    */

    /*
    $('LI.top', menu).hover(
        function(event1) { console.log('LI: ' + event1.type); },
        function(event2) { console.log('LI: ' + event2.type); }
    );
    
    $('UL.sub', menu).hover(
        function(event1) { console.log('UL: ' + event1.type); },
        function(event2) { console.log('UL: ' + event2.type); }
    );
    */
    
    /*
    $('.top', menu).each(function() { 
        if ($('.sub LI', this).length == 1) $('>A', this).attr('href', $('.sub LI>A', this).attr('href'));
    });
    */
    
    if ($('.categorySubHeader:first').text() == 'Store Cupboard') {
        $('#orange_menu > UL.sub').clone().appendTo('.categorySubHeader:first').addClass('AddMenu').width(200);
        
    }

});
