/**
 * @author nunziofiore
 */

columnRotator = new Class({

    initialize: function(dateString){

        this.position = 0;	
	var foto = new Array();
	var descrizione = new Array();
	var link = new Array();
                //recupero json da href
                var req = new Request.JSON({
                        url: '/data/immagini.php', // l'url da contattare
                        async: true,
                        onComplete: function(json) {
                                for(var i=0;i<json.items.length;i++)
                                {
					//alert("ciaoi");
                                        foto[i] = json.items[i].url;
                                        descrizione[i] = json.items[i].descrizione;
					link[i] = json.items[i].link;
                                }
                }
                        });
                req.get();
	this.foto = foto;
	this.descrizione = descrizione;
	this.link = link;
        this.startTimer();

    },

    updateCount: function(){
	var des = this.descrizione;
	var fot = this.foto;
	var lin = this.link;
        if (this.position == this.foto.length) {
                this.position = 0;
        } else {
                this.position++;
        }
        var pos = this.position;
        var sx = $('npcontainer');

        if (des[pos] != null) {
        	var fsx = new Fx.Tween(sx,{
        	duration: 1500,
        	onComplete: function(){
			if (des[pos] != null) {
				document.getElementById('comitatoslider').innerHTML = "<a href=\"" + lin[pos] + "\" class=\"acomitatohomepage\">" + des[pos] + "</a>";
				Cufon.replace('h3');
				document.getElementById('npcontainer').style.background='url(' + fot[pos] + ')';
		                sx.fade('in');
			}
        	}
    		});
   	 	fsx.start('opacity',1,0);
	}

    },

    stopTimer: function(){

        $clear(this.periodicalTimer);

    },

    startTimer: function(){

        this.periodicalTimer = this.updateCount.periodical(10000, this);

    }

});

window.addEvent('domready', function(){
        var colonna  = new columnRotator('');
});

