var SimpleSlideshow = new Class({
  options: {
    showControls: true,
    showDuration: 6000,
    showTOC: true,
    tocWidth: 20,
    tocClass: 'toc',
    tocActiveClass: 'toc-active'
  },
  Implements: [Options,Events],
  initialize: function(container,control_container,elements,index,options) {
    //settings
    this.container = $(container);
	this.control_container = $(control_container);
    this.elements = $$(elements);
    this.currentIndex = 0;
    this.interval = '';
    if(this.options.showTOC) this.toc = [];

    //assign
    this.elements.each(function(el,i){
      if(this.options.showTOC) {
        this.toc.push(new Element('a',{
          href: '#',
          'class': this.options.tocClass + '' + (i == 0 ? ' ' + this.options.tocActiveClass : ''),
          events: {
            click: function(e) {
              if(e) e.stop();
              this.stop();
              this.show_goto(i);
            }.bind(this)
          }
        }).inject(this.control_container));
      }
      if(i > 0) el.set('opacity',0);
    },this);

  },
  show: function() {
    this.elements[this.currentIndex].fade('out');
    if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
	this.elements[this.currentIndex = (this.currentIndex < this.elements.length - 1 ? this.currentIndex+1 : 0)].fade('in');
    if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
    var background = this.elements[this.currentIndex].getElement('.slideshow_background_image').value;
    this.elements[this.currentIndex].setStyle('background-image', 'url('+background+')');

  },
  start: function() {
    this.interval = this.show.bind(this).periodical(this.options.showDuration);
  },
  stop: function() {
    $clear(this.interval);
  },
  reset: function() {
    this.elements[this.currentIndex].fade('out');
    if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
	this.elements[this.currentIndex = 0].fade('in');
    if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
  },
  show_goto: function(newIndex) {
	this.show();
    this.elements[this.currentIndex].fade('out');
    if(this.options.showTOC) this.toc[this.currentIndex].removeClass(this.options.tocActiveClass);
	this.elements[this.currentIndex = newIndex].fade('in');
    if(this.options.showTOC) this.toc[this.currentIndex].addClass(this.options.tocActiveClass);
  }
});
