	var navTimeout;
	var shouldHide = true;
	var hiding_all = false;
	function check_bottom_menu() {
		navTimeout = setTimeout(function() {
			if(shouldHide && !hiding_all) {
				hiding_all = true;
				$('#navbar').find('ul ul').stop(true,true).slideUp();
			}
		}, 1500);
	
	}
	$(document).ready(function() {
		$('#navbar ul ul').each(function () {
			var num = $(this).width();
			var parent_width = $(this).parent('li').width()+8;
			if (num>parent_width) 
				offset = "-"+Math.floor((num-parent_width)/2)+"px";
			else
				offset = Math.floor((parent_width-num)/2)+"px";
			$(this).css('margin-left',offset);
			$('li',this).width((num-21));
		});
		
		$('#navbar ul li a.top-level-menu').hover(function() { 
			hiding_all = false;
			$('#navbar').find('ul ul').css('z-index',900).stop(true,true).slideUp();
			$(this).parent('li').find('ul').stop(true,true).css('z-index',999).slideDown();
			shouldHide = false;
			}, function() { return; });
			
		$('#navbar ul ul').hover(function() {
			hiding_all = false;
			shouldHide = false;
		});
		
		$('#navbar ul ul').bind('mouseleave', function() { 
			shouldHide = true;
			check_bottom_menu();
		});		
		$('#navbar ul li a.top-level-menu').bind('mouseleave', function() { 
			shouldHide = true;
			check_bottom_menu();
		});		
		
	});
