(function($){var defaults={zoom:.1};var wheel;function setSrcToBackground(img){var transparentPNG="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==";img.width=img.width;img.height=img.height;img.style.backgroundImage="url("+img.src+")";img.style.backgroundRepeat="no-repeat";img.src=transparentPNG}if(document.onmousewheel!==undefined){wheel="onmousewheel"}else if(document.onwheel!==undefined){wheel="onwheel"}$.fn.wheelzoom=function(options){var settings=$.extend({},defaults,options);if(!this[0]||!wheel||!("backgroundSize"in this[0].style)){return this}return this.each(function(){var img=this,$img=$(img);function loaded(){var width=$img.width(),height=$img.height(),innerWidth=$img.innerWidth(),innerHeight=$img.innerHeight(),PosX=(innerWidth-width)/2,PosY=(innerHeight-height)/2,bgWidth=width,bgHeight=height,bgPosX=PosX,bgPosY=PosY;function reset(){bgWidth=width;bgHeight=height;bgPosX=PosX;bgPosY=PosY;updateBgStyle()}function updateBgStyle(){if(bgPosX>PosX){bgPosX=PosX}else if(bgPosX<width+PosX-bgWidth){bgPosX=width+PosX-bgWidth}if(bgPosY>PosY){bgPosY=PosY}else if(bgPosY<height+PosY-bgHeight){bgPosY=height+PosY-bgHeight}img.style.backgroundSize=bgWidth+"px "+bgHeight+"px";img.style.backgroundPosition=bgPosX+"px "+bgPosY+"px"}setSrcToBackground(img);$img.css({backgroundSize:width+"px "+height+"px",backgroundPosition:PosX+"px "+PosY+"px"}).bind("wheelzoom.reset",reset);img[wheel]=function(e){var deltaY=0;e.preventDefault();if(e.deltaY){deltaY=e.deltaY}else if(e.wheelDelta){deltaY=-e.wheelDelta}var offsetParent=$img.offset();var offsetX=e.pageX-offsetParent.left;var offsetY=e.pageY-offsetParent.top;var bgCursorX=offsetX-bgPosX;var bgCursorY=offsetY-bgPosY;var bgRatioX=bgCursorX/bgWidth;var bgRatioY=bgCursorY/bgHeight;if(deltaY<0){bgWidth+=bgWidth*settings.zoom;bgHeight+=bgHeight*settings.zoom}else{bgWidth-=bgWidth*settings.zoom;bgHeight-=bgHeight*settings.zoom}bgPosX=offsetX-bgWidth*bgRatioX;bgPosY=offsetY-bgHeight*bgRatioY;if(bgWidth<=width||bgHeight<=height){reset()}else{updateBgStyle()}};img.onmousedown=function(e){var last=e;e.preventDefault();function drag(e){e.preventDefault();bgPosX+=e.pageX-last.pageX;bgPosY+=e.pageY-last.pageY;last=e;updateBgStyle()}$(document).on("mousemove",drag).one("mouseup",function(){$(document).unbind("mousemove",drag)})}}if(img.complete){loaded()}else{$img.one("load",loaded)}})};$.fn.wheelzoom.defaults=defaults})(window.jQuery);