var Slideshow = new Class({
  
  Extends: MorphList,
  
  options: {/*
    onShow: $empty,*/
    auto: false,
    autostart: false,
    autointerval: 8000,
    transition: 'fade',
    tween: { duration: 1000 }
  },
  
  initialize: function(menu, images, loader, options) {
    this.parent(menu, options);
    this.images = $(images);
    this.imagesitems = this.images.getChildren().fade('hide');
    if(this.current) this.show(this.menuitems.indexOf(this.current));
    else if(this.options.auto && this.options.autostart) this.progress();
  },
  
  auto: function(){
    if(! this.options.auto) return false;
    $clear(this.autotimer);
    this.autotimer = this.progress.delay(this.options.autointerval, this);
  },
  			
  click: function(ev, item) {
    this.parent(ev, item);
    new Event(ev).stop();
    this.show(this.menuitems.indexOf(item));
    $clear(this.autotimer);
    this.auto();
  },
  
  show: function(index) {
    //if(! this.loaded) return;
    var image = this.imagesitems[index];
		if(image == this.curimage) return;
    image.set('tween', this.options.tween).dispose().inject(this.curimage || this.images.getFirst(), this.curimage ? 'after' : 'before').fade('hide');
		image.setStyle('display', 'block');
		imageFade = new Fx.Tween ( image, {
			property: 'opacity',
			duration: 800,
			transition: Fx.Transitions.Expo.easeInOut
		});
		var slide = new Fx.Slide( image.getElementById('panetextbackground_' + index), { duration: 800, transition: Fx.Transitions.Expo.easeInOut }) ;
		slide.hide( 'horizontal' );
		imageFade.start(0, 1).addEvent( 'onComplete', function() {
			slide.slideIn( 'horizontal' );
			
		});
		this.auto();
    this.fireEvent('show', image);
    this.curimage = image;
    this.setCurrent(this.menuitems[index])
    this.morphTo(this.menuitems[index]);
		return this;
  },
  
  progress: function(){
    var curindex = this.imagesitems.indexOf(this.curimage);
    this.show((this.curimage && (curindex + 1 < this.imagesitems.length)) ? curindex + 1 : 0);
  }
});

