var Diaporama =  new Class({
  images : [],
  current_image_idx : 0,
  timer: null,

  initialize: function() {
    $('slide_gallery').getElements('div.img_container').each(function(item){
      this.images.push(item);
    }.bind(this));
    this.start(false);
  },

  switchImage: function() {
    new Fx.Tween(this.images[this.current_image_idx], { property: 'opacity', duration: 1200, fps: 15 }).start(1.0, 0.0); // fade
    this.current_image_idx++;
    if (this.current_image_idx >= this.images.length ) this.current_image_idx = 0;
    new Fx.Tween(this.images[this.current_image_idx], { property: 'opacity', duration: 1200, fps: 15 }).start(0.0, 1.0); //appear
  },

  stop: function() {
    if (!this.timer) return false;
    this.timer = $clear(this.timer);
    return true;
  },

  start: function(force) {
    if (this.timer) return false;
    if (force) { this.switchImage(); }
    this.timer = this.switchImage.periodical(3500, this);
    return true;
  }
});

