(function(i){var v;var g;var o;var D;var G;var C;var u;var s;var j;var m;var x;var e;var q;var p;var z=-1;var y;var F;var w;var d;var c;var n;var b;var a;var r;var E;var l;var f;i.fn.extend(i.sfbrowser,{imageresize:function(I){v=I.trace;g=I.openDir;s=I.aPath;m=I.oTree;j=I.oSettings;x=I.mSfb;o=I.addContextItem;D=I.file;G=I.lang;C=I.moveWindowDown;u=I.resizeWindow;var H=i.sfbrowser;e=j.sfbpath+"plugins/imageresize/connectors/"+j.connector+"/imageresize."+j.connector;x.find("#fbwin").prepend(j.imageresize);x.find("#sfbimgresize>div.sfbheader>h3").mousedown(C);x.find("div.cancelresize").text(j.lang.cancel).click(function(){i("#sfbimgresize").hide();i("#winbrowser").show();u()});x.find("div.resize").text(j.lang.resize).click(k);x.find("div.handle").attr("title",j.lang.dragMe).mousedown(B);x.find("div#crop").attr("title",j.lang.dragMe).mousedown(B);i("div#sfbimgresize>div.fbcontent>label[for=rszperc]").text(j.lang.scale);i("form#sfbsize legend:eq(0)").text(j.lang.resize+":");i("form#sfbsize label[for=rszW]").text(j.lang.width);i("form#sfbsize label[for=rszH]").text(j.lang.height);i("form#sfbsize input[name=rszW]").change(function(){w=Math.min(q.width,parseInt(i(this).val()));d=w/y;t()});i("form#sfbsize input[name=rszH]").change(function(){d=Math.min(q.height,parseInt(i(this).val()));w=d*y;t()});i("form#sfbsize legend:eq(1)").text(j.lang.crop+":");i("form#sfbsize label[for=crpW]").text(j.lang.width);i("form#sfbsize label[for=crpH]").text(j.lang.height);i("form#sfbsize input[name=crpX]").change(function(){b=parseInt(i(this).val());t()});i("form#sfbsize input[name=crpY]").change(function(){a=parseInt(i(this).val());t()});i("form#sfbsize input[name=crpW]").change(function(){c=parseInt(i(this).val());t()});i("form#sfbsize input[name=crpH]").change(function(){n=parseInt(i(this).val());t()});o("resize",j.lang.resize,function(){h()},0)}});i.extend(i.sfbrowser.imageresize,{resizeWindow:function(J,I){if(q){var K=i("#fbwin").width()-i("form#sfbsize").width()-20;var H=i("#fbwin").height()-70;F=Math.min(1,Math.min(K/q.width,H/q.height));i("div#sfbimgresize>div.fbcontent>span#rszperc").text(Math.round(F*100)+"%");i("#sfbimgresize div#org").css({width:(F*q.width)+"px",height:(F*q.height)+"px"});t()}}});function h(H){i("#winbrowser").hide();i("#sfbimgresize").show();q=D();y=q.width/q.height;l=c=w=q.width;f=n=d=q.height;r=E=b=a=0;i("#sfbimgresize>div.sfbheader>h3").text(j.lang.imgResize+": "+q.file);i("div#sfbrsimg>img").attr("src",j.sfbpath+s.join("")+q.file);i.sfbrowser.imageresize.resizeWindow()}function B(H){r=b;E=a;l=c;f=n;var I=this;x.find("div.handle").each(function(J){if(i(this)[0]==I){z=J}});p=i(this);if(p[0]==i("div#crop")[0]){z=10}i("body").mousemove(A).mouseup(function(){i("body").unbind("mousemove",A);z=-1;p=null});H.stopPropagation();return false}function A(J){var L=p.parent();var H=Math.min(Math.max(0,Math.round((J.pageX-L.offset().left)/F)),q.width);var K=Math.min(Math.max(0,Math.round((J.pageY-L.offset().top)/F)),q.height);switch(z){case 10:b=H-c/2;a=K-n/2;break;case 8:w=H;d=K;break;default:for(var I=0;I<(z<4?2:1);I++){switch(((z%4)-I+4)%4){case 0:a=K;n=f-(a-E);break;case 1:c=H-b;break;case 2:n=K-a;break;case 3:b=H;c=l-(b-r);break}}}t();J.stopPropagation();return false}function t(){w=Math.max(1,w);d=Math.max(1,d);if(w/d>y){d=w/y}else{w=d*y}b=Math.max(Math.min(b,w-c),0);a=Math.max(Math.min(a,d-n),0);c=Math.max(1,Math.min(c,w-b));n=Math.max(1,Math.min(n,d-a));var L=w*F;var J=d*F;var N=b*F;var M=a*F;var H=c*F;var K=n*F;i("div#sfbrsimg>img").css({width:L+"px",height:J+"px"});i("#sfbimgresize div#crop").css({left:N+"px",top:M+"px",width:H+"px",height:K+"px"});i("div.handle:eq(8)").css({left:(L-6)+"px",top:(J-6)+"px"});i("div.handle:eq(0)").css({left:(N-6)+"px",top:(M-6)+"px"});i("div.handle:eq(1)").css({left:(N+H-6)+"px",top:(M-6)+"px"});i("div.handle:eq(2)").css({left:(N+H-6)+"px",top:(M+K-6)+"px"});i("div.handle:eq(3)").css({left:(N-6)+"px",top:(M+K-6)+"px"});i("div.handle:eq(4)").css({left:(N+H/2-6)+"px",top:(M-6)+"px"});i("div.handle:eq(5)").css({left:(N+H-6)+"px",top:(M+K/2-6)+"px"});i("div.handle:eq(6)").css({left:(N+H/2-6)+"px",top:(M+K-6)+"px"});i("div.handle:eq(7)").css({left:(N-6)+"px",top:(M+K/2-6)+"px"});var I=w/q.width;i("form#sfbsize input[name=rszW]").val(Math.round(w));i("form#sfbsize input[name=rszH]").val(Math.round(d));i("form#sfbsize input[name=crpX]").val(Math.round(b));i("form#sfbsize input[name=crpY]").val(Math.round(a));i("form#sfbsize input[name=crpW]").val(Math.round(c));i("form#sfbsize input[name=crpH]").val(Math.round(n))}function k(){v("sfb resizeSend");var I=i("form#sfbsize input[name=rszW]").val();var K=i("form#sfbsize input[name=rszH]").val();var M=i("form#sfbsize input[name=crpX]").val();var L=i("form#sfbsize input[name=crpY]").val();var H=i("form#sfbsize input[name=crpW]").val();var J=i("form#sfbsize input[name=crpH]").val();if(I==q.width&&K==q.height&&H==q.width&&J==q.height){v("sfb Will not resize to same size.")}else{v("sfb Sending resize request...");i.ajax({type:"POST",url:e,data:"a=bar&folder="+s.join("")+"&file="+q.file+"&w="+I+"&h="+K+"&cx="+M+"&cy="+L+"&cw="+H+"&ch="+J,dataType:"json",success:function(P,O){if(typeof(P.error)!="undefined"){if(P.error!=""){v(G(P.error));alert(G(P.error))}else{q.width=H;q.height=J;q.tr.find("td:eq(4)").attr("abbr",H*J).text(H+" x "+J+" px");var N=i("#fbpreview").clone(true);i("#fbpreview").html("");i("#fbpreview").html(N.children());i("#sfbimgresize").hide();i("#winbrowser").show();u()}}}})}}})(jQuery);