(function(g,d){var j=RegExp("^"+UPLOAD_URL);d.extend(g,{fileManager:function(a,f,e){var b=["?app=system&controller=attachment&action=index&select=1"];e||b.push("&single=1");f||(f="jpg,jpeg,png,gif");b.push("&ext_limit="+f);var c=g.iframe(b.join(""),820,465,null,{ok:function(h){if(e)for(var i=0,k=h.length;i<k;i++)h[i].src&&(h[i].src=h[i].src.replace(j,""));else h.src&&(h.src=h.src.replace(j,""));(g.func(a)||function(){})(h);c.dialog("close")}});return c},editImage:function(a,f){if(a){var e=g.iframe("?app=system&controller=attachment&action=edit_image&fileurl="+
a,450,450,null,{ok:function(b){b=b.orig_img.replace(j,"");(g.func(f)||function(){})(b);e.dialog("close")}});return e}}});d.fn.imageInput=function(){this.each(function(){var a=d(this),f=d(a.attr("upbtn")),e=d(a.attr("filebtn")),b=d(a.attr("editbtn"));a.floatImg({url:UPLOAD_URL,width:200});f.imgUploader(function(c){a.val(c);b.show()});b.click(function(){g.editImage(a.val(),function(c){a.val(c.replace(""+UPLOAD_URL,""))})});e.click(function(){g.fileManager(function(c){a.val(c.src.replace(""+UPLOAD_URL,
""));b.show()})})});return this};d.fn.photoInput=function(){var a=this,f=d(a.attr("upbtn")),e=d(a.attr("editbtn")),b=d(a.attr("preview"));f.imgUploader(function(c){a.val(c.replace(/^avatar\//,""));b.attr("src",UPLOAD_URL+c);e.show()},"?app=system&controller=upload&action=photo","images/upload.gif");e.click(function(){g.editImage("avatar/"+a.val(),function(c){a.val(c.replace(/^avatar\//,""));b.attr("src",UPLOAD_URL+c+"?"+Math.random())})});return this}})(cmstop,jQuery);
