$(document).ready(function(){
    var t1
        ,t2
        ,slide_up_speed=100
        ,slide_down_speed=100
        ,slide_right_speed=150
        ,mouse_leave_timeout=300;
            
    //hide background:
        
    $('.l1h').each(function(){
        $(this).children('.l1:last').children('a').css('background', 'none');
    });

    $('.l2h').each(function(){
        $(this).children('.l2:last').children('a').css('background', 'none');
    });
    
    /**
     * attach event on moving top menu items.
     */
    $('.l0').mousemove(function(){
            
        clearTimeout(t1);
        
        $('.l1h').not($(this).children('.l1h')).slideUp(slide_up_speed);
        $('.l1h').children('.l2h').hide();
            
        $(this)
        .children('.l1h')
        .not(':visible')
        .not(':animated')
        .slideDown(slide_down_speed);
    })
    .mouseleave(function(){
        var t = this;
            t1=setTimeout(
                function(){
                    $(t).children('.l1h').slideUp(slide_up_speed); 
                }, mouse_leave_timeout);
    });
        
    $('.l1').mousemove(function(){
        var elt = $(this)
        .children('.l2h')
        .not(':visible')
        .not(':animated');
            
        $('.l2h')
        .not($(this).children('.l2h'))
        .hide();
                
        elt
            .data('auto_width', elt.width())
            .css('width',0)
            .animate({
                width: elt.data('auto_width') + 'px'
            }, slide_right_speed)
            .show();
    });
});
