(function(d){var c=0;d.multiUpload=function(b){var f=this,a;f.id=f.generateID();f.settings={};f.settings=b=d.extend(f.settings,b);if(b.max_size){b.max_size=f.parseSize(b.max_size)}if(b.chunk_size){b.chunk_size=f.parseSize(b.chunk_size)}if(b.oninit){d(f).bind("multiUpload:init",function(){b.oninit.call(f,f)})}f.init();d(["setup","filesSelected","fileProgress","filesProgress","filesUploaded","fileUploaded","fileUploadProgress"]).each(function(){if(b[(this)]){d(f).bind("multiUpload:"+this,b[(this)])}});d(f).trigger("multiUpload:setup");d(f).bind("multiUpload:selectFiles",function(){this.cache={}});d(f).bind("multiUpload:filesSelected",function(j,l){var e=f.settings.max_size;function k(g){var i=/\.([^.]+)$/.exec(g.name.toLowerCase()),h=i?i[1]:null;return h&&d.inArray(h,b.filter)!=-1&&(!e||g.size<e)}if(b.filter[0]!="*"){this.files=d.grep(this.files,k);l.files=d.grep(l.files,k)}this.cache={}})};d.extend(d.multiUpload.prototype,{files:[],cache:{},listeners:{},status:0,init:function(){},repaint:function(){},selectFiles:function(){d(this).trigger("multiUpload:selectFiles")},startUpload:function(){this.status=1;d(this).trigger("multiUpload:startUpload");this.uploadNext()},stopUpload:function(){this.status=0;d(this).trigger("multiUpload:stopUpload")},uploadNext:function(){var b,a=this.files;if(!this.status){return}for(b=0;b<a.length;b++){if(!a[b].status){d(this).trigger("multiUpload:uploadFile",[a[b]]);return}}this.stopUpload()},getFile:function(a){var i=this,b,j,f=i.files;if(b=i.cache[a]){return b}for(j=0;j<f.length;j++){if(f[j].id==a){return i.cache[a]=f[j]}}},removeFile:function(a){var f=this,b;f.files=d.grep(f.files,function(e){if(e.id==a){b=e}return e.id!=a});d(this).trigger("multiUpload:removeFile",b);d(this).trigger("multiUpload:filesChanged")},clearFiles:function(){this.stopUpload();this.files=[];this.cache={};d(this).trigger("multiUpload:clearFiles");d(this).trigger("multiUpload:filesChanged")},formatSize:function(a){if(a>1048576){return Math.round(a/1048576,1)+" MB"}if(a>1024){return Math.round(a/1024,1)+" KB"}return a+" b"},generateID:function(){return"u"+(c++)},parseSize:function(a){var b;if(typeof(a)=="string"){a=/^([0-9]+)([mk]+)$/.exec(a.toLowerCase().replace(/[^0-9mk]/g,""));b=a[2];a=parseInt(a[1]);if(b=="m"){a*=1048576}if(b=="k"){a*=1024}}return a}});d.extend(d.multiUpload,{instances:{},create:function(a){return this.add(new d.multiUpload(a))},remove:function(a){if(this.get(a)){delete this.instances[a]}},add:function(a){return this.instances[a.id]=a},get:function(a){return this.instances[a]}})})(jQuery);