var ProdottiVeloci = {
	init: function(){
		var prodotti = $$('#prodottiveloci dd a');
		var fx = new Fx.Elements(prodotti, {wait: false, duration: 200, transition: Fx.Transitions.quadOut});
		prodotti.each(function(prodotto, i){
			prodotto.addEvent('mouseover', function(e){
				e = new Event(e).stop();
				var obj = {};
				obj[i] = { 'width': [prodotto.getStyle('width').toInt(), 163] };
				prodotti.each(function(other, j){
					if (other != prodotto){
						var w = other.getStyle('width').toInt();
						if (w != 93) obj[j] = {'width': [w, 93]};
					}
				});
				fx.start(obj);
			});
		});
		
		document.addEvent('mouseover', function(e){
			e = new Event(e);
			var obj = {};
			prodotti.each(function(other, j){
				obj[j] = {'width': [other.getStyle('width').toInt(), 103]};
			});
			fx.start(obj);
		});
	}
};


var Rotazione = {
  init: function(){
    this.images = new Image();
    this.imagecount = 14;
    this.actualimage = 1;
    
    // preload
    for (i = 1; i <= this.imagecount; i++) {
      this.images.src = "images/home/rotazione-"+i+".jpg";
      if (i = this.imagecount) this.timer = setInterval("Rotazione.next()", 5000);
    }
  },


  next: function(){
    if (this.actualimage == this.imagecount) { this.actualimage = 1; }
    else { this.actualimage++; }
    
    // definisce le variabili delle immagini e definisce le classi
    if ($$('#rotazione img')[0].className == "") {
      $$('#rotazione img')[0].className = 'original';
      new Element('img').injectInside('rotazione').className = 'support';
    }
    this.image1 = $$('#rotazione img.original')[0];
    this.image2 = $$('#rotazione img.support')[0];
    
    // aggiorna l'immagine
    var Image1Fx = new Fx.Style(this.image1, 'opacity', {
      duration: 500,
      transition: Fx.Transitions.cubicIn
    });
    var Image2Fx = new Fx.Style(this.image2, 'opacity', {
      duration: 500,
      transition: Fx.Transitions.cubicOut
    });
    var CrossDissolve = new Chain();
    CrossDissolve.chain(function(){
      Image2Fx.set(0)
      Rotazione.image2.src = "images/home/rotazione-"+Rotazione.actualimage+".jpg";
      this.callChain();
    }).chain(function(){
      Image1Fx.start(1,0);
      Image2Fx.start(0,1).chain(function(){ CrossDissolve.callChain() });
    }).chain(function(){
      Rotazione.image1.src = "images/home/rotazione-"+Rotazione.actualimage+".jpg";
      Image1Fx.set(1);      
      Image2Fx.set(0);
      this.callChain();
    }).callChain();
  },


  stop: function(){
    clearInterval(this.timer);
  }
}
