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="Текущее изображение"/><div class="previous" title="Показать предыдущее изображение">&lt;</div><div class="next" title="Показать следующее изображение">&gt;</div><div class="index">0 / 0</div><div class="maximize" title="Максимизировать"></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")?"\u041C\u0430\u043A\u0441\u0438\u043C\u0438\u0437\u0438\u0440\u043E\u0432\u0430\u0442\u044C":"\u041C\u0438\u043D\u0438\u043C\u0438\u0437\u0438\u0440\u043E\u0432\u0430\u0442\u044C";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(c){var d=(c&&c.memo.elements)||[$("body")];d.forEach(function(f){var e=f.hasClassName("gallery")?[f]:f.select(".gallery");e.forEach(function(g){new b.Gallery(g)})})}(b.isInitialized&&a())||document.observe("xwiki:dom:loading",a);document.observe("xwiki:dom:updated",a);return b}(XWiki||{}));