// javascript by posttoast, 2008 (http://www.posttoast.nl)
// Some modifications in 2010

var slideShow = new Class({

  Implements: [Options, Events],
  options: {
    container: "",
    slideElement: "",
    duration: 3000 // Time between slide in ms
  },
 
  initialize: function(options){
    this.setOptions(options);
    this.slideImg = $(this.options.container).getElements(this.options.slideElement); 
    this.numImg = this.slideImg.length;
    if (this.numImg > 1){
      this.slideImg.setStyle('display', 'none');
      this.current = 0;
      this.start();
    }
  },
 
  initSlideshow: function(){
      this.slideImg[this.current].setStyle('display', 'block');
      this.slideImg[this.current].setStyle('opacity', '0');
      this.slideImg[this.current].fade('in');

    this.slideImg.each(function(el, j){
      if (j != this.current) {
        el.setStyle('display', 'none');
      }
    }.bind(this));
    this.previous = this.current;
    this.current ++;
    if (this.current == this.numImg) this.current = 0;

    this.cycleForward = this.initSlideshow.delay(this.options.duration, this);
  },

  stopSliding: function(){
    $clear(this.cycleForward);
  },

  start: function(){
    this.initSlideshow();
  }

});
