var froiSlider = new Class({
	initialize: function(params){
		this.box = params.box;
		this.interval = params.interval || 4000;
		this.listItems = params.box.getElements('li');
		//this.listItemsInfo = params.box.getElements('li .hoverInfo');
		this.numItems = params.box.getElements('li').length;
		this.visible = params.visible || '4';
		this.currentLast = this.visible;
		this.currentFirst = 1;
		this.direction = params.direction || "right";
		
		this.startUp();
		this.auto = this.rotate.periodical(this.interval, this);
		this.addEvents();
	},
	
	startUp: function(){
		this.listItems.setStyle('display', 'none');
		this.box.getElements('#leftArrow').setStyle('display', 'inline');
		this.box.getElements('#rightArrow').setStyle('display', 'inline');
		//this.listItemsInfo.setStyle('display', 'none');
		this.box.getElements('#leftArrow').setStyles({cursor: 'auto', opacity: '.3'});
		for(i = 1; i < this.visible+1; i++){
			this.listItems[i].setStyle('display', 'block');
		}
	},
	
	addEvents: function(){
			var thisHolder = this;
			this.box.addEvents({
				mouseover: function() {$clear(thisHolder.auto)},
				mouseout: function() {thisHolder.auto = thisHolder.rotate.periodical(thisHolder.interval, thisHolder)}
			});
			//this.listItems.addEvents({
			//	mouseover: function() { this.getElements('.hoverInfo').setStyle('display', 'inline'); },
			//	mouseout: function() { this.getElements('.hoverInfo').setStyle('display', 'none'); }
			//});
			this.box.getElements('#leftArrow').addEvents({
				click: function() { thisHolder.left() }
			});
			this.box.getElements('#rightArrow').addEvents({
				click: function() { thisHolder.right() }
			});
	},
	
	right: function(delay){		
		if( this.currentLast < this.numItems - 2 ){
			this.listItems[this.currentFirst].setStyle('display', 'none');
			this.currentLast++;
			this.currentFirst++;
			this.listItems[this.currentLast].setStyle('display', 'block');

			if(this.currentLast == this.numItems-2){
				this.box.getElements('#rightArrow').setStyles({cursor: 'auto', opacity: '.3'});
			}
			else if(this.box.getElements('#leftArrow').getStyle('cursor').contains('auto')){
				this.box.getElements('#leftArrow').setStyles({cursor: 'pointer', opacity: '1'});
			}
		}
		else{
			this.direction = "left";
			return false;
		}
	},
	
	left: function(delay){
		if( this.currentFirst > 1 ){
			this.listItems[this.currentLast].setStyle('display', 'none');
			this.currentLast--;
			this.currentFirst--;
			this.listItems[this.currentFirst].setStyle('display', 'block');
			
			if(this.currentFirst == 1){
				this.box.getElements('#leftArrow').setStyles({cursor: 'auto', opacity: '.3'});
			}
			else if(this.box.getElements('#rightArrow').getStyle('cursor').contains('auto')){
				this.box.getElements('#rightArrow').setStyles({ cursor: 'pointer', opacity: '1'});
			}
		}
		else{
			this.direction = "right";
			return false;
		}
	},
	
	rotate: function(){
		if(this.direction == "right"){
			this.right();
		}
		else{
			this.left();	
		}
	}
});

window.addEvent('domready', function(){  
	var rollMe = new froiSlider({
		box: $('slider'),
		interval: 7000,
		visible: 3
	});
});