$(document).ready(function(){
	//Fix Errors - http://www.learningjquery.com/2009/01/quick-tip-prevent-animation-queue-buildup/
	
	var ce=document.getElementById("submenu");
	function moveup()
	{
	}	
	
		function txt1(b)
		{
		if(b!=-1)
		{
		if(document.getElementById("sub1").style.display=="block") { document.getElementById("sub1").style.display="none"; }
		if(document.getElementById("sub2").style.display=="block") { document.getElementById("sub2").style.display="none"; }
		if(document.getElementById("sub3").style.display=="block") { document.getElementById("sub3").style.display="none"; }
		if(document.getElementById("sub4").style.display=="block") { document.getElementById("sub4").style.display="none"; }
		if(document.getElementById("sub5").style.display=="block") { document.getElementById("sub5").style.display="none"; }
		if(document.getElementById("sub6").style.display=="block") { document.getElementById("sub6").style.display="none"; }
		if(document.getElementById("sub7").style.display=="block") { document.getElementById("sub7").style.display="none"; }
		if(document.getElementById("rodovnik")!=null)
		{
		if(document.getElementById("rodovnik").style.display=="block") { document.getElementById("rodovnik").style.display="none"; }		
		}
		
		switch (b)
		{
		case 0:
		  document.getElementById("sub1").style.display="block";
	    break;
		case 1:
		  document.getElementById("sub2").style.display="block";
	    break;
		case 2:
		  document.getElementById("sub3").style.display="block";
	    break;
		case 3:
		  document.getElementById("sub4").style.display="block";
	    break;
		case 4:
		  document.getElementById("sub7").style.display="block";
	    break;
		case 5:
		  document.getElementById("sub5").style.display="block";
	    break;
		case 6:
		  document.getElementById("sub6").style.display="block";
	    break;
		case 7:
		  document.getElementById("rodovnik").style.display="block";
	    break;		
		}
		}					
		}	
		
	//When mouse rolls over
	$("#mmm li").mouseover(function(){
		var a=$(this).parent().find('li').index(this);
		//---	
		
		//var d = new Date();
		//document.getElementById("log").innerHTML+="mouse over. current: " + current + ". element: " + a + ". ms: " + d.getMilliseconds() + "<br>"; 
		clearInterval(wait); 
		wait = setInterval(
			function() 
			{				
				if(state=="up" && moving=="" && current!=a)
			 	{
					//document.getElementById("log").innerHTML+="mouse over. state up. element: " + a + "<br>"; 
					txt1(a);
			     	clearInterval(wait); 
					//easeOutBounce
		   		 	$(ce).stop().animate({marginTop: '196px'},{queue:false, duration:400, easing: 'swing', 
										 step: function(){ moving="down"; current=a; }, 
										 complete: function(){ moving=""; state="down"; }}
										); 
		 	 	}
				if(current==a)
				{
				  clearInterval(wait); 
				  clearInterval(wait2); 
				  current=-1;
				}
			}
		, 1);
        //---
	});
	
			if(document.getElementById("rodovnik")!=null)
		{
	//When mouse rolls over
	$(document.getElementById("rodovnikgumb")).click(function(){
		var a=$(this).parent().find('li').index(this);
		//---	
		
		//var d = new Date();
		//document.getElementById("log").innerHTML+="mouse over. current: " + current + ". element: " + a + ". ms: " + d.getMilliseconds() + "<br>"; 
		
		clearInterval(wait); 
		wait = setInterval(
			function() 
			{				
				//if(state=="up" && moving=="")
			 	{
					//document.getElementById("log").innerHTML+="mouse over. state up. element: " + a + "<br>"; 
					txt1(7);
			     	clearInterval(wait); 
					//easeOutBounce
		   		 	$(document.getElementById("submenu1")).stop().animate({marginTop: '-235px'},{queue:false, duration:2500, easing: 'easeOutBounce', 
										 step: function(){ moving="down"; current=a; }, 
										 complete: function(){ moving=""; state="down"; }}
										); 
		 	 	}
				if(current==a)
				{
				  clearInterval(wait); 
				  clearInterval(wait2); 
				  current=-1;
				}
			}
		, 1);
        //---
	});	
	
	//When mouse rolls over
	$(document.getElementById("rodovnikgumb")).mouseout(function(){
		    var a=$(this).parent().find('li').index(this);							  
			//---
			
 		    //var d = new Date();			
			//document.getElementById("log").innerHTML+="mouse out. current: " + current + ". element: " + a + ". ms: " + d.getMilliseconds() + "<br>"; 
			
			clearInterval(wait2);
			//clearInterval(wait);
			wait2 = setInterval(
			function() 
			{
					//if((state=="down" && moving=="" && current==a) || (current!=a && state=="down"))
					 {
						 //document.getElementById("log").innerHTML+="mouse out. state down. element: " + a + "<br><br>"; 
			  		     clearInterval(wait2); 
		   				 $(document.getElementById("submenu1")).stop().animate({marginTop: '-630px'},{queue:false, duration:400, easing: 'swing', 
											  step: function(){ moving="up"; current=a; }, 
											  complete: function(){ moving=""; state="up"; current=-1; }}
											 ); 						 
					 } 
					 //document.getElementById("log").innerHTML+="state: " + state + "moving: " + moving + "<br><br>"; 
			}
			, 1);	
			//---
	});		
		
	//When mouse is removed
	$(document.getElementById("submenu1")).mouseout(function(){
		    var a=$(this).parent().find('li').index(this);							  
			//---
			
 		    //var d = new Date();			
			//document.getElementById("log").innerHTML+="mouse out. current: " + current + ". element: " + a + ". ms: " + d.getMilliseconds() + "<br>"; 
			
			clearInterval(wait2);
			//clearInterval(wait);
			wait2 = setInterval(
			function() 
			{
					//if((state=="down" && moving=="" && current==a) || (current!=a && state=="down"))
					 {
						 //document.getElementById("log").innerHTML+="mouse out. state down. element: " + a + "<br><br>"; 
			  		     clearInterval(wait2); 
		   				 $(document.getElementById("submenu1")).stop().animate({marginTop: '-630px'},{queue:false, duration:400, easing: 'swing', 
											  step: function(){ moving="up"; current=a; }, 
											  complete: function(){ moving=""; state="up"; current=-1; }}
											 ); 						 
					 } 
					 //document.getElementById("log").innerHTML+="state: " + state + "moving: " + moving + "<br><br>"; 
			}
			, 1);	
			//---
	});		
	}
		
	//When mouse is removed
	$("#mmm li").mouseout(function(){
		    var a=$(this).parent().find('li').index(this);							  
			//---
			
 		    //var d = new Date();			
			//document.getElementById("log").innerHTML+="mouse out. current: " + current + ". element: " + a + ". ms: " + d.getMilliseconds() + "<br>"; 
			
			clearInterval(wait2);
			clearInterval(wait);
			wait2 = setInterval(
			function() 
			{
					if((state=="down" && moving=="" && current==a) || (current!=a && state=="down"))
					 {
						 //document.getElementById("log").innerHTML+="mouse out. state down. element: " + a + "<br><br>"; 
			  		     clearInterval(wait2); 
		   				 $(ce).stop().animate({marginTop: '156px'},{queue:false, duration:200, easing: 'swing', 
											  step: function(){ moving="up"; current=a; }, 
											  complete: function(){ moving=""; state="up"; current=-1; }}
											 ); 						 
					 } 
					 //document.getElementById("log").innerHTML+="state: " + state + "moving: " + moving + "<br><br>"; 
			}
			, 1);	
			//---
	});
	
	//When mouse is removed
	$(document.getElementById("submenu")).mouseout(function(){
		    var a=$(this).parent().find('li').index(this);							  
			//---
			
			//document.getElementById("log").innerHTML+="mouse out. current: " + current + ". element: " + a + "<br>"; 
			
			clearInterval(wait2); 
			wait2 = setInterval(
			function() 
			{
					if((state=="down" && moving=="" && current==a) || (current!=a && state=="down"))
					 {
						 //document.getElementById("log").innerHTML+="mouse out. state down. iz dropdown. element: " + a + "<br><br>"; 
			  		     clearInterval(wait2); 
		   				 $(ce).stop().animate({marginTop: '156px'},{queue:false, duration:200, easing: 'swing', 
											  step: function(){ moving="up"; current=a; }, 
											  complete: function(){ moving=""; state="up"; current=-1; }}
											 ); 						 
					 } 
					 //document.getElementById("log").innerHTML+="state: " + state + "moving: " + moving + "<br><br>"; 
			}
			, 1);	
			//---
	});	
	
	//When mouse is removed
	$(document.getElementById("blue")).mouseout(function(){
		    var a=$(this).parent().find('li').index(this);							  
			//---
			
			//document.getElementById("log").innerHTML+="mouse out. current: " + current + ". element: " + a + "<br>"; 
			
			clearInterval(wait2); 
			wait2 = setInterval(
			function() 
			{
					if((state=="down" && moving=="" && current==a) || (current!=a && state=="down"))
					 {
						 //document.getElementById("log").innerHTML+="mouse out. state down. iz dropdown. element: " + a + "<br><br>"; 
			  		     clearInterval(wait2); 
		   				 $(ce).stop().animate({marginTop: '156px'},{queue:false, duration:200, easing: 'swing', 
											  step: function(){ moving="up"; current=a; }, 
											  complete: function(){ moving=""; state="up"; current=-1; }}
											 ); 						 
					 } 
					 //document.getElementById("log").innerHTML+="state: " + state + "moving: " + moving + "<br><br>"; 
			}
			, 1);	
			//---
	});		
	
	//When mouse is removed
	$(document.getElementById("outerDiv")).mouseover(function(){
		    var a=$(this).parent().find('li').index(this);							  
			//---
			
			//document.getElementById("log").innerHTML+="mouse out. current: " + current + ". element: " + a + "<br>"; 
			
			clearInterval(wait2); 
			wait2 = setInterval(
			function() 
			{
					if((state=="down" && moving=="" && current==a) || (current!=a && state=="down"))
					 {
						 //document.getElementById("log").innerHTML+="MOVE UP.<br><br>"; 
			  		     clearInterval(wait2); 
		   				 $(ce).stop().animate({marginTop: '156px'},{queue:false, duration:200, easing: 'swing', 
											  step: function(){ moving="up"; current=a; }, 
											  complete: function(){ moving=""; state="up"; current=-1; }}
											 ); 						 
					 } 
					 if(moving=="")
					 {
						clearInterval(wait2);  
					 }
					 //document.getElementById("log").innerHTML+="state: " + state + "moving: " + moving + "<br><br>"; 
			}
			, 1);	
			//---
	});		
	
});
