MLP.Carousel=Class.create(UI.Carousel,{options:{elementSize:-1,url:null,baseImageIndex:-1},initialize:function($super,a,b){if(!b.url){throw ("url option is required for MLP.Carousel")}if(!b.elementSize){throw ("elementSize option is required for MLP.Carousel")}$super(a,b);this.startIndex=0;this.endIndex=0;this.hasMore=true;this.hasLess=true;this.updateHandler=this.update.bind(this);this.updateAndScrollHandler=function(e,f,d){this.update(f,d);this.scroll(e)}.bind(this);var c=Math.ceil(this.nbVisible);this.runRequest.bind(this).defer({parameters:{baseIndex:this.options.baseImageIndex,direction:"both",count:c},onSuccess:this.updateHandler})},runRequest:function(a){this.requestRunning=true;new Ajax.Request(this.options.url,Object.extend({method:"GET"},a));this.fire("request:started");return this},scroll:function($super,a){if(this.animating||this.requestRunning){return this}var c=(-a)/this.elementSize;if(this.hasMore&&c>0&&this.currentIndex()+this.nbVisible+c-1>this.endIndex){var b=Math.ceil(this.nbVisible);this.runRequest({parameters:{baseIndex:this.endIndex,direction:"right",count:b},onSuccess:this.updateAndScrollHandler.curry(a).bind(this)});return this}if(this.hasLess&&c<0&&this.currentIndex()+this.nbVisible+c-1<this.startIndex){var b=Math.ceil(this.nbVisible);this.runRequest({parameters:{baseIndex:this.startIndex,direction:"left",count:b},onSuccess:this.updateAndScrollHandler.curry(a).bind(this)});return this}$super(a)},update:function(transport,json){try{this.requestRunning=false;this.fire("request:ended");if(!json){json=eval("("+transport.responseText+")")}if("left"==json.direction||"both"==json.direction){this.hasLess=json.less;this.startIndex=json.from}if("right"==json.direction||"both"==json.direction){this.hasMore=json.more;this.endIndex=json.to}if("right"==json.direction||"both"==json.direction){this.elements=this.container.insert({bottom:json.html}).childElements()}else{this.elements=this.container.insert({top:json.html}).childElements();var newElementsCount=parseInt(json.to)-parseInt(json.from);var newElementsWidth=this.options.elementSize*newElementsCount;var attribs={};attribs[this.posAttribute]=(-newElementsWidth)+"px";this.container.setStyle(attribs)}}catch(e){}return this.updateButtons()},computeElementSize:function(){return this.options.elementSize},currentIndex:function(){return this.startIndex-(this.currentPosition()/this.elementSize)},updateSize:function($super){var a=this.nbVisible;$super();if(Math.floor(this.nbVisible)-Math.floor(a)>=1&&this.hasMore){if(this.currentIndex()+Math.floor(this.nbVisible)>=this.endIndex){var b=Math.floor(this.currentIndex()+Math.floor(this.nbVisible)-this.endIndex);this.runRequest({parameters:{baseIndex:this.endIndex,direction:"left",count:b},onSuccess:this.updateHandler})}}return this},updatePreviousButton:function($super){var a=this.currentPosition();var b=this.currentSize();var c="previous_button"+this.options.disabledButtonSuffix;if(this.previousButton.hasClassName(c)&&(a!=0||this.hasLess)){this.previousButton.removeClassName(c);this.fire("previousButton:enabled")}else{if(!this.previousButton.hasClassName(c)&&a==0&&!this.hasLess){this.previousButton.addClassName(c);this.fire("previousButton:disabled")}}},updateNextButton:function($super){var c=this.currentLastPosition();var a=this.currentSize();var b="next_button"+this.options.disabledButtonSuffix;if(this.nextButton.hasClassName(b)&&(c!=a||this.hasMore)){this.nextButton.removeClassName(b);this.fire("nextButton:enabled")}else{if(!this.nextButton.hasClassName(b)&&c==a&&!this.hasMore){this.nextButton.addClassName(b);this.fire("nextButton:disabled")}}}});