var MooZoom=new Class({Implements:Options,elements:null,options:{linkSelector:"a",imageSelector:"img",imageRoot:"/images/",transition:Fx.Transitions.linear.easeOut,duration:250,close:"top-left"},initialize:function(options){this.setOptions(options);if(this.options.imageRoot[this.options.imageRoot.length-1]!="/")
this.options.imageRoot+="/";this.elements=document.getElements(this.options.linkSelector);this.elements.each(function(a){a.getElements(this.options.imageSelector).each(function(img){this.setupImage(a,img);}.bind(this));}.bind(this));},setupImage:function(a,img){var href=a.getProperty("href");a.setProperty("href",null);a.setStyle("cursor","pointer");var container=new Element("img",{src:href,styles:{"opacity":0,"top":-99999,"left":-99999,"position":"absolute","cursor":"pointer","border":"1px solid #000"}}).inject(document.body);if(this.options.close){var close=new Element("img",{src:this.options.imageRoot+"/moozoom_close.png",styles:{"opacity":0,"top":-99999,"left":-99999,"position":"absolute","cursor":"pointer"}}).inject(document.body);}
var bigCoords=null;var smallCoords=null;a.addEvent("click",function(e){if(!bigCoords)bigCoords={width:container.width,height:container.height};if(!smallCoords)smallCoords=img.getCoordinates();var startWidth=(smallCoords.width/bigCoords.width)*bigCoords.width;var startHeight=(smallCoords.height/bigCoords.height)*bigCoords.height;var bodyElem=$$('body')[0];var endTop=bodyElem.getScroll().y+(bodyElem.getHeight()-bigCoords.height)/2;var endLeft=bodyElem.getScroll().x+(bodyElem.getWidth()-bigCoords.width)/2;if(this.options.close){var closeTop=endTop-10;var closeLeft=endLeft-10;switch(this.options.close){case"bottom-right":closeTop=endTop+bigCoords.height-14;closeLeft=endLeft+bigCoords.width-14;break;case"bottom-left":closeTop=endTop+bigCoords.height-14;break;case"top-right":closeLeft=endLeft+bigCoords.width-14;break;}
close.setStyles({"top":smallCoords.top,"left":smallCoords.left,"opacity":0,"width":1,"height":1});new Fx.Morph(close,{transition:this.options.transition,duration:this.options.duration}).start({height:24,width:24,opacity:1,top:closeTop,left:closeLeft});}
container.setStyles({"position":"absolute","top":smallCoords.top,"left":smallCoords.left,"opacity":0,"width":startWidth,"height":startHeight});new Fx.Morph(container,{transition:this.options.transition,duration:this.options.duration,onComplete:function(e){container.setStyles({"-moz-box-shadow":"0px 2px 15px #000","-webkit-box-shadow":"0px 2px 15px #000"});}.bind(this)}).start({height:bigCoords.height,width:bigCoords.width,opacity:1,top:endTop,left:endLeft});}.bind(this));var closeEvent=function(e){if(!bigCoords)bigCoords={width:container.width,height:container.height};if(!smallCoords)smallCoords=img.getCoordinates();var endWidth=(smallCoords.width/bigCoords.width)*bigCoords.width;var endHeight=(smallCoords.height/bigCoords.height)*bigCoords.height;container.setStyles({"-moz-box-shadow":"none","-webkit-box-shadow":"none"});if(this.options.close){new Fx.Morph(close,{transition:this.options.transition,duration:this.options.duration,onComplete:function(){close.setStyles({"top":-99999,"left":-99999});}}).start({width:1,height:1,opacity:0,top:smallCoords.top,left:smallCoords.left});}
new Fx.Morph(container,{transition:this.options.transition,duration:this.options.duration,onComplete:function(){container.setStyles({"top":-99999,"left":-99999});}}).start({width:endWidth,height:endHeight,opacity:0,top:smallCoords.top,left:smallCoords.left});e.stopPropagation();}.bind(this);container.addEvent("click",closeEvent);if(this.options.close){close.addEvent("click",closeEvent);}}});