$(document).ready(function() {
    //On Hover Over
    function megaHoverOverQuick(){       
        $(this).find(".sub10").stop().show();
        $(this).find(".sub20").stop().show(); //Find sub and fade it in
    }
    
    //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
        });*/
    }
    
    //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#langnav li").hoverIntent(configQuick); //Trigger Hover intent with custom configurations
    $("ul#langnav li .sub20").css({'display':'none'}); //Fade sub nav to 0 opacity on default
    $("ul#langnav li .sub10").css({'display':'none'}); //Fade sub nav to 0 opacity on default    

    var width = 0;
    var count = 0;
    var size = $('ul#langnav li').size();
    $('ul#langnav li').each(function() {
        if( count == 0) {
            width -= $(this).offset().left;
        }
        if( count == (size-1)) {
            width += $(this).offset().left + parseInt($(this).width(),10);
        }
        var right10 = 0;        
        var next = $(this).next();
        while(typeof(next.get(0)) != "undefined") {
            right10 += next.width() + 7;            
            next = next.next();
        }
        //$(this).find(".sub10").css({'right' : right10, 'width': $(this).width() });
        $(this).find(".sub10").css({'width': 30 });         
        count++;
    });
        
    $("ul#langnav 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});
        $(this).hide();
    }); 
        
    if($.browser.msie && $.browser.version < 7){
        $("ul#langnav li .sub10").css({ "border": "1px solid #BBBBBB","border-bottom": 0, "top": -1, "right": -1, "height": 21 });
        $("ul#langnav li .sub20").css({ "border": "1px solid #BBBBBB", "left": -1 });        
    } else {
        $("ul#langnav li .sub10").shadowOn({ imageset: 102 });        
        $("ul#langnav li .sub20").shadowOn({ imageset: 2 });
    } 

});
