$(document).ready(function() {
    //On Hover Over
    function megaHoverOverQuick(){
        stopSwitch(); //Stop the rotation

        var next = $(this).next();
        while(typeof(next.get(0)) != "undefined") {
            next.find(".sub10").stop().hide();
            next.find(".sub20").stop().hide();
            next = next.next();            
        }
        var prev = $(this).prev();
        while(typeof(prev.get(0)) != "undefined") {
            prev.find(".sub10").stop().hide();
            prev.find(".sub20").stop().hide();
            prev = prev.prev();            
        }
        $(this).find(".sub10").stop().show();
        $(this).find(".sub20").stop().show();
    }
    
    //On Hover Out
    function megaHoverOutQuick(){
        $(this).find(".sub10").stop().hide();
        $(this).find(".sub20").stop().hide();
        /*$(this).find(".sub20").stop().fadeTo(100, 0, function() { //Fade to 0 opactiy
          $(this).hide();  //after fading, hide it
        });*/
        rotateSwitch();
    }
    
    //Set custom configurations
    var configQuick = {
         sensitivity: 100, // number = sensitivity threshold (must be 1 or higher)
         interval: 0, // number = milliseconds for onMouseOver polling interval
         over: megaHoverOverQuick, // function = onMouseOver callback (REQUIRED)
         timeout: 0, // number = milliseconds delay before onMouseOut
         out: megaHoverOutQuick // function = onMouseOut callback (REQUIRED)
    };
        
    $("ul#quicknav li").hoverIntent(configQuick); //Trigger Hover intent with custom configurations    
    $("ul#quicknav li .sub20").css({'display':'none'}); //Fade sub nav to 0 opacity on default
    $("ul#quicknav li .sub10").css({'display':'none'}); //Fade sub nav to 0 opacity on default    

    var count = 0;
    var size = $("ul#quicknav").children().size();
    var width = 0; //$.browser.msie ? size : size-1;
    var left20 = 0;
    $("ul#quicknav").children().each(function() {
        var tmp = parseInt($(this).width(),10);
        if(tmp % 2 == 1) {                  
            $(this).css({'padding-left': 2});
            $(this).find(".sub10").css({'padding-left': 2});
            width++;
        }          
        if( count == 0) {        
            left20 = $(this).get(0).offsetLeft;
            width -= left20;;
        }        
        if( count == (size-1)) {
            width += $(this).get(0).offsetLeft + tmp;
        }
        $(this).find(".sub10").css({'width': tmp});
        $(this).find(".sub10").css({'left' : $(this).get(0).offsetLeft});
                
        count++;
        return true;
    });
        
    $("ul#quicknav li .sub20").each(function() {
        $(this).show();
        rowHeight = 0;
        //Calculate row
        $(this).find("ul").each(function() { //for each ul...
            if($(this).height() > rowHeight)
                rowHeight = $(this).height(); //Add each ul's width together
        });
        $(this).css({'height': rowHeight, 'width': width, 'left': left20});
        $(this).hide();
    }); 
    
    if($.browser.msie && $.browser.version < 7){
        $("ul#quicknav li .sub10").css({ "border": "1px solid #BBBBBB","border-bottom": 0 });
        $("ul#quicknav li .sub20").css({ "border": "1px solid #BBBBBB" });        
    } else {
        $("ul#quicknav li .sub10").shadowOn({ imageset: 102});        
        $("ul#quicknav li .sub20").shadowOn({ imageset: 2});      
    }       

});
