!function(n,t,i){"use strict";function e(n,t,i,r){return n/=r,n--,-i*(n*n*n*n-1)+t}function l(n){return n.complete&&("undefined"==typeof n.naturalWidth||0!==n.naturalWidth)}function f(n,t){this.container=n;this.onStart=t.onStart||o;this.onMove=t.onMove||o;this.onEnd=t.onEnd||o;this.sliderId=t.sliderId||"slider"+Math.ceil(1e6*Math.random())}function u(t,i){var r=this;t.is("#iv-container")&&(r._fullPage=!0);r.container=t;i=r.options=n.extend({},u.defaults,i);r.zoomValue=100;t.find(".snap-view").length||t.prepend(h);t.addClass("iv-container");"static"==t.css("position")&&t.css("position","relative");r.snapView=t.find(".iv-snap-view");r.snapImageWrap=t.find(".iv-snap-image-wrap");r.imageWrap=t.find(".iv-image-wrap");r.snapHandle=t.find(".iv-snap-handle");r.zoomHandle=t.find(".iv-zoom-handle");r._viewerId="iv"+Math.floor(1e6*Math.random())}var o=function(){},s=n("body"),c=n(t),r=n(i),a=15,v=5,h;!function(){for(var r=0,i=["ms","moz","webkit","o"],n=0;n<i.length&&!t.requestAnimationFrame;++n)t.requestAnimationFrame=t[i[n]+"RequestAnimationFrame"],t.cancelAnimationFrame=t[i[n]+"CancelAnimationFrame"]||t[i[n]+"CancelRequestAnimationFrame"];t.requestAnimationFrame||(t.requestAnimationFrame=function(n){var i=(new Date).getTime(),u=Math.max(0,16-(i-r)),f=t.setTimeout(function(){n(i+u)},u);return r=i+u,f});t.cancelAnimationFrame||(t.cancelAnimationFrame=function(n){clearTimeout(n)})}();h='<div class="iv-loader"><\/div> <div class="iv-snap-view"><div class="iv-snap-image-wrap"><div class="iv-snap-handle"><\/div><\/div><div class="iv-zoom-slider"><div class="iv-zoom-handle"><\/div><\/div><\/div><div class="iv-image-view" ><div class="iv-image-wrap" ><\/div><\/div>';n(function(){s.length||(s=n("body"));s.append('<div id="iv-container">'+h+'<div class="iv-close"><\/div><div>')});f.prototype.init=function(){var t=this,n=(this.container,"."+this.sliderId);return this.container.on("touchstart"+n+" mousedown"+n,function(i){var f,e;i.preventDefault();var o=("touchstart"==i.type?"touchmove":"mousemove")+n,s=("touchstart"==i.type?"touchend":"mouseup")+n,u=i.originalEvent,h=u.clientX||u.touches[0].clientX,c=u.clientY||u.touches[0].clientY,l=t.onStart(i,{x:h,y:c});l!==!1&&(f=function(n){n.preventDefault();u=n.originalEvent;var i=u.clientX||u.touches[0].clientX,r=u.clientY||u.touches[0].clientY;t.onMove(n,{dx:i-h,dy:r-c,mx:i,my:r})},e=function(){r.off(o,f);r.off(s,e);t.onEnd()},r.on(o,f),r.on(s,e))}),this};u.prototype={constructor:u,_init:function(){function y(t){u.snapView&&(l||n.zoomValue<=100||!n.loaded||(clearTimeout(it),l=!0,n.snapView.css("opacity",1),t||(it=setTimeout(function(){n.snapView.css("opacity",0);l=!1},4e3))))}var n=this,u=n.options,s=!1,p=this.container,t="."+n._viewerId,nt=this.snapHandle,b=this.snapImageWrap,h=this.imageWrap,i=new f(b,{sliderId:n._viewerId,onStart:function(){if(!n.loaded)return!1;var t=nt[0].style;this.curHandleTop=parseFloat(t.top);this.curHandleLeft=parseFloat(t.left);this.handleWidth=parseFloat(t.width);this.handleHeight=parseFloat(t.height);this.width=b.width();this.height=b.height();clearInterval(tt.slideMomentumCheck);cancelAnimationFrame(tt.sliderMomentumFrame)},onMove:function(t,i){var r=this.curHandleLeft+100*i.dx/this.width,u=this.curHandleTop+100*i.dy/this.height;r=Math.max(0,r);r=Math.min(100-this.handleWidth,r);u=Math.max(0,u);u=Math.min(100-this.handleHeight,u);var f=n.containerDim,e=n.imageDim.w*(n.zoomValue/100),o=n.imageDim.h*(n.zoomValue/100),s=e<f.w?(f.w-e)/2:-e*r/100,h=o<f.h?(f.h-o)/2:-o*u/100;nt.css({top:u+"%",left:r+"%"});n.currentImg.css({left:s,top:h})}}).init(),tt=n._imageSlider=new f(h,{sliderId:n._viewerId,onStart:function(t,r){if(!n.loaded)return!1;if(!s){var u=this;i.onStart();u.imgWidth=n.imageDim.w*n.zoomValue/100;u.imgHeight=n.imageDim.h*n.zoomValue/100;u.positions=[r,r];u.startPosition=r;n._clearFrames();u.slideMomentumCheck=setInterval(function(){u.currentPos&&(u.positions.shift(),u.positions.push({x:u.currentPos.mx,y:u.currentPos.my}))},50)}},onMove:function(n,t){s||(this.currentPos=t,i.onMove(n,{dx:-t.dx*i.width/this.imgWidth,dy:-t.dy*i.height/this.imgHeight}))},onEnd:function(){function f(){60>=t&&(n.sliderMomentumFrame=requestAnimationFrame(f));o+=e(t,r/3,-r/3,60);h+=e(t,u/3,-u/3,60);i.onMove(null,{dx:-(o*i.width/n.imgWidth),dy:-(h*i.height/n.imgHeight)});t++}if(!s){var n=this,r=this.positions[1].x-this.positions[0].x,u=this.positions[1].y-this.positions[0].y;if(Math.abs(r)>30||Math.abs(u)>30){var t=1,o=n.currentPos.dx,h=n.currentPos.dy;f()}}}}).init(),k=0,d,o,it,l,g,w;h.on("mousewheel"+t+" DOMMouseScroll"+t,function(t){var r,i;if(u.zoomOnMouseWheel&&n.loaded&&(n._clearFrames(),r=Math.max(-1,Math.min(1,t.originalEvent.wheelDelta||-t.originalEvent.detail)),i=n.zoomValue*(100+r*a)/100,i>=100&&i<=u.maxZoom?k=0:k+=Math.abs(r),!(k>v))){t.preventDefault();var f=p.offset(),e=(t.pageX||t.originalEvent.pageX)-f.left,o=(t.pageY||t.originalEvent.pageY)-f.top;n.zoom(i,{x:e,y:o});y()}});h.on("touchstart"+t,function(t){var i,u;if(n.loaded&&(i=t.originalEvent.touches[0],u=t.originalEvent.touches[1],i&&u)){s=!0;var f=p.offset(),h=Math.sqrt(Math.pow(u.pageX-i.pageX,2)+Math.pow(u.pageY-i.pageY,2)),c=n.zoomValue,l={x:(u.pageX+i.pageX)/2-f.left,y:(u.pageY+i.pageY)/2-f.top},e=function(t){t.preventDefault();var i=t.originalEvent.touches[0],r=t.originalEvent.touches[1],u=Math.sqrt(Math.pow(r.pageX-i.pageX,2)+Math.pow(r.pageY-i.pageY,2)),f=c+(u-h)/2;n.zoom(f,l)},o=function(){r.off("touchmove",e);r.off("touchend",o);s=!1};r.on("touchmove",e);r.on("touchend",o)}});o=0;h.on("click"+t,function(t){0==o?(o=Date.now(),d={x:t.pageX,y:t.pageY}):Date.now()-o<500&&Math.abs(t.pageX-d.x)<50&&Math.abs(t.pageY-d.y)<50?(n.zoomValue==u.zoomValue?n.zoom(200):n.resetZoom(),o=0):o=0});g=n.snapView.find(".iv-zoom-slider");new f(g,{sliderId:n._viewerId,onStart:function(t){return n.loaded?(this.leftOffset=g.offset().left,this.handleWidth=n.zoomHandle.width(),void this.onMove(t)):!1},onMove:function(t){var i=(t.pageX||t.originalEvent.touches[0].pageX)-this.leftOffset-this.handleWidth/2,r;i=Math.max(0,i);i=Math.min(n._zoomSliderLength,i);r=100+(u.maxZoom-100)*i/n._zoomSliderLength;n.zoom(r)}}).init();h.on("touchmove"+t+" mousemove"+t,function(){y()});w={};w["mouseenter"+t+" touchstart"+t]=function(){l=!1;y(!0)};w["mouseleave"+t+" touchend"+t]=function(){l=!1;y()};n.snapView.on(w);u.refreshOnResize&&c.on("resize"+t,function(){n.refresh()});n._fullPage&&(p.on("touchmove"+t+" mousewheel"+t+" DOMMouseScroll"+t,function(n){n.preventDefault()}),p.find(".iv-close").on("click"+t,function(){n.hide()}))},zoom:function(n,t){function s(){o++;20>o&&(i._zoomFrame=requestAnimationFrame(s));var b=e(o,u,n-u,20),g=b/u,k=i.imageDim.w*b/100,d=i.imageDim.h*b/100,r=-((t.x-p)*g-t.x),h=-((t.y-w)*g-t.y);r=Math.min(r,c);h=Math.min(h,l);a>r+k&&(r=a-k);v>h+d&&(h=v-d);f.css({height:d+"px",width:k+"px",left:r+"px",top:h+"px"});i.zoomValue=b;i._resizeHandle(k,d,r,h);i.zoomHandle.css("left",(b-100)*i._zoomSliderLength/(y-100)+"px")}n=Math.round(Math.max(100,n));n=Math.min(this.options.maxZoom,n);t=t||{x:this.containerDim.w/2,y:this.containerDim.h/2};var i=this,y=this.options.maxZoom,u=this.zoomValue,f=this.currentImg,r=this.containerDim,p=parseFloat(f.css("left")),w=parseFloat(f.css("top"));i._clearFrames();var o=0,r=i.containerDim,h=i.imageDim,c=(r.w-h.w)/2,l=(r.h-h.h)/2,a=r.w-c,v=r.h-l;s()},_clearFrames:function(){clearInterval(this._imageSlider.slideMomentumCheck);cancelAnimationFrame(this._imageSlider.sliderMomentumFrame);cancelAnimationFrame(this._zoomFrame)},resetZoom:function(){this.zoom(this.options.zoomValue)},_calculateDimensions:function(){var n=this,e=n.currentImg,c=n.container,l=n.snapView,a=e.width(),v=e.height(),r=c.width(),u=c.height(),o=l.innerWidth(),y=l.innerHeight(),t,i,f,s,h;n.containerDim={w:r,h:u};f=a/v;t=a>v&&u>=r||f*u>r?r:f*u;i=t/f;n.imageDim={w:t,h:i};e.css({width:t+"px",height:i+"px",left:(r-t)/2+"px",top:(u-i)/2+"px","max-width":"none","max-height":"none"});s=t>i?o:t*y/i;h=i>t?y:i*o/t;n.snapImageDim={w:s,h:h};n.snapImg.css({width:s,height:h});n._zoomSliderLength=o-n.zoomHandle.outerWidth()},refresh:function(){this.loaded&&(this._calculateDimensions(),this.resetZoom())},_resizeHandle:function(n,t,i,r){var u=this.currentImg,f=n||this.imageDim.w*this.zoomValue/100,e=t||this.imageDim.h*this.zoomValue/100,o=Math.max(100*-(i||parseFloat(u.css("left")))/f,0),s=Math.max(100*-(r||parseFloat(u.css("top")))/e,0),h=Math.min(100*this.containerDim.w/f,100),c=Math.min(100*this.containerDim.h/e,100);this.snapHandle.css({top:s+"%",left:o+"%",width:h+"%",height:c+"%"})},show:function(n,t){this._fullPage&&(this.container.show(),n&&this.load(n,t))},hide:function(){this._fullPage&&this.container.hide()},options:function(n,t){return t?void(this.options[n]=t):this.options[n]},destroy:function(){var n="."+this._viewerId;return this._fullPage?(container.off(n),container.find('[class^="iv"]').off(n)):this.container.remove('[class^="iv"]'),c.off(n),null},load:function(t,i){function e(){r.loaded=!0;r.zoomValue=100;u.show();r.snapImg.show();r.refresh();r.resetZoom();f.find(".iv-loader").hide()}var r=this,f=this.container,o,u;f.find(".iv-snap-image,.iv-large-image").remove();o=this.container.find(".iv-snap-image-wrap");o.prepend('<img class="iv-snap-image" src="'+t+'" />');this.imageWrap.prepend('<img class="iv-large-image" src="'+t+'" />');i&&this.imageWrap.append('<img class="iv-large-image" src="'+i+'" />');u=this.currentImg=this.container.find(".iv-large-image");this.snapImg=this.container.find(".iv-snap-image");r.loaded=!1;f.find(".iv-loader").show();u.hide();r.snapImg.hide();l(u[0])?e():n(u[0]).on("load",e)}};u.defaults={zoomValue:100,snapView:!0,maxZoom:500,refreshOnResize:!0,zoomOnMouseWheel:!0};t.ImageViewer=function(t,i){var r,f,o,e;return t&&("string"==typeof t||t instanceof Element||t[0]instanceof Element)||(i=t,t=n("#iv-container")),t=n(t),t.is("img")?(r=t,f=r[0].src,o=r.attr("high-res-src")||r.attr("data-high-res-src"),t=r.wrap('<div class="iv-container" style="display:inline-block; overflow:hidden"><\/div>').parent(),r.css({opacity:0,position:"relative",zIndex:-1})):(f=t.attr("src")||t.attr("data-src"),o=t.attr("high-res-src")||t.attr("data-high-res-src")),e=new u(t,i),e._init(),f&&e.load(f,o),e};n.fn.ImageViewer=function(i){return this.each(function(){var r=n(this),u=t.ImageViewer(r,i);r.data("ImageViewer",u)})}}(window.jQuery,window,document)