(function(b){b.ImageUtils=function(a){var g=this,d=document,h;a=b(a);g.target=a;if(b.browser.msie){d.namespaces.add("v","urn:schemas-microsoft-com:vml");h=d.createStyleSheet();h.cssText="v\\:*{behavior:url(#default#VML);display:inline-block;margin:0;padding:0}"}else{a.after('<canvas id="editImageCanvas" style="display:none"></canvas>');g.canvas=document.getElementById("editImageCanvas");g.context=g.canvas.getContext("2d")}};b.extend(b.ImageUtils.prototype,{render:function(){var a=this;a.img=new Image();b(a.img).load(function(){if(a.canvas){a.canvas.width=a.img.width;a.canvas.height=a.img.height;b(a.canvas).css({width:a.img.width,height:a.img.height}).show();a.context.drawImage(a.img,0,0)}else{a.target.after('<v:image id="editImageVML" src="'+a.img.src+'" style="width:'+a.img.width+"px;height:"+a.img.height+'px"></v:image>')}a.target.hide();b(a).trigger("ImageUtils:load")});a.img.src=a.target.attr("src")},flip:function(d){var f=this,a=f.context;if(!f.canvas){b("#editImageVML").css("flip",d=="h"?"x":"y");return}if(d=="h"){a.save();a.scale(-1,1);a.drawImage(f.img,-f.img.width,0);a.restore()}else{a.save();a.scale(1,-1);a.drawImage(f.img,0,-f.img.height);a.restore()}},rotate:function(k){var i=this,j=i.img,h=i.canvas,l=i.context,a=k*Math.PI/180;if(!i.canvas){b("#editImageVML").attr("rotation",k);return}l.save();switch(k){case 90:h.width=j.height;h.height=j.width;l.rotate(a);l.drawImage(j,0,-j.height);b(i.canvas).css({width:j.height,height:j.width});break;case 180:h.width=j.width;h.height=j.height;l.rotate(a);l.drawImage(j,-j.width,-j.height);break;case 270:h.width=j.height;h.height=j.width;l.rotate(a);l.drawImage(j,-j.width,0);break}l.restore();b(i.canvas).css({width:h.width,height:h.height})},destroy:function(){var a=this;if(a.canvas){b(a.canvas).remove()}else{b("#editImageVML").remove()}a.target.show()}})})(jQuery);