/*!
 * @name        easyzoom ( modified )
 * @author      Matt Hinchliffe <>
 * @modified    Tuesday, February 14th, 2017
 * @version     2.5.0
 */
!function(t,e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],function(t){e(t)}):"object"==typeof module&&module.exports?module.exports=t.EasyZoom=e(require("jquery")):t.EasyZoom=e(t.jQuery)}(this,function(t){"use strict";function e(e,o){this.$target=t(e),this.opts=t.extend({},r,o,this.$target.data()),void 0===this.isOpen&&this._init()}var o,i,s,h,n,a,r={linkAttribute:"data-zoom",preventClicks:!0,beforeShow:t.noop,beforeHide:t.noop,onShow:t.noop,onHide:t.noop,onMove:t.noop};e.prototype._init=function(){this.$link=this.$target,this.$image=this.$target.find("img"),this.$flyout=t('<div class="easyzoom-flyout" />'),this.$target.on({"mousemove.easyzoom touchmove.easyzoom":t.proxy(this._onMove,this),"mouseleave.easyzoom touchend.easyzoom":t.proxy(this._onLeave,this),"mouseenter.easyzoom touchstart.easyzoom":t.proxy(this._onEnter,this)}),this.opts.preventClicks&&this.$target.on("click.easyzoom",function(t){t.preventDefault()})},e.prototype.show=function(t,e){var n,a,r,p,u=this;if(!1!==this.opts.beforeShow.call(this)){if(!this.isReady)return this._loadImage(this.$link.attr(this.opts.linkAttribute),function(){!u.isMouseOver&&e||u.show(t)});this.$target.append(this.$flyout),n=this.$target.width(),a=this.$target.height(),r=this.$flyout.width(),p=this.$flyout.height(),o=this.$zoom.width()-r,i=this.$zoom.height()-p,o<0&&(o=0),i<0&&(i=0),s=o/n,h=i/a,this.isOpen=!0,this.opts.onShow.call(this),t&&this._move(t)}},e.prototype._onEnter=function(t){var e=t.originalEvent.touches;this.isMouseOver=!0,e&&1!=e.length||(t.preventDefault(),this.show(t,!0))},e.prototype._onMove=function(t){this.isOpen&&(t.preventDefault(),this._move(t))},e.prototype._onLeave=function(){this.isMouseOver=!1,this.isOpen&&this.hide()},e.prototype._onLoad=function(t){t.currentTarget.width&&(this.isReady=!0,this.$flyout.html(this.$zoom),t.data.call&&t.data())},e.prototype._loadImage=function(e,o){var i=new Image;this.$zoom=t(i).on("load",o,t.proxy(this._onLoad,this)),i.style.position="absolute",i.src=e},e.prototype._move=function(t){if(0===t.type.indexOf("touch")){var e=t.touches||t.originalEvent.touches;n=e[0].pageX,a=e[0].pageY}else n=t.pageX||n,a=t.pageY||a;var r=this.$target.offset(),p=a-r.top,u=n-r.left,l=Math.ceil(p*h),f=Math.ceil(u*s);if(f<0||l<0||f>o||l>i)this.hide();else{var c=-1*l,d=-1*f;this.$zoom.css({top:c,left:d}),this.opts.onMove.call(this,c,d)}},e.prototype.hide=function(){this.isOpen&&!1!==this.opts.beforeHide.call(this)&&(this.$flyout.detach(),this.isOpen=!1,this.opts.onHide.call(this))},e.prototype.swap=function(e,o,i){this.hide(),this.isReady=!1,this.$image.attr({src:e,srcset:t.isArray(i)?i.join():i}),this.$link.attr(this.opts.linkAttribute,o)},e.prototype.teardown=function(){this.hide(),this.$target.off(".easyzoom"),delete this.$link,delete this.$zoom,delete this.$image,delete this.$flyout,delete this.isOpen,delete this.isReady},t.fn.easyZoom=function(o){return this.each(function(){var i=t.data(this,"easyZoom");i?void 0===i.isOpen&&i._init():t.data(this,"easyZoom",new e(this,o))})}});