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

	Implements: [Options,Events],

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

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

		this.elements.each( function(el,i){ if(i > 0){ el.setStyles({'opacity':0, 'z-index':0}); }else{ el.setStyle('z-index','999') } },this );
		
		if( this.controls.length > 0 ){ 
			this.controls[this.currentIndex].setStyle('color', '#FFFFFF');
			this.controls.each(  function(el,i){ el.addEvent( 'click', function(){ this.stop(); this.show(i); }.bind( this ) ); }, this );
		}
		
		if( this.markers.length > 0 ){ this.markers[this.currentIndex].removeClass('markers_off').addClass('markers_on'); }

		if( this.download ){
			this.download.setProperty( 'href', (this.download.getProperty( 'href' ).split("="))[0] + "=" + (this.elements[this.currentIndex].getProperty('src').split("/")).getLast() );
		}		
	},

	show: function(to) {
		if( this.markers.length > 0 ){ this.markers[this.currentIndex].removeClass('markers_on').addClass('markers_off'); }
		if( this.controls.length > 0 ){ this.controls[this.currentIndex].removeProperty('style'); }
		
		this.elements[this.currentIndex].fade('out');
		this.elements[this.currentIndex].setStyle('z-index',0);
		
		this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex + 1 : 0));
		
		this.elements[this.currentIndex].fade('in');
		this.elements[this.currentIndex].setStyle('z-index',999);
		
		if( this.download ){
			this.download.setProperty( 'href', (this.download.getProperty( 'href' ).split("="))[0] + "=" + (this.elements[this.currentIndex].getProperty('src').split("/")).getLast() );
		}
		
		if( this.markers.length > 0 ){ this.markers[this.currentIndex].removeClass('markers_off').addClass('markers_on'); }
		if( this.controls.length > 0 ){ this.controls[this.currentIndex].setStyle('color', '#FFFFFF'); }
	},

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