var celciusRotator = new Class({
	options: {
		showDuration: '',
		itemWidth: ''
	},
	
	Implements: [Options,Events],

	initialize: function(container,elements,options) {
		this.setOptions(options);
		this.container = $(container);
		this.elements = $$(elements);
		this.currentIndex = 0;
		this.interval = '';
		this.direction = 'right';
		this.showDuration = this.options.showDuration;
		this.itemWidth = this.options.itemWidth;
	},

	show: function() {
		if( this.direction == 'right' ){
			precog = this.currentIndex + 1;
			if( ( precog > this.elements.length ) || ( precog == ( this.elements.length - 2 ) ) ){
				this.currentIndex = 0;
			}else{
				this.currentIndex = this.currentIndex + 1;
			}
		}else{
			precog = this.currentIndex - 1;
			if( precog < 0 ){
				this.currentIndex = this.elements.length;
			}else if( 
				( precog == ( this.elements.length - 1 ) ) || 
				( precog == ( this.elements.length - 2 ) )
			){
				this.currentIndex = this.elements.length - 4;
			}else{
				this.currentIndex = this.currentIndex - 1;
			}			
		}
		myFx = new Fx.Scroll( this.container ).start( (this.itemWidth * this.currentIndex), 0 );
	},

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

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

	next: function() {
		this.stop();
		this.direction = 'right';
		this.show();
	},

	prev: function() {
		this.stop();
		this.direction = 'left';
		this.show();
	}
});

var celciusSlideshow = new Class({
    options: {
	showDuration: '',
	thumbnailWidth: ''
    },
    
    Implements: [Options,Events],
    
    initialize: function(container,elements,otherSlider,thumbz,options){
    	this.setOptions(options);
	this.container = $(container);
	this.thumbContainer = $(thumbz);
	this.elements = $$(elements);
	this.otherSlider = otherSlider;
	this.currentIndex = 0;
	this.interval = '';
	this.showDuration = this.options.showDuration;
	this.thumbnailWidth = this.options.thumbnailWidth;
	this.elements.each( function(el,i){ if(i > 0) el.set('opacity',0); },this );	
    },
    
    show: function(to) {
	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');
	if( this.thumbContainer ){ myFx = new Fx.Scroll( this.thumbContainer ).start( (this.thumbnailWidth * this.currentIndex), 0 ); }
	if( this.otherSlider ){ this.otherSlider.show( this.currentIndex ); }
    },
    
    start: function() {
	this.interval = this.show.bind(this).periodical(this.options.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);
    }
});
