var XWiki=(function(b){b.Gallery=Class.create({initialize:function(c){this.images=this._collectImages(c);this.container=c.update('<input type="text" tabindex="-1" class="focusCatcher"/><img class="currentImage" alt="Current image"/><div class="previous" title="Show previous image">&lt;</div><div class="next" title="Show next image">&gt;</div><div class="index">0 / 0</div><div class="maximize" title="Maximize"></div>');this.container.addClassName("xGallery");this.focusCatcher=this.container.down(".focusCatcher");this.focusCatcher.observe("keydown",this._onKeyDown.bindAsEventListener(this));this.container.observe("click",function(){this.focusCatcher.focus()}.bind(this));this.container.down(".previous").observe("click",this._onPreviousImage.bind(this));this.container.down(".next").observe("click",this._onNextImage.bind(this));this.currentImage=this.container.down(".currentImage");this.currentImage.observe("load",this._onLoadImage.bind(this));this.currentImage.observe("error",this._onErrorImage.bind(this));this.currentImage.observe("abort",this._onAbortImage.bind(this));this.indexDisplay=this.container.down(".index");this.maximizeToggle=this.container.down(".maximize");this.maximizeToggle.observe("click",this._onToggleMaximize.bind(this));this.show(0)},_collectImages:function(d){var c=[];var f=d.select("img");for(var e=0;e<f.length;e++){var g=f[e];c.push({url:g.getAttribute("src"),title:g.title});g.removeAttribute("src")}return c},_onPreviousImage:function(){this.show(this.index>0?this.index-1:this.images.length-1)},_onNextImage:function(){this.show(this.index<this.images.length-1?this.index+1:0)},_onLoadImage:function(){Element.removeClassName(this.currentImage.parentNode,"loading");this.currentImage.style.visibility="visible"},_onErrorImage:function(){},_onAbortImage:function(){},_onKeyDown:function(d){var c=true;switch(d.keyCode){case Event.KEY_LEFT:this._onPreviousImage();break;case Event.KEY_RIGHT:this._onNextImage();break;case Event.KEY_HOME:this.show(0);break;case Event.KEY_END:this.show(this.images.length-1);break;case Event.KEY_ESC:if(this.container.hasClassName("maximized")){this._onToggleMaximize()}break;case 70:this._onToggleMaximize();break;default:c=false;break}if(c){Event.stop(d)}},_onToggleMaximize:function(){this.maximizeToggle.toggleClassName("maximize");this.maximizeToggle.toggleClassName("minimize");this.maximizeToggle.title=this.maximizeToggle.hasClassName("maximize")?"Maximize":"Minimize";this.container.toggleClassName("maximized");$(document.documentElement).toggleClassName("maximized")},show:function(c){if(c<0||c>=this.images.length||c==this.index){return}if(this.currentImage.src!=this.images[c].url){this.currentImage.style.visibility="hidden";Element.addClassName(this.currentImage.parentNode,"loading");this.currentImage.title=this.images[c].title;this.currentImage.src=this.images[c].url}this.index=c;this.indexDisplay.update((c+1)+" / "+this.images.length)}});function a(){$$(".gallery").each(function(c){new b.Gallery(c)})}(b.isInitialized&&a())||document.observe("xwiki:dom:loading",a);return b}(XWiki||{}));