var celciusSlideshow = new Class({
	options: {
		controls: '',
		showDuration: '',
		footer: ''
	},

	Implements: [Options,Events],

	initialize: function(container,elements,options) {
		this.setOptions(options);

		this.container 		= $(container);
		this.elements 		= $$(elements);
		this.currentIndex 	= 0;
		this.interval 		= '';
		this.showDuration 	= this.options.showDuration;
		this.controls		= $(this.options.controls);
		this.footer		= $(this.options.footer);

		this.elements.each( function(el,i){ if(i > 0) el.set('opacity',0); },this );
		this.setCaption();
		
		if( this.controls ){
			if( this.elements.length > 1 ){
				(this.controls.getChildren('div'))[0].addEvent( 'click', function(){ this.prev(); }.bind( this ) );
				(this.controls.getChildren('div'))[1].addEvent( 'click', function(){ this.next(); }.bind( this ) );
				this.controls.getChildren('img').addEvents({
					'mouseenter' : function(){ this.setProperty('src', this.getProperty('src').replace('off', 'on' ) ); },
					'mouseleave' : function(){ this.setProperty('src', this.getProperty('src').replace('on', 'off' ) ); }
				});				
			}else{
				this.controls.setStyle('display','none');
			}
		}
	},

	show: function(to) {
		this.elements[this.currentIndex].setStyle('opacity',0);
		this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex + 1 : 0));
		this.elements[this.currentIndex].setStyle('opacity',1);
		this.setCaption();
	},

	start: function() {
		this.interval = this.show.bind(this).periodical(this.showDuration);
	},

	stop: function() {
		$clear(this.interval);
	},

	next: function() {
		this.stop();
		this.show();
	},

	prev: function() {
		this.stop();
		this.show(this.currentIndex != 0 ? this.currentIndex -1 : this.elements.length-1);
	},
	
	setCaption: function() {
		if( this.footer ){
			this.footer.set('html', this.elements[this.currentIndex].get('rel') );
		}	
	}
});
