(function(e,g){var b=e.document,c={transform3d:("WebKitCSSMatrix" in e&&"m11" in new WebKitCSSMatrix()),touch:("ontouchstart" in e)};function d(i,k){var j=i,h=k;return c.transform3d?"translate3d("+j+"px, "+h+"px, 0)":"translate("+j+"px, "+h+"px)"}function a(h,i){return c.touch?h.changedTouches[0][i]:h[i]}var f=function(){};f.prototype={init:function(o){var i=this,n=o||{};var m=b.querySelectorAll(n.elem+" img"),l=b.querySelector("#zoomtu"),h=b.querySelector("#scroller img"),k=b.querySelector("#zoomtu"),j="";i.buffMove=3;i.buffScale=2;i.finger=false;i._destroy();h.onload=function(){b.addEventListener("touchmove",i.eventStop,false);i.imgBaseWidth=h.offsetWidth;i.imgBaseHeight=h.offsetHeight;i.addEventStart({wrapX:l.offsetWidth,wrapY:l.offsetHeight,mapX:h.width,mapY:h.height})};k.addEventListener("click",function(){i._destroy();b.removeEventListener("touchmove",i.eventStop,false)},false)},addEventStart:function(j){var h=this,i=j||{};h.element=b.querySelector("#scroller img");h.wrapX=i.wrapX||0;h.wrapY=i.wrapY||0;h.mapX=i.mapX||0;h.mapY=i.mapY||0;h.outDistY=(h.mapY-h.wrapY)/2;h.width=h.mapX-h.wrapX;h.height=h.mapY-h.wrapY;h.element.addEventListener("touchstart",function(k){h._touchstart(k)},false);h.element.addEventListener("touchmove",function(k){h._touchmove(k)},false);h.element.addEventListener("touchend",function(k){h._touchend(k)},false)},_destroy:function(){this.distX=0;this.distY=0;this.newX=0;this.newY=0},_changeData:function(){this.mapX=this.element.offsetWidth;this.mapY=this.element.offsetHeight;this.width=this.mapX-this.wrapX;this.height=this.mapY-this.wrapY},_touchstart:function(i){var h=this;var j=i.targetTouches.length;h._changeData();if(j==1){h.basePageX=a(i,"pageX");h.basePageY=a(i,"pageY");h.finger=false}else{h.finger=true;h.startFingerDist=h.getTouchDist(i).dist;h.startFingerX=h.getTouchDist(i).x;h.startFingerY=h.getTouchDist(i).y}},_touchmove:function(i){var h=this;var j=i.targetTouches.length;if(j==1&&!h.finger){h._move(i)}if(j>=2){h._zoom(i)}},_touchend:function(i){var h=this;h._changeData();if(h.finger){h.distX=-h.imgNewX;h.distY=-h.imgNewY}if(h.distX>0){h.newX=0}else{if(h.distX<=0&&h.distX>=-h.width){h.newX=h.distX;h.newY=h.distY}else{if(h.distX<-h.width){h.newX=-h.width}}}h.reset()},_move:function(k){var h=this,j=a(k,"pageX"),i=a(k,"pageY");h.distX=(j-h.basePageX)+h.newX;h.distY=(i-h.basePageY)+h.newY;if(h.distX>0){h.moveX=Math.round(h.distX/h.buffMove)}else{if(h.distX<=0&&h.distX>=-h.width){h.moveX=h.distX}else{if(h.distX<-h.width){h.moveX=-h.width+Math.round((h.distX+h.width)/h.buffMove)}}}h.movePos();h.finger=false},_zoom:function(l){var j=this;l.preventDefault();l.stopPropagation();var m=j.getTouchDist(l).dist,k=m/j.startFingerDist,i=Math.round(j.mapX*k),h=Math.round(j.mapY*k);j.imgNewX=Math.round(j.startFingerX*k-j.startFingerX-j.newX*k);j.imgNewY=Math.round((j.startFingerY*k-j.startFingerY)/2-j.newY*k);if(i>=j.imgBaseWidth){j.element.style.width=i+"px";j.refresh(-j.imgNewX,-j.imgNewY,"0s","ease");j.finger=true}else{if(i<j.imgBaseWidth){j.element.style.width=j.imgBaseWidth+"px"}}j.finger=true},movePos:function(){var j=this;if(j.height<0){if(j.element.offsetWidth==j.imgBaseWidth){j.moveY=Math.round(j.distY/j.buffMove)}else{var k=Math.round((j.element.offsetHeight-j.imgBaseHeight)/2);j.moveY=-k+Math.round((j.distY+k)/j.buffMove)}}else{var i=Math.round((j.wrapY-j.imgBaseHeight)/2),h=j.element.offsetHeight-j.wrapY+Math.round(j.wrapY-j.imgBaseHeight)/2;if(j.distY>=-i){j.moveY=Math.round((j.distY+i)/j.buffMove)-i}else{if(j.distY<=-h){j.moveY=Math.round((j.distY+h)/j.buffMove)-h}else{j.moveY=j.distY}}}j.refresh(j.moveX,j.moveY,"0s","ease")},reset:function(){var k=this,j=".2s";if(k.height<0){k.newY=-Math.round(k.element.offsetHeight-k.imgBaseHeight)/2}else{var i=Math.round((k.wrapY-k.imgBaseHeight)/2),h=k.element.offsetHeight-k.wrapY+Math.round(k.wrapY-k.imgBaseHeight)/2;if(k.distY>=-i){k.newY=-i}else{if(k.distY<=-h){k.newY=-h}else{k.newY=k.distY}}}k.refresh(k.newX,k.newY,j,"ease-in-out")},refresh:function(h,k,j,i){this.element.style.webkitTransitionProperty="-webkit-transform";this.element.style.webkitTransitionDuration=j;this.element.style.webkitTransitionTimingFunction=i;this.element.style.webkitTransform=d(h,k)},getTouchDist:function(o){var l=0,n=0,j=0,m=0,i=0,k=0,h={};l=o.touches[0].pageX;j=o.touches[1].pageX;n=o.touches[0].pageY-b.body.scrollTop;m=o.touches[1].pageY-b.body.scrollTop;if(!l||!j){return}if(l<=j){i=(j-l)/2+l}else{i=(l-j)/2+j}if(n<=m){k=(m-n)/2+n}else{k=(n-m)/2+m}h={dist:Math.round(Math.sqrt(Math.pow(l-j,2)+Math.pow(n-m,2))),x:Math.round(i),y:Math.round(k)};return h},eventStop:function(h){h.preventDefault();h.stopPropagation()}};e.ImagesZoom=new f()})(this);