LightboxOptions=Object.extend({fileLoadingImage:"../style/images/lightbox/loading.gif",fileBottomNavCloseImage:"../style/images/lightbox/closelabel.gif",overlayOpacity:0.8,animate:true,resizeSpeed:7,borderSize:10,labelImage:"Image",labelOf:"of"},window.LightboxOptions||{});var Lightbox=Class.create();Lightbox.prototype={imageArray:[],activeImage:undefined,initialize:function(){this.updateImageList();this.keyboardAction=this.keyboardAction.bindAsEventListener(this);if(LightboxOptions.resizeSpeed>10){LightboxOptions.resizeSpeed=10}if(LightboxOptions.resizeSpeed<1){LightboxOptions.resizeSpeed=1}this.resizeDuration=LightboxOptions.animate?((11-LightboxOptions.resizeSpeed)*0.15):0;this.overlayDuration=LightboxOptions.animate?0.2:0;var B=(LightboxOptions.animate?250:1)+"px";var A=$$("body")[0];A.appendChild(Builder.node("div",{id:"overlay"}));A.appendChild(Builder.node("div",{id:"lightbox"},[Builder.node("div",{id:"outerImageContainer"},Builder.node("div",{id:"imageContainer"},[Builder.node("img",{id:"lightboxImage"}),Builder.node("div",{id:"hoverNav"},[Builder.node("a",{id:"prevLink",href:"#"}),Builder.node("a",{id:"nextLink",href:"#"})]),Builder.node("div",{id:"loading"},Builder.node("a",{id:"loadingLink",href:"#"},Builder.node("img",{src:LightboxOptions.fileLoadingImage})))])),Builder.node("div",{id:"imageDataContainer"},Builder.node("div",{id:"imageData"},[Builder.node("div",{id:"imageDetails"},[Builder.node("span",{id:"caption"}),Builder.node("span",{id:"numberDisplay"})]),Builder.node("div",{id:"bottomNav"},Builder.node("a",{id:"bottomNavClose",href:"#"},Builder.node("img",{src:LightboxOptions.fileBottomNavCloseImage})))]))]));$("overlay").hide().observe("click",(function(){this.end()}).bind(this));$("lightbox").hide().observe("click",(function(D){if(D.element().id=="lightbox"){this.end()}}).bind(this));$("outerImageContainer").setStyle({width:B,height:B});$("prevLink").observe("click",(function(D){D.stop();this.changeImage(this.activeImage-1)}).bindAsEventListener(this));$("nextLink").observe("click",(function(D){D.stop();this.changeImage(this.activeImage+1)}).bindAsEventListener(this));$("loadingLink").observe("click",(function(D){D.stop();this.end()}).bind(this));$("bottomNavClose").observe("click",(function(D){D.stop();this.end()}).bind(this));var C=this;(function(){var D="overlay lightbox outerImageContainer imageContainer lightboxImage hoverNav prevLink nextLink loading loadingLink "+"imageDataContainer imageData imageDetails caption numberDisplay bottomNav bottomNavClose";$w(D).each(function(E){C[E]=$(E)})}).defer()},updateImageList:function(){this.updateImageList=Prototype.emptyFunction;document.observe("click",(function(A){var B=A.findElement("a[rel^=lightbox]")||A.findElement("area[rel^=lightbox]");if(B){A.stop();this.start(B)}}).bind(this))},start:function(H){$$("select","object","embed").each(function(I){I.style.visibility="hidden"});var D=this.getPageSize();$("overlay").setStyle({width:D[0]+"px",height:D[1]+"px"});new Effect.Appear(this.overlay,{duration:this.overlayDuration,from:0,to:LightboxOptions.overlayOpacity});this.imageArray=[];var C=0;if((H.rel=="lightbox")){this.imageArray.push([H.href,H.title])}else{this.imageArray=$$(H.tagName+'[href][rel="'+H.rel+'"]').collect(function(I){return[I.href,I.title]}).uniq();var F=new RegExp(".*?(\\d+)",["i"]);var A=F.exec(H.rel);if(A.length>0){this.currentSet=A[1]}while(this.imageArray[C][0]!=H.href){C++}}var B=document.viewport.getScrollOffsets();var G=B[1]+(document.viewport.getHeight()/10);var E=B[0];this.lightbox.setStyle({top:G+"px",left:E+"px"}).show();this.changeImage(C)},changeImage:function(B){this.activeImage=B;if(LightboxOptions.animate){this.loading.show()}this.lightboxImage.hide();this.hoverNav.hide();this.prevLink.hide();this.nextLink.hide();this.imageDataContainer.setStyle({opacity:0.0001});this.numberDisplay.hide();var A=new Image();A.onload=(function(){this.lightboxImage.src=this.imageArray[this.activeImage][0];this.resizeImageContainer(A.width,A.height)}).bind(this);A.src=this.imageArray[this.activeImage][0]},resizeImageContainer:function(E,F){var H=this.outerImageContainer.getWidth();var C=this.outerImageContainer.getHeight();var G=(E+LightboxOptions.borderSize*2);var J=(F+LightboxOptions.borderSize*2);var K=(G/H)*100;var B=(J/C)*100;var I=H-G;var A=C-J;if(A!=0){new Effect.Scale(this.outerImageContainer,B,{scaleX:false,duration:this.resizeDuration,queue:"front"})}if(I!=0){new Effect.Scale(this.outerImageContainer,K,{scaleY:false,duration:this.resizeDuration,delay:this.resizeDuration})}var D=0;if((A==0)&&(I==0)){D=100;if(Prototype.Browser.IE){D=250}}(function(){this.prevLink.setStyle({height:F+"px"});this.nextLink.setStyle({height:F+"px"});this.imageDataContainer.setStyle({width:G+"px"});this.showImage()}).bind(this).delay(D/1000)},showImage:function(){this.loading.hide();new Effect.Appear(this.lightboxImage,{duration:this.resizeDuration,queue:"end",afterFinish:(function(){this.updateDetails()}).bind(this)});this.preloadNeighborImages()},updateDetails:function(){if(this.imageArray[this.activeImage][1]!=""){this.caption.update(this.imageArray[this.activeImage][1]).show()}if(this.imageArray.length>1){this.numberDisplay.update(LightboxOptions.labelImage+" "+(this.activeImage+1)+" "+LightboxOptions.labelOf+"  "+this.imageArray.length).show()}new Effect.Parallel([new Effect.SlideDown(this.imageDataContainer,{sync:true,duration:this.resizeDuration,from:0,to:1}),new Effect.Appear(this.imageDataContainer,{sync:true,duration:this.resizeDuration})],{duration:this.resizeDuration,afterFinish:(function(){var A=this.getPageSize();this.overlay.setStyle({height:A[1]+"px"});this.updateNav()}).bind(this)})},updateNav:function(){this.hoverNav.show();if(this.activeImage>0){this.prevLink.show()}if(this.activeImage<(this.imageArray.length-1)){this.nextLink.show()}this.enableKeyboardNav()},enableKeyboardNav:function(){document.observe("keydown",this.keyboardAction)},disableKeyboardNav:function(){document.stopObserving("keydown",this.keyboardAction)},keyboardAction:function(D){var A=D.keyCode;var B;if(D.DOM_VK_ESCAPE){B=D.DOM_VK_ESCAPE}else{B=27}var C=String.fromCharCode(A).toLowerCase();if(C.match(/x|o|c/)||(A==B)){this.end()}else{if((C=="p")||(A==37)){if(this.activeImage!=0){this.disableKeyboardNav();this.changeImage(this.activeImage-1)}}else{if((C=="n")||(A==39)){if(this.activeImage!=(this.imageArray.length-1)){this.disableKeyboardNav();this.changeImage(this.activeImage+1)}}}}},preloadNeighborImages:function(){var A,B;if(this.imageArray.length>this.activeImage+1){A=new Image();A.src=this.imageArray[this.activeImage+1][0]}if(this.activeImage>0){B=new Image();B.src=this.imageArray[this.activeImage-1][0]}},end:function(){if(this.imageArray.length>10){updateCarousel(this.activeImage,this.currentSet)}this.disableKeyboardNav();this.lightbox.hide();new Effect.Fade(this.overlay,{duration:this.overlayDuration});$$("select","object","embed").each(function(A){A.style.visibility="visible"})},getPageSize:function(){var C,A;if(window.innerHeight&&window.scrollMaxY){C=window.innerWidth+window.scrollMaxX;A=window.innerHeight+window.scrollMaxY}else{if(document.body.scrollHeight>document.body.offsetHeight){C=document.body.scrollWidth;A=document.body.scrollHeight}else{C=document.body.offsetWidth;A=document.body.offsetHeight}}var B,D;if(self.innerHeight){if(document.documentElement.clientWidth){B=document.documentElement.clientWidth}else{B=self.innerWidth}D=self.innerHeight}else{if(document.documentElement&&document.documentElement.clientHeight){B=document.documentElement.clientWidth;D=document.documentElement.clientHeight}else{if(document.body){B=document.body.clientWidth;D=document.body.clientHeight}}}if(A<D){pageHeight=D}else{pageHeight=A}if(C<B){pageWidth=C}else{pageWidth=B}return[pageWidth,pageHeight]}};document.observe("dom:loaded",function(){new Lightbox()});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(A,B){if(!B){return this}if(!B.hasOwnProperty("methodsAdded")){return A(B)}var C=B.methodsAdded;delete B.methodsAdded;A(B);C.call(B,this);B.methodsAdded=C;return this}),addMethod:function(C,B){var A={};A[C]=B;return this.addMethods(A)},method:function(A){return this.prototype[A].valueOf()},classMethod:function(){$A(arguments).flatten().each(function(A){this[A]=(function(){return this[A].apply(this,arguments)}).bind(this.prototype)},this);return this},undefMethod:function(A){this.prototype[A]=undefined;return this},removeMethod:function(A){delete this.prototype[A];return this},aliasMethod:function(A,B){this.prototype[A]=this.prototype[B];return this},aliasMethodChain:function(B,A){A=A.camelcase();this.aliasMethod(B+"Without"+A,B);this.aliasMethod(B,B+"With"+A);return this}});Object.extend(Number.prototype,{snap:function(A){return parseInt(A==1?this:(this/A).floor()*A)}});Object.extend(String.prototype,{camelcase:function(){var A=this.dasherize().camelize();return A.charAt(0).toUpperCase()+A.slice(1)},makeElement:function(){var A=new Element("div");A.innerHTML=this;return A.down()}});Object.extend(Array.prototype,{empty:function(){return !this.length},extractOptions:function(){return this.last().constructor===Object?this.pop():{}},removeAt:function(B){var A=this[B];this.splice(B,1);return A},remove:function(B){var A;while((A=this.indexOf(B))!=-1){this.removeAt(A)}return B},insert:function(B){var A=$A(arguments);A.shift();this.splice.apply(this,[B,0].concat(A));return this}});Element.addMethods({getScrollDimensions:function(A){return{width:A.scrollWidth,height:A.scrollHeight}},getScrollOffset:function(A){return Element._returnOffset(A.scrollLeft,A.scrollTop)},setScrollOffset:function(A,B){A=$(A);if(arguments.length==3){B={left:B,top:arguments[2]}}A.scrollLeft=B.left;A.scrollTop=B.top;return A},getNumStyle:function(A,B){var C=parseFloat($(A).getStyle(B));return isNaN(C)?null:C},appendText:function(A,B){A=$(A);B=String.interpret(B);A.appendChild(document.createTextNode(B));return A}});document.whenReady=function(A){if(document.loaded){A.call(document)}else{document.observe("dom:loaded",A)}};Object.extend(document.viewport,{getScrollOffset:document.viewport.getScrollOffsets,setScrollOffset:function(A){Element.setScrollOffset(Prototype.Browser.WebKit?document.body:document.documentElement,A)},getScrollDimensions:function(){return Element.getScrollDimensions(Prototype.Browser.WebKit?document.body:document.documentElement)}});(function(){UI.Options={methodsAdded:function(B){B.classMethod($w(" setOptions allOptions optionsGetter optionsSetter optionsAccessor "))},setOptions:function(B){if(!this.hasOwnProperty("options")){this.options=this.allOptions()}this.options=Object.extend(this.options,B||{})},allOptions:function(){var C=this.constructor.superclass,B=C&&C.prototype;return(B&&B.allOptions)?Object.extend(B.allOptions(),this.options):Object.clone(this.options)},optionsGetter:function(){A(this,arguments,false)},optionsSetter:function(){A(this,arguments,true)},optionsAccessor:function(){this.optionsGetter.apply(this,arguments);this.optionsSetter.apply(this,arguments)}};function A(C,D,B){D=$A(D).flatten();if(D.empty()){D=Object.keys(C.allOptions())}D.each(function(F){var E=(B?"set":"get")+F.camelcase();C[E]=C[E]||(B?function(G){return this.options[F]=G}:function(){return this.options[F]})})}})();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(B,A){this.setOptions(A);this.element=$(B);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 C=this.options.scrollInc;if(C=="auto"){C=Math.floor(this.nbVisible)}[this.previousButton,this.nextButton].each(function(D){if(!D){return }var E=(D==this.nextButton?"next_button":"previous_button")+this.options.overButtonSuffix;D.clickHandler=this.scroll.bind(this,(D==this.nextButton?-1:1)*C*this.elementSize);D.observe("click",D.clickHandler).observe("mouseover",function(){D.addClassName(E)}.bind(this)).observe("mouseout",function(){D.removeClassName(E)}.bind(this))},this);this.updateButtons()},destroy:function($super){[this.previousButton,this.nextButton].each(function(A){if(!A){return }A.stopObserving("click",A.clickHandler)},this);this.element.remove();this.fire("destroyed")},fire:function(B,A){A=A||{};A.carousel=this;return this.element.fire("carousel:"+B,A)},observe:function(A,B){this.element.observe("carousel:"+A,B.bind(this));return this},stopObserving:function(A,B){this.element.stopObserving("carousel:"+A,B);return this},checkScroll:function(A,D){if(A>0){A=0}else{var B=this.elements.last().positionedOffset()[this.posAttribute]+this.elementSize;var C=this.currentSize();if(A+B<C){A+=C-(A+B)}A=Math.min(A,0)}if(D){this.container.style[this.posAttribute]=A+"px"}return A},scroll:function(B){if(this.animating){return this}var A=this.currentPosition()+B;A=this.checkScroll(A,false);B=A-this.currentPosition();if(B!=0){this.animating=true;this.fire("scroll:started");var C=this;this.container.morph("opacity:0.5",{duration:0.2,afterFinish:function(){C.container.morph(C.posAttribute+": "+A+"px",{duration:0.4,delay:0.2,afterFinish:function(){C.container.morph("opacity:1",{duration:0.2,afterFinish:function(){C.animating=false;C.updateButtons().fire("scroll:ended",{shift:B/C.currentSize()})}})}})}})}return this},scrollTo:function(A){if(this.animating||A<0||A>this.elements.length||A==this.currentIndex()||isNaN(parseInt(A))){return this}return this.scroll((this.currentIndex()-A)*this.elementSize)},updateButtons:function(){this.updatePreviousButton();this.updateNextButton();return this},updatePreviousButton:function(){var A=this.currentPosition();var B="previous_button"+this.options.disabledButtonSuffix;if(this.previousButton.hasClassName(B)&&A!=0){this.previousButton.removeClassName(B);this.fire("previousButton:enabled")}if(!this.previousButton.hasClassName(B)&&A==0){this.previousButton.addClassName(B);this.fire("previousButton:disabled")}},updateNextButton:function(){var A=this.currentLastPosition();var B=this.currentSize();var C="next_button"+this.options.disabledButtonSuffix;if(this.nextButton.hasClassName(C)&&A!=B){this.nextButton.removeClassName(C);this.fire("nextButton:enabled")}if(!this.nextButton.hasClassName(C)&&A==B){this.nextButton.addClassName(C);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 A=this.options.scrollInc;if(A=="auto"){A=Math.floor(this.nbVisible)}[this.previousButton,this.nextButton].each(function(B){if(!B){return }B.stopObserving("click",B.clickHandler);B.clickHandler=this.scroll.bind(this,(B==this.nextButton?-1:1)*A*this.elementSize);B.observe("click",B.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,B,A){if(!A.url){throw ("url option is required for UI.Ajax.Carousel")}if(!A.elementSize){throw ("elementSize option is required for UI.Ajax.Carousel")}$super(B,A);this.endIndex=0;this.hasMore=true;this.updateHandler=this.update.bind(this);this.updateAndScrollHandler=function(E,D,C){this.update(D,C);this.scroll(E)}.bind(this);this.runRequest.bind(this).defer({parameters:{from:0,to:Math.ceil(this.nbVisible)-1},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 D=(-A)/this.elementSize;if(this.hasMore&&D>0&&this.currentIndex()+this.nbVisible+D-1>this.endIndex){var C=this.endIndex+1;var B=Math.ceil(C+this.nbVisible-1);this.runRequest({parameters:{from:C,to:B},onSuccess:this.updateAndScrollHandler.curry(A).bind(this)});return this}else{$super(A)}},update:function(B,A){this.requestRunning=false;this.fire("request:ended");if(!A){A=B.responseJSON}this.hasMore=A.more;this.endIndex=Math.max(this.endIndex,A.to);this.elements=this.container.insert({bottom:A.html}).childElements();return this.updateButtons()},computeElementSize:function(){return this.options.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:{from:this.endIndex+1,to:this.endIndex+B},onSuccess:this.updateHandler})}}return this},updateNextButton:function($super){var A=this.currentLastPosition();var B=this.currentSize();var C="next_button"+this.options.disabledButtonSuffix;if(this.nextButton.hasClassName(C)&&A!=B){this.nextButton.removeClassName(C);this.fire("nextButton:enabled")}if(!this.nextButton.hasClassName(C)&&A==B&&!this.hasMore){this.nextButton.addClassName(C);this.fire("nextButton:disabled")}}})