var kmenu = {
        
    container: '#dd_horizontal_menu',
    
    init: function() {
         $(kmenu.container + ' li').hover(
            function () {  
                $(this).find('ul').first().show();
                $(kmenu.container).find('.hasfocus').blur().each(function() {
                    kmenu.hide(this);
                });
     
           },   
            function () {  
                $(this).find('ul').first().hide();      
           }
         );
        $(kmenu.container + ' li').find('a').bind('focus', function() {
            $(this).addClass('hasfocus');
            $(this).parents('li').find('ul').first().each(function() {
                $(this).show();
            });
        }).bind('blur', function() {
            kmenu.hide(this);
        });
    },
    
    show: function(element) {
        $(element).show();
    },
    
    hide: function(_this) {
	setTimeout(function() {		
	$(_this).removeClass('hasfocus');
	$(_this).parents('ul').each(function() {

		if($(this).find('.hasfocus').length == 0 && $(this).parent('li').hasClass('m1')) {
			$(this).hide();
		}
	});	

	$(_this).parents('li').children('ul').each(function() {
		if($(this).find('.hasfocus').length == 0) {
			$(this).hide();
		}
	});
	}, 1);
return;
        if(_this, $(_this).parents('ul').length > 1) {
            setTimeout(function() {
                $(_this).removeClass('hasfocus');
                if($(_this).parents('ul').first().find('.hasfocus').length == 0) {
                    $(_this).parents('ul').first().hide(); 
                }
            }, 1);
            
            $(_this).parents('ul').first().parent('li').first().find('a').first().each(function() {
                kmenu.hide(this);
            });
        }
    }
    
};

$(document).ready(function() {
    kmenu.init();        
});
