var RoundedSlideshow = Class.create({
  initialize: function(element){
    this.slideshow_timeout = [];
    this.current = 0;           // current tab
    this.timeout = 6;           // seconds for tabswitch

    this.rounded_slideshow = $(element);
    this.slides = this.rounded_slideshow.select('.slideshow_block');
    this.slide_positions = this.slides.collect(function(slide, x){ 
        slide.index_x = x;
        return x * 422;
    });
    
    this.container_block = this.rounded_slideshow.select('.slideshow_blocks').first();
    this.container_block.setStyle("width: " + this.slide_positions.length * 422 + "px;");

    this.start_auto_timeout();
  },

  open: function(slide){

		new Effect.Morph(this.container_block, { 
      style: 'left: ' + (0 - this.slide_positions[slide.index_x]) + 'px;' 
    })
  },

 	next: function(){
		this.current = (this.current + 1) % this.slides.length;
		this.open(this.slides[this.current]);
	},
	
	start_auto_timeout: function(){
		this.slideshow_timeout.push(setInterval(function(){
			this.next();
		}.bind(this), this.timeout * 1000));
	}
});

	
document.observe("dom:loaded", function(){
  $$('.rounded_slideshow').each(function(element){ new RoundedSlideshow(element); })
});
