Rotazione = {
  init: function() {
    this.imagelist = $$('#rotazione ul li img');
    this.imagecount = this.imagelist.length;
    this.lastimage = this.imagecount-1;
    this.actualimage = 0;
    this.nextimage = this.actualimage+1;
    
    // Nasconde tutte le immagini a parte la prima
    for (i=1; i <= this.lastimage; i++) {
      this.imagelist[i].setStyle('opacity', '0');
    }
    
    this.timer = setInterval("Rotazione.next()", 5000);
  },
  
  next: function() {
    var Image1Fx = new Fx.Style(this.imagelist[this.actualimage], 'opacity', { duration: 2000 });
    var Image2Fx = new Fx.Style(this.imagelist[this.nextimage], 'opacity', { duration: 2000 });

    var CrossDissolve = new Chain();
    CrossDissolve.chain(function() {
      Image2Fx.set(0);
      this.callChain();
    }).chain(function() {
      Image1Fx.start(1,0);
      Image2Fx.start(0,1);
    }).callChain();
    
    // Aggiorna i numeri delle immagini
    this.actualimage = this.actualimage == this.lastimage ? 0 : this.actualimage+1;
    this.nextimage = this.nextimage == this.lastimage ? 0 : this.nextimage+1;
  }
}

window.onDomReady(function() { Rotazione.init() });