/*$(document).ready(function() {
	var durata_animazione = 1500;					   
	var intervallo = durata_animazione + 5000; //secondi in cui la news resta ferma
	var run = true;
	var interval_id = setInterval(muovi, intervallo);
	
	$('#news-viewport').mouseover(function(){
		//fermo l'animazione							   
		run = false;								   
	}).mouseleave(function(){
		run = true;
	});

	function muovi(){
		if (run == true){
			$('.homepage-news').each(function(i){
			var current_position = $(this).css('top');
			var current_position_value = current_position.substr(0, current_position.length-2);
			var next_position = current_position_value - 95;
			var top_value = next_position + "px";
			$(this).animate({
							top: top_value
							},
							durata_animazione,
							'',
							controlla_posizione);
			
			});
		}
	}
	function controlla_posizione(){
		$('.homepage-news').each(function(i){
			if( $(this).css('top') <= "-95px"){
				$(this).css('top', "285px");
			};
		});
	}
	
	
	
});*/
// JavaScript Document
$(document).ready(
	function(){
		
		var viewport = $('#news-viewport');
		var news = viewport.children();
		var intervallo = 5000;
		var durata_animazione = 1000;
		var start = 0;
		var hover_var = false;
		
		news.css('display','none');
		
		$(news[start]).fadeIn(durata_animazione);
		if(news.length>1){
			setInterval(
				function(){
					if(!hover_var){
						old = start;
						start++;
						start = start == news.length ? 0 : start;
						$(news[old]).fadeOut(
							durata_animazione,
							function(){
								$(news[start]).fadeIn(durata_animazione);
							}
						);
					}
				},
			intervallo
		);
		}
		viewport.hover(
			   function(){
				   hover_var = true;
			   },
			   function(){
				   hover_var = false;
			   }
		);
	}
);