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

	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.elements.each( function(el,i){ if(i > 0) el.setStyles({'opacity':0, 'visibility':'visible'}); },this );
		
		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 ) );
		}else{
			this.controls.setStyle('display','none');
		}
	},

	show: function(to) {
		if( this.elements.length > 0 ){
			this.elements[this.currentIndex].fade('out');
			this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex + 1 : 0));
			this.elements[this.currentIndex].fade('in');
		}
	},

	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);
	}
});
