jQuery(document).ready(function()
{
	var activecolor, activebutton, activenr;
	if ($('.item1 p a').hasClass('button1 active'))
	{	activecolor = '#1dbee2';
		activebutton = '.button1';
		activenr = 0;
		$('.item1 p a').css({'color': '#FFF'});}
	else if ($('.item2 p a').hasClass('button2 active'))
	{	activecolor = '#0E6CB4';
		activebutton = '.button2';
		activenr = 1;
		$('.item2 p a').css({'color': '#FFF'});}
	else if ($('.item3 p a').hasClass('button3 active'))
	{	activecolor = '#AACC41';
		activebutton = '.button3';
		activenr = 2;
		$('.item3 p a').css({'color': '#FFF'});}
	else if ($('.item4 p a').hasClass('button4 active'))
	{	activecolor = '#E63A9E';
		activebutton = '.button4';
		activenr = 3;
		$('.item4 p a').css({'color': '#FFF'});}
	else if ($('.item5 p a').hasClass('button5 active'))
	{	activecolor = '#F67D21';
		activebutton = '.button5';
		activenr = 4;
		$('.item5 p a').css({'color': '#FFF'});}
	
	$('#menu_hoverblok').corner("round 5px");
	var c = $(activebutton);
	$('#menu_hoverblok').css({'width': textWidth(activebutton), 'height': (c.innerHeight() + 14), 
							'left': (positionLeft(activebutton, activenr)), 'top': (positionTop(activebutton) + 3 - 7), 'background-color': activecolor});

	$('.button1').mouseenter(function (){MouseEnter(1);}).mouseleave(function (){MouseLeave(1);});
	$('.button2').mouseenter(function (){MouseEnter(2);}).mouseleave(function (){MouseLeave(2);});
	$('.button3').mouseenter(function (){MouseEnter(3);}).mouseleave(function (){MouseLeave(3);});
	$('.button4').mouseenter(function (){MouseEnter(4);}).mouseleave(function (){MouseLeave(4);});
	$('.button5').mouseenter(function (){MouseEnter(5);}).mouseleave(function (){MouseLeave(5);});
	
	function MouseEnter(nr)
	{
		var speed = 250;
		var prevbutton, prevcolor;
		if (nr == 1)
		{	
			$('#menu_hoverblok').animate({'left': (positionLeft('.button1', 0)),'background-color': '#1dbee2', 'width': textWidth('.button1')}, speed);
			$('.button1').animate({'color': '#FFF'}, speed);
			$('.button2').animate({'color': '#0E6CB4'}, speed);
			$('.button3').animate({'color': '#AACC41'}, speed);
			$('.button4').animate({'color': '#E63A9E'}, speed);
			$('.button5').animate({'color': '#F67D21'}, speed);
			window.clearTimeout(Delay);
		}
		else if (nr == 2)
		{	
			$('#menu_hoverblok').animate({'left': (positionLeft('.button2', 1)),'background-color': '#0E6CB4', 'width': textWidth('.button2')}, speed);
			$('.button1').animate({'color': '#1dbee2'}, speed);
			$('.button2').animate({'color': '#FFF'}, speed);
			$('.button3').animate({'color': '#AACC41'}, speed);
			$('.button4').animate({'color': '#E63A9E'}, speed);
			$('.button5').animate({'color': '#F67D21'}, speed);	
			window.clearTimeout(Delay);	
		}
		else if (nr == 3)
		{	
			$('#menu_hoverblok').animate({'left': (positionLeft('.button3', 2)),'background-color': '#AACC41', 'width': textWidth('.button3')}, speed);
			$('.button1').animate({'color': '#1dbee2'}, speed);
			$('.button2').animate({'color': '#0E6CB4'}, speed);
			$('.button3').animate({'color': '#FFF'}, speed);
			$('.button4').animate({'color': '#E63A9E'}, speed);
			$('.button5').animate({'color': '#F67D21'}, speed);
			window.clearTimeout(Delay);
		}
		else if (nr == 4)
		{	
			$('#menu_hoverblok').animate({'left': (positionLeft('.button4', 3)),'background-color': '#E63A9E', 'width': textWidth('.button4')}, speed);
			$('.button1').animate({'color': '#1dbee2'}, speed);
			$('.button2').animate({'color': '#0E6CB4'}, speed);
			$('.button3').animate({'color': '#AACC41'}, speed);
			$('.button4').animate({'color': '#FFF'}, speed);
			$('.button5').animate({'color': '#F67D21'}, speed);
			window.clearTimeout(Delay);
		}
		else if (nr == 5)
		{	
			$('#menu_hoverblok').animate({'left': (positionLeft('.button5', 4)),'background-color': '#F67D21', 'width': textWidth('.button5')}, speed);
			$('.button1').animate({'color': '#1dbee2'}, speed);
			$('.button2').animate({'color': '#0E6CB4'}, speed);
			$('.button3').animate({'color': '#AACC41'}, speed);
			$('.button4').animate({'color': '#E63A9E'}, speed);
			$('.button5').animate({'color': '#FFF'}, speed);
			window.clearTimeout(Delay);
		}
	}
	
	function MouseLeave(nr)
	{
		var speed = 250;
		
		Delay = window.setTimeout(function() {
		$('#menu_hoverblok').animate({'left': (positionLeft(activebutton, activenr)),'background-color': activecolor, 'width': textWidth(activebutton)}, speed);
		$(activebutton).animate({'color': '#FFF'}, speed);
		
		if (nr == 1 && activebutton != '.button1')
			$('.button1').animate({'color': '#1dbee2'}, speed);
		else if (nr == 2 && activebutton != '.button2')
			$('.button2').animate({'color': '#0E6CB4'}, speed);
		else if (nr == 3 && activebutton != '.button3')
			$('.button3').animate({'color': '#AACC41'}, speed);
		else if (nr == 4 && activebutton != '.button4')
			$('.button4').animate({'color': '#E63A9E'}, speed);
		else if (nr == 5 && activebutton != '.button5')
			$('.button5').animate({'color': '#F67D21'}, speed);
			
		}, 1500);
	}
	
	function textWidth(button) {return $(button).innerWidth() + 23;}
	function positionLeft(button, buttonNr) {return $(button).position().left + ((buttonNr * 192) - 11);}
	function positionTop(button) {return $(button).position().top;}
});
