// JavaScript Document

var FancySlider = new Class({
		
		options:{
			duration : 1000,
			transition : Fx.Transitions.Back.easeOut,
			sizeOfEach: 61,
			numberDisplayed: 5,
			styleToModify: 'margin-top',
			elementExtension: 'ul li',
			nextButtonExtension: '.nextLink',
			previousButtonExtension: '.previousLink'
		},
		
		initialize: function( element, options){
			this.setOptions(options);
			this.elements = $$(element + ' ' + this.options.elementExtension);
			this.parent = this.elements[0].getParent();
			this.container = this.parent.getParent();
			this.currentIndex = 0 + this.options.numberDisplayed;
			this.inProgress = false;
			this.totalElements = this.elements.length;
			this.animObject = new Fx.Style( this.parent, this.options.styleToModify, { duration: this.options.duration, transition: this.options.transition, onComplete:this.sortOutButtons.bindAsEventListener(this) } );
			this.nextButton = $$(element + ' ' + this.options.nextButtonExtension)[0];
			this.previousButton = $$(element + ' ' + this.options.previousButtonExtension)[0];
			if(window.ie){
				this.options.sizeOfEach = this.options.sizeOfEach + 3;
			}
			this.container.setStyle('height', this.options.sizeOfEach * this.options.numberDisplayed + 'px');
			this.nextButton.addEvent( 'click', this.slideLeft.bindAsEventListener(this) );
			this.previousButton.addEvent( 'click', this.slideRight.bindAsEventListener(this) );
			this.sortOutButtons();
		},
		
		slideLeft: function(ev){
			if( (this.currentIndex + 1) >= this.totalElements ){ return;}
			this.nextButton.setStyle( 'visibility', 'hidden' );
			this.previousButton.setStyle( 'visibility', 'hidden');
			currentMargin = this.parent.getStyle(this.options.styleToModify).toInt();
			this.animObject.start( currentMargin, currentMargin - (this.options.sizeOfEach * this.options.numberDisplayed) );
			this.currentIndex = this.currentIndex + this.options.numberDisplayed;
			this.InProgress = true;
		},
		
		slideRight: function(ev){
			if( this.currentIndex < this.options.numberDisplayed ){ return;}
			this.nextButton.setStyle( 'visibility', 'hidden' );
			this.previousButton.setStyle( 'visibility', 'hidden');
			currentMargin = this.parent.getStyle(this.options.styleToModify).toInt();
			this.animObject.start( currentMargin, currentMargin + (this.options.sizeOfEach * this.options.numberDisplayed) );
			this.currentIndex = this.currentIndex - this.options.numberDisplayed;
			this.InProgress = true;
		},
		
		sortOutButtons: function(){
			this.InProgress = false;
			if( this.options.numberDisplayed >= this.totalElements ){
				this.previousButton.setStyle( 'visibility', 'hidden' );
				this.nextButton.setStyle( 'visibility', 'hidden' );
			}else{
				if( (this.currentIndex + 1) > this.totalElements ){
					this.nextButton.setStyle( 'visibility', 'hidden' );
					this.previousButton.setStyle( 'visibility', 'visible');
				}else if( this.currentIndex <= (this.options.numberDisplayed + 1)  ){
					this.previousButton.setStyle( 'visibility', 'hidden' );
					this.nextButton.setStyle( 'visibility', 'visible');
				}else{
					this.nextButton.setStyle( 'visibility', 'visible');
					this.previousButton.setStyle( 'visibility', 'visible');
				}
			}
		}
});
			
FancySlider.implement(new Options);
		
			
		
		