var Zoomer=new Class({version:"1.8",Implements:[Options],options:{smooth:6,externalVar:true,borderLeft:50,borderRight:50,borderTop:40,borderBottom:10},initialize:function(b,a){this.setOptions(a);this.small=b;this.zoomActive=false;if(!this.small.complete){this.small.addEvent("load",function(){this.prepareSmall()}.bind(this))}else{this.prepareSmall()}var c=this.options.big||this.small.get("big");this.big=new Element("img",{src:c,styles:{position:"absolute",top:0,left:0,opacity:0,cursor:"crosshair"}});if(!this.big.complete){this.big.addEvent("load",function(){this.prepareBig()}.bind(this))}else{this.prepareBig()}},prepareSmall:function(){this.wrapper=new Element("div",{"class":"zoomer-wrapper"}).wraps(this.small);["margin","left","top","bottom","right","float","clear","border","padding"].each(function(d){var a=this.small.getStyle(d);var b="auto";if(["float","clear","border"].contains(d)){b="none"}if(d=="padding"){b="0"}try{this.small.setStyle(d,b);this.wrapper.setStyle(d,a)}catch(c){}},this);this.wrapper.setStyles({width:this.small.offsetWidth,height:this.small.offsetHeight,position:"relative",overflow:"hidden"});this.smallSize={width:this.small.width,height:this.small.height};if(this.bigPrepared){this.ready()}else{this.smallPrepared=true}},prepareBig:function(){this.bigSize={width:this.big.width,height:this.big.height};if(this.smallPrepared){this.ready()}else{this.bigPrepared=true}},ready:function(){this.big.inject(this.wrapper);this.bigWrapper=new Element("div",{"class":"zoomer-wrapper-big",styles:{position:"absolute",overflow:"hidden",top:this.small.getPosition().y-this.wrapper.getPosition().y-this.wrapper.getStyle("border-top-width").toInt(),left:this.small.getPosition().x-this.wrapper.getPosition().x-this.wrapper.getStyle("border-left-width").toInt(),width:this.small.offsetWidth,height:this.small.offsetHeight,background:"url(_)"},events:{mouseenter:this.handleMouseenter.bind(this)}}).wraps(this.big)},externalCheck:function(){if(eval(this.options.externalVar)){dbug.log("External: OK");return true}else{dbug.log("External: WAIT");$clear(this.zoomTimer);this.zoomTimer=(function(){if(eval(this.options.externalVar)){$clear(this.zoomTimer);this.handleMouseenter()}}).periodical(100,this);(function(){$clear(this.zoomTimer)}).delay(4000,this);return false}},handleMouseenter:function(){if(this.zoomActive){return}if(!this.externalCheck()){return}this.smallCoordinates=this.small.getCoordinates();window.removeEvents("mousemove");window.removeEvents("click");window.addEvents({mousemove:function(a){if(a.page.x<this.smallCoordinates.left-this.options.borderLeft||a.page.x>this.smallCoordinates.right+this.options.borderRight||a.page.y<this.smallCoordinates.top-this.options.borderTop||a.page.y>this.smallCoordinates.bottom+this.options.borderBottom){dbug.log("Mouse leave");this.stopZoom()}else{this.move(a)}}.bind(this),click:function(){dbug.log("Mouse click");this.stopZoom()}.bind(this)});this.startZoom()},move:function(a){this.dstPos=a.page},startZoom:function(){dbug.log("startZoom");this.position=this.small.getPosition();this.ratio={x:1-(this.bigSize.width)/this.smallSize.width,y:1-(this.bigSize.height)/this.smallSize.height};this.current={left:this.big.getStyle("left").toInt(),top:this.big.getStyle("top").toInt()};this.timer=this.zoom.periodical(10,this);this.big.fade("in")},stopZoom:function(){dbug.log("stopZoom");this.zoomActive=false;$clear(this.zoomTimer);$clear(this.timer);window.removeEvents("mousemove");window.removeEvents("click");this.big.fade("out")},zoom:function(){if(!this.dstPos){return}var a=this.options.smooth;var d=0;var b=0;if(this.dstPos.x>=this.smallCoordinates.left){if(this.dstPos.x>this.smallCoordinates.right){d=parseInt((this.smallCoordinates.right-this.position.x)*this.ratio.x)}else{d=parseInt((this.dstPos.x-this.position.x)*this.ratio.x)}}if(this.dstPos.y>=this.smallCoordinates.top){if(this.dstPos.y>this.smallCoordinates.bottom){b=parseInt((this.smallCoordinates.bottom-this.position.y)*this.ratio.y)}else{b=parseInt((this.dstPos.y-this.position.y)*this.ratio.y)}}var c={left:d,top:b};if(!this.zoomActive){this.current.left-=(this.current.left-c.left);this.current.top-=(this.current.top-c.top);this.zoomActive=true}this.current.left-=(this.current.left-c.left)/a;this.current.top-=(this.current.top-c.top)/a;this.big.setStyles(this.current)}});
