var OtherProjects = new Class({
	Implements: [Events, Options],
	
	options: {
		sliderPos: 0,
		sliderStep: 3,
		visibleElements: 3
	},
	
	initialize: function(options){
		this.setOptions(options);
		this.slider = $$('div.projects div.slider')[0];
		this.sliderFX = new Fx.Scroll(this.slider, {
			fps:75,
			onStart: function(){
				this.running = true;
			}.bind(this),
			onComplete: function(){
				this.running = false;
			}.bind(this)
		});
		this.sliderElements = this.slider.getElements('.project');
		this.running = false;
		
		this.initWrapper();
		this.buildSliderControls();
	},
	
	prev: function(){
		if (!this.running){
			var pos = 0;
			if ((this.options.sliderPos-this.options.sliderStep) >= 0){
				pos = this.sliderElements[this.options.sliderPos-this.options.sliderStep];
			} else if (this.options.sliderPos > 0 && (this.options.sliderPos-this.options.sliderStep) < 0) {
				pos = this.sliderElements[0];
			} else 
				return false;
			
			this.sliderFX.toElement(pos);
			this.options.sliderPos = this.sliderElements.indexOf(pos);
		}
	},
	
	next: function(){
		if (!this.running){
			var pos = 0;

			if ((this.options.sliderPos+this.options.sliderStep) <= (this.sliderElements.length-1)){
				pos = this.sliderElements[this.options.sliderPos+this.options.sliderStep];
			} else if (this.options.sliderPos < (this.sliderElements.length-this.options.sliderStep) && (this.options.sliderPos+this.options.sliderStep) > (this.sliderElements.length-1)) {
				pos = this.sliderElements.getLast();
			} else {
				return false;
			}
			
			this.sliderFX.toElement(pos);
			this.options.sliderPos = this.sliderElements.indexOf(pos);
		}
	},
	
	initWrapper: function(){
		var width = this.sliderElements[0].getCoordinates().width;
		var margin = parseInt(this.sliderElements[0].getStyle('margin-right'));
		this.slider.getElement('.wrapper').setStyles({'width' : this.sliderElements.length*width+(this.sliderElements.length)*margin});
	},
	
	buildSliderControls: function(){
		if (this.sliderElements.length <= this.options.visibleElements)
			this.slider.getSiblings('a.prev, a.next').setStyles({'visibility' : 'hidden'});
			
		this.slider.getSiblings('a.prev')[0].addEvent('click', function(e){
			e.stop();
			this.prev();
		}.bind(this));
		
		this.slider.getSiblings('a.next')[0].addEvent('click', function(e){
			e.stop();
			this.next();
		}.bind(this));
	}
});
