if(typeof Prototype=="undefined"||!Prototype.Version.match("1.6")){throw ("Prototype-UI library require Prototype library >= 1.6.0")}if(Prototype.Browser.WebKit){Prototype.Browser.WebKitVersion=parseFloat(navigator.userAgent.match(/AppleWebKit\/([\d\.\+]*)/)[1]);Prototype.Browser.Safari2=(Prototype.Browser.WebKitVersion<420)}if(Prototype.Browser.IE){Prototype.Browser.IEVersion=parseFloat(navigator.appVersion.split(";")[1].strip().split(" ")[1]);Prototype.Browser.IE6=Prototype.Browser.IEVersion==6;Prototype.Browser.IE7=Prototype.Browser.IEVersion==7}Prototype.falseFunction=function(){return false};Prototype.trueFunction=function(){return true};var UI={Abstract:{},Ajax:{}};Object.extend(Class.Methods,{extend:Object.extend.methodize(),addMethods:Class.Methods.addMethods.wrap(function(e,d){if(!d){return this}if(!d.hasOwnProperty("methodsAdded")){return e(d)}var f=d.methodsAdded;delete d.methodsAdded;e(d);f.call(d,this);d.methodsAdded=f;return this}),addMethod:function(f,d){var e={};e[f]=d;return this.addMethods(e)},method:function(b){return this.prototype[b].valueOf()},classMethod:function(){$A(arguments).flatten().each(function(b){this[b]=(function(){return this[b].apply(this,arguments)}).bind(this.prototype)},this);return this},undefMethod:function(b){this.prototype[b]=undefined;return this},removeMethod:function(b){delete this.prototype[b];return this},aliasMethod:function(d,c){this.prototype[d]=this.prototype[c];return this},aliasMethodChain:function(c,d){d=d.camelcase();this.aliasMethod(c+"Without"+d,c);this.aliasMethod(c,c+"With"+d);return this}});Object.extend(Number.prototype,{snap:function(b){return parseInt(b==1?this:(this/b).floor()*b)}});Object.extend(String.prototype,{camelcase:function(){var b=this.dasherize().camelize();return b.charAt(0).toUpperCase()+b.slice(1)},makeElement:function(){var b=new Element("div");b.innerHTML=this;return b.down()}});Object.extend(Array.prototype,{empty:function(){return !this.length},extractOptions:function(){return this.last().constructor===Object?this.pop():{}},removeAt:function(c){var d=this[c];this.splice(c,1);return d},remove:function(c){var d;while((d=this.indexOf(c))!=-1){this.removeAt(d)}return c},insert:function(c){var d=$A(arguments);d.shift();this.splice.apply(this,[c,0].concat(d));return this}});Element.addMethods({getScrollDimensions:function(b){return{width:b.scrollWidth,height:b.scrollHeight}},getScrollOffset:function(b){return Element._returnOffset(b.scrollLeft,b.scrollTop)},setScrollOffset:function(d,c){d=$(d);if(arguments.length==3){c={left:c,top:arguments[2]}}d.scrollLeft=c.left;d.scrollTop=c.top;return d},getNumStyle:function(e,d){var f=parseFloat($(e).getStyle(d));return isNaN(f)?null:f},appendText:function(d,c){d=$(d);c=String.interpret(c);d.appendChild(document.createTextNode(c));return d}});document.whenReady=function(b){if(document.loaded){b.call(document)}else{document.observe("dom:loaded",b)}};Object.extend(document.viewport,{getScrollOffset:document.viewport.getScrollOffsets,setScrollOffset:function(b){Element.setScrollOffset(Prototype.Browser.WebKit?document.body:document.documentElement,b)},getScrollDimensions:function(){return Element.getScrollDimensions(Prototype.Browser.WebKit?document.body:document.documentElement)}});(function(){UI.Options={methodsAdded:function(a){a.classMethod($w(" setOptions allOptions optionsGetter optionsSetter optionsAccessor "))},setOptions:function(a){if(!this.hasOwnProperty("options")){this.options=this.allOptions()}this.options=Object.extend(this.options,a||{})},allOptions:function(){var d=this.constructor.superclass,a=d&&d.prototype;return(a&&a.allOptions)?Object.extend(a.allOptions(),this.options):Object.clone(this.options)},optionsGetter:function(){b(this,arguments,false)},optionsSetter:function(){b(this,arguments,true)},optionsAccessor:function(){this.optionsGetter.apply(this,arguments);this.optionsSetter.apply(this,arguments)}};function b(f,e,a){e=$A(e).flatten();if(e.empty()){e=Object.keys(f.allOptions())}e.each(function(c){var d=(a?"set":"get")+c.camelcase();f[d]=f[d]||(a?function(h){return this.options[c]=h}:function(){return this.options[c]})})}})();UI.Carousel=Class.create(UI.Options,{options:{direction:"horizontal",previousButton:".previous_button",nextButton:".next_button",container:".container",scrollInc:"auto",disabledButtonSuffix:"_disabled",overButtonSuffix:"_over"},initialize:function(d,e){this.setOptions(e);this.element=$(d);this.id=this.element.id;this.container=this.element.down(this.options.container).firstDescendant();this.elements=this.container.childElements();this.previousButton=this.options.previousButton==false?null:this.element.down(this.options.previousButton);this.nextButton=this.options.nextButton==false?null:this.element.down(this.options.nextButton);this.posAttribute=(this.options.direction=="horizontal"?"left":"top");this.dimAttribute=(this.options.direction=="horizontal"?"width":"height");this.elementSize=this.computeElementSize();this.nbVisible=this.currentSize()/this.elementSize;var f=this.options.scrollInc;if(f=="auto"){f=Math.floor(this.nbVisible)}[this.previousButton,this.nextButton].each(function(b){if(!b){return}var a=(b==this.nextButton?"next_button":"previous_button")+this.options.overButtonSuffix;b.clickHandler=this.scroll.bind(this,(b==this.nextButton?-1:1)*f*this.elementSize);b.observe("click",b.clickHandler).observe("mouseover",function(){b.addClassName(a)}.bind(this)).observe("mouseout",function(){b.removeClassName(a)}.bind(this))},this);this.updateButtons()},destroy:function($super){[this.previousButton,this.nextButton].each(function(b){if(!b){return}b.stopObserving("click",b.clickHandler)},this);this.element.remove();this.fire("destroyed")},fire:function(c,d){d=d||{};d.carousel=this;return this.element.fire("carousel:"+c,d)},observe:function(d,c){this.element.observe("carousel:"+d,c.bind(this));return this},stopObserving:function(d,c){this.element.stopObserving("carousel:"+d,c);return this},checkScroll:function(f,g){if(f>0){f=0}else{var e=this.elements.last().positionedOffset()[this.posAttribute]+this.elementSize;var h=this.currentSize();if(f+e<h){f+=h-(f+e)}f=Math.min(f,0)}if(g){this.container.style[this.posAttribute]=f+"px"}return f},scroll:function(d){if(this.animating){return this}var e=this.currentPosition()+d;e=this.checkScroll(e,false);d=e-this.currentPosition();if(d!=0){this.animating=true;this.fire("scroll:started");var f=this;this.container.morph("opacity:0.5",{duration:0.2,afterFinish:function(){f.container.morph(f.posAttribute+": "+e+"px",{duration:0.4,delay:0.2,afterFinish:function(){f.container.morph("opacity:1",{duration:0.2,afterFinish:function(){f.animating=false;f.updateButtons().fire("scroll:ended",{shift:d/f.currentSize()})}})}})}})}return this},scrollTo:function(b){if(this.animating||b<0||b>this.elements.length||b==this.currentIndex()||isNaN(parseInt(b))){return this}return this.scroll((this.currentIndex()-b)*this.elementSize)},updateButtons:function(){this.updatePreviousButton();this.updateNextButton();return this},updatePreviousButton:function(){var d=this.currentPosition();var c="previous_button"+this.options.disabledButtonSuffix;if(this.previousButton.hasClassName(c)&&d!=0){this.previousButton.removeClassName(c);this.fire("previousButton:enabled")}if(!this.previousButton.hasClassName(c)&&d==0){this.previousButton.addClassName(c);this.fire("previousButton:disabled")}},updateNextButton:function(){var e=this.currentLastPosition();var d=this.currentSize();var f="next_button"+this.options.disabledButtonSuffix;if(this.nextButton.hasClassName(f)&&e!=d){this.nextButton.removeClassName(f);this.fire("nextButton:enabled")}if(!this.nextButton.hasClassName(f)&&e==d){this.nextButton.addClassName(f);this.fire("nextButton:disabled")}},computeElementSize:function(){return this.elements.first().getDimensions()[this.dimAttribute]},currentIndex:function(){return -this.currentPosition()/this.elementSize},currentLastPosition:function(){if(this.container.childElements().empty()){return 0}return this.currentPosition()+this.elements.last().positionedOffset()[this.posAttribute]+this.elementSize},currentPosition:function(){return this.container.getNumStyle(this.posAttribute)},currentSize:function(){return this.container.parentNode.getDimensions()[this.dimAttribute]},updateSize:function(){this.nbVisible=this.currentSize()/this.elementSize;var b=this.options.scrollInc;if(b=="auto"){b=Math.floor(this.nbVisible)}[this.previousButton,this.nextButton].each(function(a){if(!a){return}a.stopObserving("click",a.clickHandler);a.clickHandler=this.scroll.bind(this,(a==this.nextButton?-1:1)*b*this.elementSize);a.observe("click",a.clickHandler)},this);this.checkScroll(this.currentPosition(),true);this.updateButtons().fire("sizeUpdated");return this}});UI.Ajax.Carousel=Class.create(UI.Carousel,{options:{elementSize:-1,url:null},initialize:function($super,c,d){if(!d.url){throw ("url option is required for UI.Ajax.Carousel")}if(!d.elementSize){throw ("elementSize option is required for UI.Ajax.Carousel")}$super(c,d);this.endIndex=0;this.hasMore=true;this.updateHandler=this.update.bind(this);this.updateAndScrollHandler=function(a,b,f){this.update(b,f);this.scroll(a)}.bind(this);this.runRequest.bind(this).defer({parameters:{from:0,to:Math.ceil(this.nbVisible)-1},onSuccess:this.updateHandler})},runRequest:function(b){this.requestRunning=true;new Ajax.Request(this.options.url,Object.extend({method:"GET"},b));this.fire("request:started");return this},scroll:function($super,f){if(this.animating||this.requestRunning){return this}var g=(-f)/this.elementSize;if(this.hasMore&&g>0&&this.currentIndex()+this.nbVisible+g-1>this.endIndex){var h=this.endIndex+1;var e=Math.ceil(h+this.nbVisible-1);this.runRequest({parameters:{from:h,to:e},onSuccess:this.updateAndScrollHandler.curry(f).bind(this)});return this}else{$super(f)}},update:function(c,d){this.requestRunning=false;this.fire("request:ended");if(!d){d=c.responseJSON}this.hasMore=d.more;this.endIndex=Math.max(this.endIndex,d.to);this.elements=this.container.insert({bottom:d.html}).childElements();return this.updateButtons()},computeElementSize:function(){return this.options.elementSize},updateSize:function($super){var d=this.nbVisible;$super();if(Math.floor(this.nbVisible)-Math.floor(d)>=1&&this.hasMore){if(this.currentIndex()+Math.floor(this.nbVisible)>=this.endIndex){var c=Math.floor(this.currentIndex()+Math.floor(this.nbVisible)-this.endIndex);this.runRequest({parameters:{from:this.endIndex+1,to:this.endIndex+c},onSuccess:this.updateHandler})}}return this},updateNextButton:function($super){var e=this.currentLastPosition();var d=this.currentSize();var f="next_button"+this.options.disabledButtonSuffix;if(this.nextButton.hasClassName(f)&&e!=d){this.nextButton.removeClassName(f);this.fire("nextButton:enabled")}if(!this.nextButton.hasClassName(f)&&e==d&&!this.hasMore){this.nextButton.addClassName(f);this.fire("nextButton:disabled")}}});