

$(function(){
	
	var timer;
	
	$('#main-menu>li:has(ul)').hover(
		function() {
			$(this).parent().children('li').not($(this)).children('ul').animate({ height: 'hide' }, 300);
			$(this).parent().children('li').not($(this)).removeClass('hovered');
			if (!$(this).hasClass('hovered')) {
				$(this).children('ul').css({ display: 'none' });
				$(this).children('ul').animate({ height: 'show' },300);
				$(this).addClass('hovered');
			}
			clearTimeout(timer);
		},
		function() {
			timer = setTimeout(
				function() { 
					$('li.hovered').children('ul').animate({ height: 'hide' }, 300); 
					$('li.hovered').removeClass('hovered'); 
				}, 1000
			);
		}
	);
	
});


