$(document).ready(function(){
//dropdown menu where necessary
/*	$("ul.menu li").hover(
		function(){
			$(this).children("ul").css({"display":"block"});
			},
		function(){
			$(this).children("ul").css({"display":"none"});	
			}
		)
*/
	var active, next, timer;
	$("ul.menu li").each(function(){
		
		var automat;
		var submenu = $(this).children("ul");
		
		//Timer
		function delayTimer(delay){
			var timer;
			return function(fn){
				timer = clearTimeout(timer);
				if(fn){timer = setTimeout(function(){fn();},delay);};
				return timer;	
				}
			};
		
		//Hover controller	
		$(this).hover(
			function(){show()},
			function(){
				automat = delayTimer(250);
				automat(function(){hide()});
				});
		
		function show(){
			submenu.css({"display":"block"});
			automat();
			}
		
		function hide(){
				submenu.css({"display":"none"});
			}
		
	})
})

