$(document).ready(function(){						   	
var timeout = 1000;
var timer =0;
var i=0;
var z=0;
var emenu = null
for(var z=1;z < 4;z++){

	$("#mainmenu"+z).mouseover(function(e){	
		closetimer();
		e.preventDefault();
		$(this).children("div").slideDown("slow");		
	});
	
	$("div#submenu"+z).mouseout(function(){		
		outtimer();
	});

	$("div#submenu"+z).mouseover(function(){	
		closetimer();
		var currentId = $(this).attr('id');		
		//alert(emenu+" 1 "+currentId)
		if(emenu != currentId) 
		{
			if(emenu != null) efadeclose(emenu);
			emenu = currentId;
		}
		
	});	
}
	$("div.submenu div").mouseover(function(){		
		$(this).css({backgroundColor: '#eee'})		
	});
	
	$("div.submenu div").mouseout(function(){		
		$(this).css({backgroundColor: '#fff'})		
	});

	function closetimer(){
	 if (timer)    {
	  window.clearTimeout(timer);
	  timer = null;
	 }
	}

	function outtimer(){
		timer = window.setTimeout(fadeclose, timeout);
	}
	
	function fadeclose(){
		for(var i=1;i < 4;i++){
			$("#submenu"+i).fadeOut("fast");
		}
	}	
	
	function efadeclose(emenu){
			$("#"+emenu).fadeOut("slow");
	}

/*	$("#submenu").mouseover(function(){		
		$(this).show();		
	});	*/
	
	document.onclick = fadeclose;
	
	
	
	for(i=1;i<11;i++){
   $("#button"+i).click(function(){
        $(this).next().slideToggle("slow");
        $(this).toggleClass("bUp");
    });
	}
	
	
});
