slideshow_disolve = new Class({
  Implements: Options,
  options: {
    container: $$('.slideshow')[0],
    speed: 500,
    delay: 2500
  },
  
  initialize: function(options){
    this.setOptions(options);
    
    if (!this.options.container) {
      return;
    }
    
    this.options.images = this.options.container.getElements('.image');
    
    if (this.options.images.length < 2) {
      return;
    }
    
    this.current = 0;
    this.prepare();
    this.play.delay(this.options.delay, this);
  },
  
  prepare: function() {
    this.options.images.setStyle('opacity', 0);
    this.options.images[0].setStyle('opacity', 1);
  },
  
  play: function() {
    if (this.current < this.options.images.length-1) {
      this.show(this.options.images[this.current+1]);
      this.hide(this.options.images[this.current]);
      this.current++;
    }
    else {
      this.show(this.options.images[0]);
      this.hide(this.options.images[this.current]);
      this.current = 0;
    }
    this.play.delay(this.options.delay+this.options.speed, this);
  },
  
  show: function(el) {
    new Fx.Morph(el, {
      duration: this.options.speed,
      transition: Fx.Transitions.Sine.easeOut
    }).start({
      'opacity': [0, 1]
    });
  },
  
  hide: function(el) {
    new Fx.Morph(el, {
      duration: this.options.speed,
      transition: Fx.Transitions.Sine.easeOut
    }).start({
      'opacity': [1, 0]
    });
  }
});

window.addEvent('load', function(){
  new slideshow_disolve({
    container: $$('.slideshow')[0],
    speed: 1500,
    delay: 3000
  });
});
