$(document).ready(function(){  
	var tShow, tHide, timer = 300;
    $('#top-menu ul li a').mouseover(function(){ 
        var link = $(this);
        tShow = setTimeout(function(){
		    var rel = link.attr('rel'); 
            link.addClass('selected-top-menu'); 
            if ( rel != 'empty' ) {
                $('#sub-menu-hover').show();
			    $('#sub-menu-hover').attr('rel', rel);
			    $('#sub-menu-hover').children('div').each(function(){
				    $(this).hide();
			    });
			    $('#' + rel).show();
            }  
        }, timer);                      
	});
	$('#top-menu ul li a').mouseout(function(){
        var link = $(this);
        tHide = setTimeout(function(){ 
		    var rel = link.attr('rel');  
            if ( rel != '' ) {
			    $('#sub-menu-hover').hide();
		    } 
            link.removeClass('selected-top-menu');  
		}, timer); 
        
	});
	$('#sub-menu-hover').mouseover(function(){
        var rel = $(this).attr('rel');
        clearTimeout(tHide);
		$('#sub-menu-hover').show();
		$('a[rel="' + rel + '"]').addClass('selected-top-menu');
	}).mouseout(function(){ 
		var rel = $(this).attr('rel');
        clearTimeout(tShow);
        tHide = setTimeout(function(){ 
		    $('#sub-menu-hover').hide();
		    $('a[rel="' + rel + '"]').removeClass('selected-top-menu');
        }, timer);    
	});
});
