!function(e){e.Jcrop=function(t,n){function o(e){return Math.round(e)+"px"}function r(e){return M.baseClass+"-"+e}function a(){return e.fx.step.hasOwnProperty("backgroundColor")}function i(t){var n=e(t).offset();return[n.left,n.top]}function s(e){return[e.pageX-z[0],e.pageY-z[1]]}function c(t){"object"!=typeof t&&(t={}),M=e.extend(M,t),e.each(["onChange","onSelect","onRelease","onDblClick"],(function(e,t){"function"!=typeof M[t]&&(M[t]=function(){})}))}function u(e,t,n){if(z=i(P),re.setCursor("move"===e?e:e+"-resize"),"move"===e)return re.activateHandlers(function(e){var t=e;return ae.watchKeys(),function(e){te.moveOffset([e[0]-t[0],e[1]-t[1]]),t=e,oe.update()}}(t),g,n);var o=te.getFixed(),r=l(e),a=te.getCorner(l(r));te.setPressed(te.getCorner(r)),te.setCurrent(a),re.activateHandlers(d(e,o),g,n)}function d(e,t){return function(n){if(M.aspectRatio)switch(e){case"e":case"w":n[1]=t.y+1;break;case"n":case"s":n[0]=t.x+1}else switch(e){case"e":case"w":n[1]=t.y2;break;case"n":case"s":n[0]=t.x2}te.setCurrent(n),oe.update()}}function l(e){switch(e){case"n":case"ne":return"sw";case"s":case"e":case"se":return"nw";case"w":case"sw":return"ne";case"nw":return"se"}}function h(e){return function(t){return!(M.disabled||"move"===e&&!M.allowMove||(z=i(P),V=!0,u(e,s(t)),t.stopPropagation(),t.preventDefault(),1))}}function f(e,t,n){var o=e.width(),r=e.height();o>t&&t>0&&(o=t,r=t/e.width()*e.height()),r>n&&n>0&&(r=n,o=n/e.height()*e.width()),G=e.width()/o,N=e.height()/r,e.width(o).height(r)}function p(e){return{x:e.x*G,y:e.y*N,x2:e.x2*G,y2:e.y2*N,w:e.w*G,h:e.h*N}}function g(e){var t=te.getFixed();t.w>M.minSelect[0]&&t.h>M.minSelect[1]?(oe.enableHandles(),oe.done()):oe.release(),re.setCursor(M.allowSelect?"crosshair":"default")}function b(e){if(M.disabled)return!1;if(!M.allowSelect)return!1;V=!0,z=i(P),oe.disableHandles(),re.setCursor("crosshair");var t=s(e);return te.setPressed(t),oe.update(),re.activateHandlers(w,g,"touch"===e.type.substring(0,5)),ae.watchKeys(),e.stopPropagation(),e.preventDefault(),!1}function w(e){te.setCurrent(e),oe.update()}function v(){var t=e("
").addClass(r("tracker"));return j&&t.css({opacity:0,backgroundColor:"white"}),t}function y(e){m([e[0]/G,e[1]/N,e[2]/G,e[3]/N]),M.onSelect.call(ie,p(te.getFixed())),oe.enableHandles()}function m(e){te.setPressed([e[0],e[1]]),te.setCurrent([e[2],e[3]]),oe.update()}function C(){M.disabled=!0,oe.disableHandles(),oe.setCursor("default"),re.setCursor("default")}function x(){M.disabled=!1,k()}function S(e,t,n){var o=t||M.bgColor;M.bgFade&&a()&&M.fadeTime&&!n?e.animate({backgroundColor:o},{queue:!1,duration:M.fadeTime}):e.css("backgroundColor",o)}function k(e){M.allowResize?e?oe.enableOnly():oe.enableHandles():oe.disableHandles(),re.setCursor(M.allowSelect?"crosshair":"default"),oe.setCursor(M.allowMove?"move":"default"),M.hasOwnProperty("trueSize")&&(G=M.trueSize[0]/J,N=M.trueSize[1]/A),M.hasOwnProperty("setSelect")&&(y(M.setSelect),oe.done(),delete M.setSelect),ne.refresh(),M.bgColor!=$&&(S(M.shade?ne.getShades():R,M.shade&&M.shadeColor||M.bgColor),$=M.bgColor),_!=M.bgOpacity&&(_=M.bgOpacity,M.shade?ne.refresh():oe.setBgOpacity(_)),Y=M.maxSize[0]||0,q=M.maxSize[1]||0,L=M.minSize[0]||0,X=M.minSize[1]||0,M.hasOwnProperty("outerImage")&&(P.attr("src",M.outerImage),delete M.outerImage),oe.refresh()}var z,M=e.extend({},e.Jcrop.defaults),O=navigator.userAgent.toLowerCase(),j=/msie/.test(O),F=/msie [1-6]\./.test(O);"object"!=typeof t&&(t=e(t)[0]),"object"!=typeof n&&(n={}),c(n);var H={border:"none",visibility:"visible",margin:0,padding:0,position:"absolute",top:0,left:0},D=e(t),I=!0;if("IMG"==t.tagName){if(0!=D[0].width&&0!=D[0].height)D.width(D[0].width),D.height(D[0].height);else{var B=new Image;B.src=D[0].src,D.width(B.width),D.height(B.height)}var P=D.clone().removeAttr("id").css(H).show();P.width(D.width()),P.height(D.height()),D.after(P).hide()}else P=D.css(H).show(),I=!1,null===M.shade&&(M.shade=!0);f(P,M.boxWidth,M.boxHeight);var J=P.width(),A=P.height(),R=e("
").width(J).height(A).addClass(r("holder")).css({position:"relative",backgroundColor:M.bgColor}).insertAfter(D).append(P);M.addClass&&R.addClass(M.addClass);var T=e("
"),K=e("
").width("100%").height("100%").css({zIndex:310,position:"absolute",overflow:"hidden"}),E=e("
").width("100%").height("100%").css("zIndex",320),W=e("
").css({position:"absolute",zIndex:600}).on("dblclick",(function(){var e=te.getFixed();M.onDblClick.call(ie,e)})).insertBefore(P).append(K,E);I&&(T=e("").attr("src",P.attr("src")).css(H).width(J).height(A),K.append(T)),F&&W.css({overflowY:"hidden"});var Y,q,L,X,G,N,V,Q,U=M.boundary,Z=v().width(J+2*U).height(A+2*U).css({position:"absolute",top:o(-U),left:o(-U),zIndex:290}).on("mousedown",b),$=M.bgColor,_=M.bgOpacity;z=i(P);var ee=function(){function e(){var e,t={},n=["touchstart","touchmove","touchend"],o=document.createElement("div");try{for(e=0;eY&&(c=t>0?i+Y:i-Y),q&&Math.abs(r)>q&&(u=r>0?s+q:s-q),X/N&&Math.abs(r)0?s+X/N:s-X/N),L/G&&Math.abs(t)0?i+L/G:i-L/G),i<0&&(c-=i,i-=i),s<0&&(u-=s,s-=s),c<0&&(i-=c,c-=c),u<0&&(s-=u,u-=u),c>J&&(i-=e=c-J,c-=e),u>A&&(s-=e=u-A,u-=e),i>J&&(u-=e=i-A,s-=e),s>A&&(u-=e=s-A,s-=e),o(n(i,s,c,u))}();var e,t,r,a,d=M.aspectRatio,l=M.minSize[0]/G,h=M.maxSize[0]/G,f=M.maxSize[1]/N,p=c-i,g=u-s,b=Math.abs(p),w=Math.abs(g);return 0===h&&(h=10*J),0===f&&(f=10*A),b/wJ&&(e=J,a=Math.abs((e-i)/d),t=g<0?s-a:a+s)):(e=c,a=b/d,(t=g<0?s-a:s+a)<0?(t=0,r=Math.abs((t-s)*d),e=p<0?i-r:r+i):t>A&&(t=A,r=Math.abs(t-s)*d,e=p<0?i-r:r+i)),e>i?(e-ih&&(e=i+h),t=t>s?s+(e-i)/d:s-(e-i)/d):eh&&(e=i-h),t=t>s?s+(i-e)/d:s-(i-e)/d),e<0?(i-=e,e=0):e>J&&(i-=e-J,e=J),t<0?(s-=t,t=0):t>A&&(s-=t-A,t=A),o(n(i,s,e,t))}function t(e){return e[0]<0&&(e[0]=0),e[1]<0&&(e[1]=0),e[0]>J&&(e[0]=J),e[1]>A&&(e[1]=A),[Math.round(e[0]),Math.round(e[1])]}function n(e,t,n,o){var r=e,a=n,i=t,s=o;return ni+t&&(t-=t+i),0>s+n&&(n-=n+s),A").css({position:"absolute",backgroundColor:M.shadeColor||M.bgColor}).appendTo(l)}function a(){d||(d=!0,l.insertBefore(P),t(),oe.setBgOpacity(1,0,1),T.hide(),i(M.shadeColor||M.bgColor,1),oe.isAwake()?c(M.bgOpacity,1):c(1,1))}function i(e,t){S(u(),e,t)}function s(){d&&(l.remove(),T.show(),d=!1,oe.isAwake()?oe.setBgOpacity(M.bgOpacity,1,1):(oe.setBgOpacity(1,1,1),oe.disableHandles()),S(R,0,1))}function c(e,t){d&&(M.bgFade&&!t?l.animate({opacity:1-e},{queue:!1,duration:M.fadeTime}):l.css({opacity:1-e}))}function u(){return l.children()}var d=!1,l=e("
").css({position:"absolute",zIndex:240,opacity:0}),h={top:r(),left:r().height(A),right:r().height(A),bottom:r()};return{update:t,updateRaw:n,getShades:u,setBgColor:i,enable:a,disable:s,resize:function(e,t){h.left.css({height:o(t)}),h.right.css({height:o(t)})},refresh:function(){M.shade?a():s(),oe.isAwake()&&c(M.bgOpacity)},opacity:c}}(),oe=function(){function t(t){var n=e("
").css({position:"absolute",opacity:M.borderOpacity}).addClass(r(t));return K.append(n),n}function n(t,n){var o=e("
").on("mousedown",h(t)).css({cursor:t+"-resize",position:"absolute",zIndex:n}).addClass("ord-"+t);return ee.support&&o.on("touchstart.jcrop",ee.createDragger(t)),E.append(o),o}function a(e){var t=M.handleSize,o=n(e,w++).css({opacity:M.handleOpacity}).addClass(r("handle"));return t&&o.width(t).height(t),o}function i(e){return n(e,w++).addClass("jcrop-dragbar")}function s(){var e=te.getFixed();te.setPressed([e.x,e.y]),te.setCurrent([e.x2,e.y2]),c()}function c(e){if(b)return u(e)}function u(e){var t=te.getFixed();(function(e,t){W.width(Math.round(e)).height(Math.round(t))})(t.w,t.h),function(e,t){M.shade||T.css({top:o(-t),left:o(-e)}),W.css({top:o(t),left:o(e)})}(t.x,t.y),M.shade&&ne.updateRaw(t),b||(W.show(),M.shade?ne.opacity(_):d(_,!0),b=!0),e?M.onSelect.call(ie,p(t)):M.onChange.call(ie,p(t))}function d(e,t,n){(b||t)&&(M.bgFade&&!n?P.animate({opacity:e},{queue:!1,duration:M.fadeTime}):P.css("opacity",e))}function l(){if(x=!0,M.allowResize)return E.show(),!0}function f(){x=!1,E.hide()}function g(e){e?(Q=!0,f()):(Q=!1,l())}var b,w=370,y={},m={},C={},x=!1;M.dragEdges&&e.isArray(M.createDragbars)&&function(e){var t;for(t=0;t').css({position:"fixed",left:"-120px",width:"12px"}).addClass("jcrop-keymgr"),o=e("
").css({position:"absolute",overflow:"hidden"}).append(n);return M.keySupport&&(n.on("keydown",(function(e){if(e.ctrlKey||e.metaKey)return!0;var n=e.shiftKey?10:1;switch(e.keyCode){case 37:t(e,-n,0);break;case 39:t(e,n,0);break;case 38:t(e,0,-n);break;case 40:t(e,0,n);break;case 27:M.allowSelect&&oe.release();break;case 9:return!0}return!1})).on("blur",(function(e){n.hide()})),F||!M.fixedSupport?(n.css({position:"absolute",left:"-20px"}),o.append(n).insertBefore(P)):n.insertBefore(P)),{watchKeys:function(){M.keySupport&&(n.show(),n.trigger("focus"))}}}();ee.support&&Z.on("touchstart.jcrop",ee.newSelection),E.hide(),k(!0);var ie={setImage:function(e,t){oe.release(),C();var n=new Image;n.onload=function(){var o=n.width,r=n.height,a=M.boxWidth,i=M.boxHeight;P.width(o).height(r),P.attr("src",e),T.attr("src",e),f(P,a,i),J=P.width(),A=P.height(),T.width(J).height(A),Z.width(J+2*U).height(A+2*U),R.width(J).height(A),ne.resize(J,A),x(),"function"==typeof t&&t.call(ie)},n.src=e},animateTo:function(e,t){function n(){window.setTimeout(v,l)}var o=e[0]/G,r=e[1]/N,a=e[2]/G,i=e[3]/N;if(!Q){var s=te.flipCoords(o,r,a,i),c=te.getFixed(),u=[c.x,c.y,c.x2,c.y2],d=u,l=M.animationDelay,h=s[0]-u[0],f=s[1]-u[1],p=s[2]-u[2],g=s[3]-u[3],b=0,w=M.swingSpeed;o=d[0],r=d[1],a=d[2],i=d[3],oe.animMode(!0);var v=function(){b+=(100-b)/w,d[0]=Math.round(o+b/100*h),d[1]=Math.round(r+b/100*f),d[2]=Math.round(a+b/100*p),d[3]=Math.round(i+b/100*g),b>=99.8&&(b=100),b<100?(m(d),n()):(oe.done(),oe.animMode(!1),"function"==typeof t&&t.call(ie))};n()}},setSelect:y,setOptions:function(e){c(e),k()},tellSelect:function(){return p(te.getFixed())},tellScaled:function(){return te.getFixed()},setClass:function(e){R.removeClass().addClass(r("holder")).addClass(e)},disable:C,enable:x,cancel:function(){oe.done(),re.activateHandlers(null,null)},release:oe.release,destroy:function(){R.remove(),D.show(),D.css("visibility","visible"),e(t).removeData("Jcrop")},focus:ae.watchKeys,getBounds:function(){return[J*G,A*N]},getWidgetSize:function(){return[J,A]},getScaleFactor:function(){return[G,N]},getOptions:function(){return M},ui:{holder:R,selection:W}};return j&&R.on("selectstart",(function(){return!1})),D.data("Jcrop",ie),ie},e.fn.Jcrop=function(t,n){var o;return this.each((function(){if(e(this).data("Jcrop")){if("api"===t)return e(this).data("Jcrop");e(this).data("Jcrop").setOptions(t)}else"IMG"==this.tagName?e.Jcrop.Loader(this,(function(){e(this).css({display:"block",visibility:"hidden"}),o=e.Jcrop(this,t),e.isFunction(n)&&n.call(o)})):(e(this).css({display:"block",visibility:"hidden"}),o=e.Jcrop(this,t),e.isFunction(n)&&n.call(o))})),this},e.Jcrop.Loader=function(t,n,o){var r=e(t),a=r[0];r.on("load.jcloader",(function t(){a.complete?(r.off(".jcloader"),e.isFunction(n)&&n.call(a)):window.setTimeout(t,50)})).on("error.jcloader",(function(t){r.off(".jcloader"),e.isFunction(o)&&o.call(a)})),a.complete&&e.isFunction(n)&&(r.off(".jcloader"),n.call(a))},e.Jcrop.defaults={allowSelect:!0,allowMove:!0,allowResize:!0,trackDocument:!0,baseClass:"jcrop",addClass:null,bgColor:"black",bgOpacity:.6,bgFade:!1,borderOpacity:.4,handleOpacity:.5,handleSize:null,aspectRatio:0,keySupport:!0,createHandles:["n","s","e","w","nw","ne","se","sw"],createDragbars:["n","s","e","w"],createBorders:["n","s","e","w"],drawBorders:!0,dragEdges:!0,fixedSupport:!0,touchSupport:null,shade:null,boxWidth:0,boxHeight:0,boundary:2,fadeTime:400,animationDelay:20,swingSpeed:3,minSelect:[0,0],maxSize:[0,0],minSize:[0,0],onChange:function(){},onSelect:function(){},onDblClick:function(){},onRelease:function(){}}}(jQuery);