(function(b){function a(i,l,j,c,k){var e,d,h,g,f;e=document.createElement("canvas");e.style.display="none";document.body.appendChild(e);d=e.getContext("2d");h=new Image();h.onload=function(){var o,m,n;f=Math.min(l/h.width,j/h.height);if(f<1){o=Math.round(h.width*f);m=Math.round(h.height*f)}else{o=h.width;m=h.height}e.width=o;e.height=m;d.drawImage(h,0,0,o,m);g=e.toDataURL(c);g=g.substring(g.indexOf("base64,")+7);g=atob(g);e.parentNode.removeChild(e);k({success:true,data:g})};h.src=i}b.runtimes.Html5=b.addRuntime("html5",{init:function(g,h){var c={},e;function f(m){var k,j,l=[],n;for(j=0;j";document.getElementById(g.id+"_html5").onchange=function(){f(this.files);this.value=""}});g.bind("PostInit",function(){var i=document.getElementById(g.settings.drop_element);if(i){b.addEvent(i,"dragover",function(j){j.preventDefault()});b.addEvent(i,"drop",function(k){var j=k.dataTransfer;if(j&&j.files){f(j.files)}k.preventDefault()})}});g.bind("Refresh",function(i){var j,k,l;j=document.getElementById(g.settings.browse_button);k=b.getPos(j,document.getElementById(i.settings.container));l=b.getSize(j);b.extend(document.getElementById(g.id+"_html5_container").style,{top:k.y+"px",left:k.x+"px",width:l.w+"px",height:l.h+"px"})});g.bind("UploadFile",function(i,l){var p=new XMLHttpRequest(),k=p.upload,j=i.settings.resize,o,n=0;function m(q){var u="----pluploadboundary"+b.guid(),s="--",t="\r\n",r="";if(i.settings.multipart){p.setRequestHeader("Content-Type","multipart/form-data; boundary="+u);b.each(i.settings.multipart_params,function(w,v){r+=s+u+t+'Content-Disposition: form-data; name="'+v+'"'+t+t;r+=w+t});r+=s+u+t+'Content-Disposition: form-data; name="file"; filename="'+l.name+'"'+t+"Content-Type: application/octet-stream"+t+t+q+t+s+u+s+t;n=r.length-q.length;q=r}p.sendAsBinary(q)}if(l.status==b.DONE||l.status==b.FAILED||i.state==b.STOPPED){return}if(k){k.onprogress=function(q){l.loaded=q.loaded-n;i.trigger("UploadProgress",l)}}p.onreadystatechange=function(){var q=p.status;if(p.readyState==4){l.status=b.DONE;l.loaded=l.size;i.trigger("UploadProgress",l);i.trigger("FileUploaded",l,{response:p.responseText,status:q});if(q!=200){i.trigger("Error",{code:b.HTTP_ERROR,message:"HTTP Error.",file:l,status:q})}}};p.open("post",b.buildUrl(i.settings.url,{name:l.target_name||l.name}),true);p.setRequestHeader("Content-Type","application/octet-stream");o=c[l.id];if(p.sendAsBinary){if(j&&/\.(png|jpg|jpeg)$/i.test(l.name)){a(o.getAsDataURL(),j.width,j.height,/\.png$/i.test(l.name)?"image/png":"image/jpeg",function(q){if(q.success){l.size=q.data.length;m(q.data)}else{m(o.getAsBinary())}})}else{m(o.getAsBinary())}}else{p.send(o)}});e=!!(File&&File.prototype.getAsDataURL);g.features={dragdrop:window.mozInnerScreenX!==undefined,jpgresize:e,pngresize:e};h({success:true})}})})(plupload);