var ProgressPushbox = new Class({
	
	Implements: Options,
	
	// init
	options: {
		'container': {},
		'duration': 3
	},
	
	initialize: function(options) {
		
		// set options
		this.setOptions(options);
		
		// init slides
		this.slides = this.options.container.getElements('li');
		if (this.slides) {
			this.initSlides();
		}
		
		// set first slide to be visible
		this.currentSlide = 0;
		
		// start functionality
		this.startSlide();
	},
	
	/**
	 * add class 'slide' and hides elements of current pushbox
	 * @return void
	 */
	initSlides: function() {
		this.slides.each(function(slide, index) {
			slide.addClass('slide');
			slide.fade('hide');
		})
	},
	
	/**
	 * fades the first slide in and starts progress bar
	 * @return void
	 */	
	startSlide: function() {
		this.slides[this.currentSlide].fade('show');
		this.startProgressBar();
	},
	
	/**
	 * adds one to or resets slide index
	 * fades over the slides and starts progress bar
	 * @return void
	 */	
	showSlide: function() {
		this.currentSlide++;
		if (this.currentSlide >= this.slides.length) {
			this.currentSlide = 0			
		}
		
		this.previousSlide = this.currentSlide-1;
		if (this.previousSlide < 0) {
			this.previousSlide = this.slides.length-1;			
		}
		
		this.slides[this.previousSlide].fade('out').get('tween').chain(function() {
			this.resetProgressBar();
			this.slides[this.currentSlide].fade('in').get('tween').chain(function() {
				this.startProgressBar();
			}.bind(this));
		}.bind(this));
	},
	
	/**
	 * resets and starts animation of progressbar
	 * @return void
	 */	
	startProgressBar: function() {
		this.progressBar = this.slides[this.currentSlide].getElement('div.progressbar');
		this.resetProgressBar();
		this.progressBar.set('tween', {duration: (this.options.duration*1000).toInt()});
		this.progressBar.tween('left', 0).get('tween').chain(function() {
			this.showSlide();
		}.bind(this));
	},

	/**
	 * reset progressbar method
	 * @return void
	 */	
	resetProgressBar: function() {
		this.progressBar.setStyle('left', '-660px');
	}
});
