(function(b){if(!b.multiUpload.initialized&&window.google&&google.gears){b.multiUpload.initialized=1;b.multiUpload.runtime="gears";b.extend(b.multiUpload.prototype,{init:function(){var a=this;b(a).trigger("multiUpload:init");b(a).bind("multiUpload:selectFiles",function(e){var j=this,i=google.gears.factory.create("beta.desktop"),h={};if(j.settings.filter[0]!="*"){h.filter=b.map(j.settings.filter,function(c){return"."+c})}i.openFiles(function(c){var d=[];if(c.length){j._fireEvent("multiUpload:beforeFilesSelected");b(c).each(function(){var f={id:j.generateID(),name:this.name,blob:this.blob,size:this.blob.length,loaded:0};j.files.push(f);d.push(f)});j._fireEvent("multiUpload:filesSelected",[{files:d}]);j._fireEvent("multiUpload:filesChanged")}else{j._fireEvent("multiUpload:filesSelectionCancelled")}},h)});b(a).bind("multiUpload:uploadFile",function(r,q){var i,t=this,x,e=0,s,u,y,v=0,w;x=t.settings.chunk_size||1024*1024;s=Math.ceil(q.blob.length/x);z();function z(){var c=t.settings.upload_url;if(q.status){return}w=Math.min(x,q.blob.length-(e*x));i=google.gears.factory.create("beta.httprequest");i.open("POST",c+(c.indexOf("?")==-1?"?":"&")+"name="+escape(q.name)+"&chunk="+e+"&chunks="+s+"&path="+escape(t.settings.path));i.setRequestHeader("Content-Disposition",'attachment; filename="'+q.name+'"');i.setRequestHeader("Content-Type","application/octet-stream");i.setRequestHeader("Content-Range","bytes "+e*x);i.upload.onprogress=function(d){q.loaded=v+d.loaded;t._fireEvent("multiUpload:fileUploadProgress",[{file:q,loaded:q.loaded,total:q.size}])};i.onreadystatechange=function(){var d;if(i.readyState==4){if(i.status==200){d={file:q,chunk:e,chunks:s,response:i.responseText};t._fireEvent("multiUpload:chunkUploaded",[d]);if(d.cancel){q.status="failed";t._fireEvent("multiUpload:filesChanged");t.uploadNext();return}v+=w;if(++e>=s){q.status="completed";t._fireEvent("multiUpload:fileUploaded",[{file:q,response:i.responseText}]);t._fireEvent("multiUpload:filesChanged");t.uploadNext()}else{z()}}else{t._fireEvent("multiUpload:uploadChunkError",[{file:q,chunk:e,chunks:s,error:"Status: "+i.status}])}}};if(e<s){i.send(q.blob.slice(e*x,w))}}})},_fireEvent:function(d,a){b(this).trigger(d,a)}})}})(jQuery);