window.addEvent('domready', function(){
	$$('.news-bottom a').each(function(link) {
		link.addEvent('click', function(e) {
			e.stop();
			var pagina = this.getProperty('href').split('=');
			
			var req = new Request.HTML({
				url: '../news-ajax.php?pagina='+pagina[1],
				onRequest: function() {
					var lista = $('lista-news');
					lista.addClass('loading');
					lista.getChildren().addClass('hidden');
				},
				onSuccess: function(html) {
					$$('.paginazione-attivo').removeClass('paginazione-attivo');
					link.addClass('paginazione-attivo');
					var lista = $('lista-news');
					lista.removeClass('loading');
					lista.getChildren().destroy();
					lista.adopt(html);
				},
				onFailure: function() {
					ultimoElemento.set('text', 'Richiesta fallita.');
				}
			}).send();
		});
	});
	
	if($('img-centrale') && $('lista-img'))
	{
		var imgCentrale = $('img-centrale');
		$$('#lista-img img').each(function(img) {
			img.addEvent('click', function(e) {
				e.stop();
				imgCentrale.setProperty('src','../images/vuoto.gif');
				
				var array = img.getProperty('src').split('/');
				var nuovoPath = array[0]+'/'+array[1]+'/'+array[2]+'/'+array[3]+'/'+array[5];
				//console.log(nuovoPath);
				
				var myImage = new Asset.image(nuovoPath, {
					onload: function() {
						imgCentrale.setProperty('src', nuovoPath);
					}
				});
			});
		});
	}
	
	if($('frase')) 
	{
		var lista = $('frase').getFirst();
		var myFx = new Fx.Tween(lista, {
			duration: 400,
			transition: Fx.Transitions.Quad.easeOut
		});
		
		var increment = 224;
		var valoreIncremento = lista.getChildren().length;
		var totIncrement = 0;
		var maxRightIncrement = increment*(-valoreIncremento);
		
		var scorri = function(){ 
			totIncrement = totIncrement - increment;
			if(totIncrement == maxRightIncrement)
				totIncrement = 0;
				
			myFx.pause();
			myFx.start('margin-left', totIncrement);
		};
	
		scorri.periodical(7000);
	}
});