$(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");
			};
		});
	}
	
	
	
});