/*
mootools : 1.2 
*/

var mooSlideMenu = new Class({
	Implements: Options,

	options: {
		property: 'margin-left',
		transition: Fx.Transitions.Quad.easeOut,
		transitionDuration: 5000,
		waitDuration: 1000,
		wait: true
	},
	totIncrement		: 0,
	increment			: 147,
	maxRightIncrement	: -1029,
	fx : null,
	
	initialize: function(element, pr, nx, options){
		this.setOptions(options);
		this.element = $(element);
		var sum=0;
		this.element.getElements('li').each(function(el,index){
		 	var s = el.getSize();
			sum+=s.x;
		});
		this.element.setStyle('width',sum+'px');
		var parent_size = this.element.getParent().getSize();
		this.maxRightIncrement = parent_size.x-sum;
		
		this.fx = new Fx.Tween(element);
		this.fx.set('tween',{
			duration: this.options.transitionDuration, 
			transition: this.options.transition, 
			wait: this.options.wait
		});
		$(pr).addEvent('click',function(e){	
			var e = new Event(e).stop();
			this.previous(); 
		}.bind(this));
		$(nx).addEvent('click',function(e){
			var e = new Event(e).stop();	
			this.next(); 
		}.bind(this));
	},
	
	start : function(){
		this.fx.stop;
		this.fx.start('margin-left',this.totIncrement+'px');
	},
	
	previous : function(){
		if(this.totIncrement<0){
			this.totIncrement = this.totIncrement+this.increment;
			this.start();
		}	
	},
	
	next : function(){
		if(this.totIncrement>this.maxRightIncrement){
		 	this.totIncrement = this.totIncrement-this.increment;
			this.start();
		}
	}
	
});
