var Protopuff = Class.create({

	initialize: function(element, options) {		
		this.options = {
      		duration: 1,
			delay: 4.0
    	}
		Object.extend(this.options, options || {});

    	this.element        = $(element);
		this.slides			= this.element.childElements();
		this.num_slides		= this.slides.length;		
		this.current_slide 	= this.num_slides - 1;
		this.end_slide		= 0;
		
		this.startSlideshow();
	},
	
	
	startSlideshow: function(event) {
		if(event) { Event.stop(event); }
		if(!this.running) {
			this.executer = new PeriodicalExecuter(function(){
	  			this.updateSlide(this.current_slide);
	 		}.bind(this), this.options.delay);
			
			this.running = true;
		}
	},
	
	updateSlide: function(current_slide) {
		if(current_slide == this.end_slide) {
			next_slide = this.num_slides - 1;
		} else {
			next_slide = current_slide - 1; 
		}
		
		this.puff(next_slide, current_slide);		
	},
	
 	puff: function (next, current) {
		var currentSlideEl = this.slides[current];
		
		new Effect.Puff(this.slides[current], { 
			duration: this.options.duration,
			object: this,
			afterFinish: function() {
				currentSlideEl.remove();
				
				this.object.element.insert({
					top: currentSlideEl
				});
				
				currentSlideEl.show();
			}
		});
		
		this.current_slide = next;		
	}
});