/* mooWheel - 2010 02 24 */
/* @ Wesley (NovaRage) */
var mooWheel=new Class({Implements:[Options],options:{step:168,steps:4,activeStep:5,startDirectionRight:true,duration:700,fps:100,transition:'sine:in:out',maxItems:0,maxMargin:0},el:{links:{},rechts:{},carrousel:{}},initialize:function(el,options){this.setOptions(options);this.el.cBox=el;this.getFields();this.setFields();},getFields:function(){this.el.links=this.el.cBox.getElements('div.links');this.el.carrousel=this.el.cBox.getElements('div#carrousel');this.el.rechts=this.el.cBox.getElements('div.rechts');},keyPress:function(evt){switch(evt.key){case'right':this.goRight();break;case'left':this.goLeft();break;}},wheel:function(evt){if(evt.wheel<0)this.goRight();else
this.goLeft();return false;},setFields:function(){this.el.rechts.set({events:{click:this.goRight.bind(this)}});this.el.links.set({events:{click:this.goLeft.bind(this)}});document.addEvent('keydown',this.keyPress.bind(this));this.el.cBox.addEvent('DOMMouseScroll',this.wheel.bind(this));this.el.cBox.addEvent('mousewheel',this.wheel.bind(this));this.el.carrousel.set('tween',{duration:this.options.duration,fps:this.options.fps,transition:this.options.transition});this.margin=(this.startDirectionRight)?'marginRight':'marginLeft';this.options.maxItems=$$('div#carrousel div.carrousel-item').length;this.options.maxMargin=toInt('-'+(this.options.step*(this.options.maxItems-toInt(this.options.activeStep+1))));this.chkSetDisabled(0);},goLeft:function(){var curMargin=this.el.carrousel.getStyle(this.margin);curMargin=toInt(curMargin.toString().replace(/px/i,''));if(curMargin%this.options.step!=0)return false;var curSteps=toInt(curMargin.toString().replace('-',''))/toInt(this.options.step);var nextSteps=curSteps-toInt(this.options.steps);if(nextSteps<0)nextSteps=0;var nextMargin='-'+(nextSteps*this.options.step);if(curSteps==0&&this.options.maxItems>this.options.activeStep){nextMargin=(this.options.maxMargin-this.options.step);this.chkSetDisabled(nextMargin);this.el.carrousel.tween(this.margin,nextMargin+'px');}else if(curSteps!=0){this.chkSetDisabled(nextMargin);this.el.carrousel.tween(this.margin,nextMargin+'px');}},goRight:function(){var curMargin=this.el.carrousel.getStyle(this.margin);curMargin=toInt(curMargin.toString().replace(/px/i,''));if(curMargin%this.options.step!=0)return false;var curSteps=toInt(curMargin.toString().replace('-',''))/toInt(this.options.step);var nextSteps=curSteps+toInt(this.options.steps);if(nextSteps+this.options.activeStep>=this.options.maxItems)nextSteps=this.options.maxItems-this.options.activeStep;var nextMargin='-'+(nextSteps*this.options.step);if(curSteps==nextSteps){this.chkSetDisabled(0);this.el.carrousel.tween(this.margin,0+'px');}else{this.chkSetDisabled(nextMargin);this.el.carrousel.tween(this.margin,nextMargin+'px');}},chkSetDisabled:function(nextMargin){if(nextMargin<0)this.el.links.removeClass('disabled');else
this.el.links.addClass('disabled');if(this.options.maxMargin<=nextMargin&&this.options.maxItems>this.options.activeStep)this.el.rechts.removeClass('disabled');else
this.el.rechts.addClass('disabled');}});
