var celciusSlideshow = new Class({
    options: {
	showDuration: '',
	legende: ''
    },
    
    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.legende = this.options.legende;
	
	this.elements.each(function(el,i){
	    if(i > 0) el.set('opacity',0);
	},this);
	
	this.container.addEvents({
	    mouseenter: function() { this.stop(); }.bind(this),
	    mouseleave: function() { this.start(); }.bind(this)
	});
    },
    
    show: function(to) {
	this.elements[this.currentIndex].fade('out');
	this.setLegende( this.currentIndex, 'off' );
	this.currentIndex = ($defined(to) ? to : (this.currentIndex < this.elements.length - 1 ? this.currentIndex + 1 : 0));
	this.elements[this.currentIndex].fade('in');
	this.setLegende( this.currentIndex, 'on' );
    },
    
    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);
    },
    
    setLegende: function( i, state ){
    	target = this.legende + i;
    	if( $(target) ){
    		newSRC = $(target).getProperty( 'src' ).replace( "_on", "_STATE" ).replace( "_off", "_STATE" ).replace( "_STATE", "_" + state );
    		$(target).setProperty( 'src', newSRC );
    	}
    }
});
