/**
 * @author Marco Valori
 */


var pause = 0;

$(function() {		
	$('.articolo').each( function () {
		$('a.lightbox_da_mostrare', this).show().lightBox();
	});
	
	var refreshId = setInterval(function() {
		$.ajax({
		  type: "GET",
		  url: "keep_alive.php"
		});
	}, 60000);
	
	init();
	scrivi_ora();
	
	$('#scroll').hover(function() {
		pause = 1;
	}, function() {
		pause = 0;
	});
	
});

function scorri(){
   copyspeed = 1
	scrollerheight = 0
	if (pause == 1) copyspeed = 0
	scroller = document.getElementById("scroll");
	actualheight=scroller.offsetHeight
	if (parseInt(scroller.style.top)>(actualheight*(-1)-40)){
		scroller.style.top=parseInt(scroller.style.top)-copyspeed+"px";
		setTimeout("scorri()", 100);
		return;
	} else {
		setTimeout("scorri()", 100);
		scroller.style.top=parseInt(scrollerheight)+30+"px";
		return;
	}
}
//-------------------

function init(){
	div_scorrimento = $('#scroll');
	if (div_scorrimento != undefined) {
   		scorri();
	}
}

function scrivi_ora(){
	today=new Date();
	var myDays=["Dom","Lun","Mar","Mer","Gio","Ven","Sab","Dom"];
	var myMonths=["Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre"];
	thisDay=today.getDay();
	thisDay=myDays[thisDay];
	thisMonth=myMonths[today.getMonth()];
	if (today.getMinutes() < 10) testoMin = '0'; 
	else testoMin = '';
	if (today.getSeconds() % 2 == 0) testoBlink = '.';
	else testoBlink = ' ';
	$('#ora').html(thisDay + ' ' + today.getDate() + ' ' + thisMonth + ' ' + today.getFullYear() + ' - ' + today.getHours() + testoBlink + testoMin + today.getMinutes());
	setTimeout("scrivi_ora()", 1000);
}
