var XWiki=(function(a){a.Gallery=Class.create({initialize:function(b){this.images=this._collectImages(b);
this.container=b.update('<input type="text" tabindex="-1" class="focusCatcher"/><div class="currentImageWrapper"><img class="currentImage" alt="${escapetool.xml($msg.get("core.widgets.gallery.currentImage"))}"/><span class="currentImagePinPoint"></span></div><div class="previous" title="${escapetool.xml($msg.get("core.widgets.gallery.previousImage"))}">&lt;</div><div class="next" title="${escapetool.xml($msg.get("core.widgets.gallery.nextImage"))}">&gt;</div><div class="index">0 / 0</div><div class="maximize" title="${escapetool.xml($msg.get("core.widgets.gallery.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(c){var b=[];
var e=c.select("img");
for(var d=0;
d<e.length;
d++){var f=e[d];
b.push({url:f.getAttribute("src"),title:f.title});
f.removeAttribute("src")
}return b
},_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(){this._maybeLimitImageSize();
Element.removeClassName(this.currentImage.parentNode,"loading");
this.currentImage.style.visibility="visible"
},_maybeLimitImageSize:function(){this.currentImage.style.height=this.currentImage.style.width="";
var c=this.currentImage.offsetHeight;
var d=this.currentImage.offsetWidth;
var g=this.currentImage.parentNode.offsetHeight;
var f=this.currentImage.parentNode.offsetWidth-128;
if(c>g||d>f){var e=d/c;
var b=f/e;
if(b>g){this.currentImage.style.height=g+"px"
}else{this.currentImage.style.width=f+"px"
}}},_onErrorImage:function(){},_onAbortImage:function(){},_onKeyDown:function(c){var b=true;
switch(c.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:b=false;
break
}if(b){Event.stop(c)
}},_onToggleMaximize:function(){this.maximizeToggle.toggleClassName("maximize");
this.maximizeToggle.toggleClassName("minimize");
this.maximizeToggle.title=this.maximizeToggle.hasClassName("maximize")?'${escapetool.javascript($msg.get("core.widgets.gallery.maximize"))}':'${escapetool.javascript($msg.get("core.widgets.gallery.minimize"))}';
this.container.toggleClassName("maximized");
$(document.documentElement).toggleClassName("maximized");
if(this.container.hasClassName("maximized")){this._maybeUpdatePosition();
this._updateSize()
}else{this._resetSize();
this._maybeResetPosition()
}},_isIE6:function(){return Prototype.Browser.IE&&navigator.appVersion.indexOf("MSIE 6")>-1
},_maybeUpdatePosition:function(){if(this._isIE6()){this.placeHolder=this.placeHolder||new Element("div",{"class":"xGalleryPlaceHolder"});
this.container.parentNode.replaceChild(this.placeHolder,this.container);
document.body.appendChild(this.container);
setTimeout(function(){this.focusCatcher.focus()
}.bind(this),0)
}},_maybeResetPosition:function(){if(this._isIE6()){this.placeHolder.parentNode.replaceChild(this.container,this.placeHolder);
setTimeout(function(){this.focusCatcher.focus()
}.bind(this),0)
}},_updateSize:function(){var d=document.viewport.getDimensions();
if(d.width<=0){d.width=document.body.clientWidth
}if(d.height<=0){d.height=document.body.clientHeight
}var c=d.width-20;
var b=d.height-20;
if(!this._isIE6()){this.container.setStyle({width:c+"px",height:b+"px"})
}this.currentImage.up().setStyle({height:b+"px",lineHeight:b+"px"});
this.currentImage.setStyle({maxHeight:b+"px",maxWidth:(c-128)+"px"});
this._maybeLimitImageSize()
},_resetSize:function(){this.container.style.cssText="";
this.container.removeAttribute("style");
this.currentImage.parentNode.style.cssText="";
this.currentImage.parentNode.removeAttribute("style");
this.currentImage.style.cssText="";
this.currentImage.removeAttribute("style");
this._maybeLimitImageSize()
},show:function(b){if(b<0||b>=this.images.length||b==this.index){return
}this.currentImage.style.visibility="hidden";
Element.addClassName(this.currentImage.parentNode,"loading");
this.currentImage.title=this.images[b].title;
this.currentImage.src=this.images[b].url;
this.index=b;
this.indexDisplay.update((b+1)+" / "+this.images.length)
}});
return a
}(XWiki||{}));
Element.observe(document,"dom:loaded",function(){$$(".gallery").each(function(a){new XWiki.Gallery(a)
})
});