var cropbox=function(t,e){var e=e||$(t.imageBox),i={state:{},ratio:1,options:t,imageBox:e,thumbBox:e.find(t.thumbBox),spinner:e.find(t.spinner),image:new Image,getAvatar:function(){var t=this.thumbBox.width(),i=this.thumbBox.height(),n=document.createElement("canvas"),o=e.css("background-position").split(" "),a=e.css("background-size").split(" "),s=parseInt(o[0])-e.width()/2+t/2,r=parseInt(o[1])-e.height()/2+i/2,u=parseInt(a[0]);dh=parseInt(a[1]),sh=parseInt(this.image.height),sw=parseInt(this.image.width),n.width=t,n.height=i;var m=n.getContext("2d");m.drawImage(this.image,0,0,sw,sh,s,r,u,dh);var p=n.toDataURL("image/jpeg");return p},zoomIn:function(){this.ratio*=1.1,n()},zoomOut:function(){this.ratio*=.9,n()}},n=function(){var t=parseInt(i.image.width)*i.ratio,n=parseInt(i.image.height)*i.ratio,o=(e.width()-t)/2,a=(e.height()-n)/2;e.css({"background-image":"url("+i.image.src+")","background-size":t+"px "+n+"px","background-position":o+"px "+a+"px","background-repeat":"no-repeat"})},o=function(t){t.stopImmediatePropagation(),i.state.dragable=!0,i.state.mouseX=t.clientX,i.state.mouseY=t.clientY},a=function(t){if(t.stopImmediatePropagation(),i.state.dragable){var n=t.clientX-i.state.mouseX,o=t.clientY-i.state.mouseY,a=e.css("background-position").split(" "),s=n+parseInt(a[0]),r=o+parseInt(a[1]);e.css("background-position",s+"px "+r+"px"),i.state.mouseX=t.clientX,i.state.mouseY=t.clientY}},s=function(t){t.stopImmediatePropagation(),i.state.dragable=!1},r=function(t){i.ratio*=t.originalEvent.wheelDelta>0||t.originalEvent.detail<0?1.1:.9,n()};return i.spinner.show(),i.image.onload=function(){i.spinner.hide(),n(),e.bind("mousedown",o),e.bind("mousemove",a),$(window).bind("mouseup",s),e.bind("mousewheel DOMMouseScroll",r)},i.image.src=t.imgSrc,e.on("remove",function(){$(window).unbind("mouseup",s)}),i};jQuery.fn.cropbox=function(t){return new cropbox(t,this)};