$(document).ready(function()
{	
	var interval = setInterval(rotate_menu,4000);
	var cphoto = 0;
	
	$('#home_movie').attr('style','background-image: url(' + photos[cphoto] + ');');
	
	
	$.fn.slideIn = function() { 
	
		$(this).fadeIn(300,function()
		{
	    	$(this).addClass('home_news_item_active'); 
		});
	}
	
	$.fn.slideOut = function(fnc) { 
	
    	$(this).fadeOut(300,function()
		{
			$(this).removeClass('home_news_item_active'); 
			fnc();
		});
	}
	
	function rotate_menu()
	{
		if(cphoto==5)
			cphoto=0;
		else
			cphoto++;
		
		$('#home_movie').fadeOut(300,function()
		{
			$('#home_movie').attr('style','background-image: url(' + photos[cphoto] + '); display: none;');
			$('#home_movie').fadeIn(300);
		});
		
		var current = parseInt($('.home_news_item_active').attr('id').replace('home_news_item_',''));
		var next = current+1;
		
		if(current==$('.home_news_item').size())
		{
			$('#home_news_item_'+ current).slideOut
			(
				function()
				{
					$('#home_news_item_1').slideIn();					
				}
			);		
			$('#home_news_previous').addClass('disabled');
			$('#home_news_next').removeClass('disabled');
		}
		else
		{
			$('#home_news_next').trigger('click');
		}
	}
	
	$('#home_news').hover(
		function(event)
		{
			clearInterval(interval);
		},
		function(event)
		{	
			interval = setInterval(rotate_menu,5000);
		}
	);	
		
	$("#home_news_previous").click(function(event)
	{
		if($(this).hasClass('disabled'))
			return false;
		
		var current = $('.home_news_item_active').attr('id').replace('home_news_item_','');
		var prev = parseInt(current)-1;
		
		if(prev>1)
			$('#home_news_next').removeClass('disabled');
		
		if(prev==1)
			$('#home_news_previous').addClass('disabled');
		
		$('#home_news_item_'+ current).slideOut
		(
			function()
			{
				$('#home_news_item_'+ prev).slideIn();					
			}
		);	
		
		event.preventDefault();
	});
	
	$("#home_news_next").click(function(event)
	{
		if($(this).hasClass('disabled'))
			return false;
		
		var current = $('.home_news_item_active').attr('id').replace('home_news_item_','');
		var next = parseInt(current) +1;
		
		if(next>1)
			$('#home_news_previous').removeClass('disabled');
		
		if(next==$('.home_news_item').size())
			$('#home_news_next').addClass('disabled');
		
		$('#home_news_item_'+ current).slideOut
		(
			function ()
			{
				$('#home_news_item_'+ next).slideIn();	
			}
		);
		
		event.preventDefault();
	});
	
	/*$('#home_movie').click(function(event)
	{
		alert('start plu film in lightbox');
		event.preventDefault();
	});*/
});
