(function(a){var o={init:function(b){return this.each(function(){function q(a){c.remotePath=typeof c.remotePath=="function"?c.remotePath():c.remotePath;var h=c.url.indexOf("?")==-1?"?":"&",h=c.url+h+"ax-file-path="+encodeURIComponent(c.remotePath)+"&ax-allow-ext="+encodeURIComponent(t);c.data=typeof c.data=="function"?c.data():c.data;return h+"&ax-file-name="+a+"&"+c.data}function o(f,h,b){d--;b.attr("disabled",false);c.success(f,h);if(d==0){var g=[];a(e).find(".ax-file-name").each(function(){g.push(a(this).attr("title"))}); d=p;c.finish(f,g);r.attr("disabled",false)}}function w(f,h,b,g,e){var k=b.split(".").pop().toLowerCase();if(!(t.indexOf(k)<0&&t!="all")){switch(c.showSize.toLowerCase()){case "mb":g/=1048576;break;case "kb":g/=1024}g=Math.round(g*100)/100+" "+c.showSize;d++;p++;r.attr("disabled",d==0);var k=a('<input type="button" value="Remove" />').bind("click",function(){d--;p--;r.attr("disabled",d==0);a(this).parents("tr:first").remove()}),i=a('<input type="button" value="Upload" class="ax-upload" />').bind("click", function(){this.disabled=true}),f=a("<tr />").appendTo(f),l=a('<td class="ax-file-name" title="'+b+'" />').appendTo(f).html(b);a('<td class="ax-size-td" />').appendTo(f).html(g);var g=a('<td class="ax-progress-td" />').appendTo(f),u=a('<div class="ax-progress-div" />').css({width:"0%","background-color":"red"}).html(0).appendTo(g);a('<td class="ax-remove-td" />').appendTo(f).append(k);a('<td class="ax-upload-td" />').appendTo(f).append(i);var m=encodeURIComponent(b);s?i.bind("click",function(){x(h, 0,a(this),u)}):(a("<div />").appendTo(l).hide().append(h),i.bind("click",function(){var f=a('<iframe src="javascript:false;" name="ax-frame-'+e+'" />').hide().appendTo(l).load(function(){a(this).attr("load")=="1"&&(u.html("Finish"),o(this.contentWindow.document.body.innerHTML,b,i))}).attr("load","0");u.html("Uploading...");f.attr("load","1");f=q(m);a('<form method="POST" action="'+f+'" encType="multipart/form-data" />').attr("target","ax-frame-"+e).appendTo(l).hide().append(h).submit()}),a(h).clone(true).val("").prependTo(n))}} function x(a,b,d,g){var e=a.size,k,i=c.chunkSize,l=b+i,n=l/i,m=e-l<=0?1:0;a.mozSlice?k=a.mozSlice(b,l):a.webkitSlice?k=a.webkitSlice(b,l):a.slice?k=a.slice(b,i):(k=a,m=1);var j=new XMLHttpRequest;j.onreadystatechange=function(){this.readyState==4&&this.status==200&&(m==0?x(a,l,d,g):(o(j.responseText,a.name,d),g.html("100%").css("width","100%")))};j.upload.onprogress=function(a){a.lengthComputable&&(a=Math.round((a.loaded+n*i-i)*100/e),g.html(a+"%").css("width",a+"%"))};j.upload.onerror=c.error(j.responseText, a.name);var p=q(encodeURIComponent(a.name));j.open("POST",p+"&start="+b,c.async);j.setRequestHeader("Cache-Control","no-cache");j.setRequestHeader("X-Requested-With","XMLHttpRequest");j.setRequestHeader("Content-Type","multipart/form-data");j.send(k)}var c={remotePath:"js/",url:"phplibs/uploadfiles.php",data:"",async:true,maxFiles:9999,allowExt:["all"],showSize:"Mb",success:function(){},finish:function(){},error:function(){},GIFprogress:"",enable:true,chunkSize:1048576},e=this;b&&a.extend(c,b);var t= c.allowExt.join("|").toLowerCase(),m=document.createElement("input");m.type="file";m.name="ax-files[]";var s="multiple"in m&&typeof File!="undefined"&&typeof(new XMLHttpRequest).upload!="undefined",d=0,p=0,y=false;a('<iframe src="javascript:false;" name="ax-main-frame" />').hide().appendTo(e).load(function(){y&&(d=1,a(e).find(".ax-progress-div").html("100%"),o(this.contentWindow.document.body.innerHTML,"",a(e).find(".ax-upload")))});var n=a('<form target="ax-main-frame" method="POST" action="" encType="multipart/form-data" />').appendTo(e); a(m).attr("multiple",s).appendTo(n).bind("change",function(){if(s)for(var a=0;a<this.files.length;a++)d<=c.maxFiles&&w(v,this.files[a],this.files[a].name,this.files[a].size,d);else d<=c.maxFiles&&w(v,this,this.value.replace(/^.*\\/,""),0,d)});var r=a('<input style="margin-left:5px;" type="button" value="Upload all" class="ax-uploadall" />').attr("disabled",true).appendTo(n).bind("click",function(){if(s)a(e).find(".ax-upload:not(:disabled)").click();else{y=true;var b=q("");n.attr("action",b).submit(); a(e).find(".ax-upload").attr("disabled",true);c.GIFprogress!=""?a(e).find(".ax-progress-div").html('<img src="'+c.GIFprogress+'" alt="uploading..." />'):a(e).find(".ax-progress-div").html("Uploading...")}});a('<input style="margin-left:5px;" type="button" value="Clear" class="ax-clear" />').appendTo(n).bind("click",function(){p=d=0;r.attr("disabled",d==0);v.children("tbody").remove()});var v=a('<table class="ax-file-list" />').append("<thead><tr><th>File</th><th>Size</th><th>Progress</th><th>Remove</th><th>Upload</th></tr></thead>").appendTo(n); c.enable||a(this).find("input:not(:disabled), button:not(:disabled)").addClass("ax-disabled").attr("disabled",true)})},enable:function(){return this.each(function(){a(this).find(".ax-disabled").attr("disabled",false).removeClass("ax-disabled")})},disable:function(){return this.each(function(){a(this).find("input:not(:disabled), button:not(:disabled)").addClass("ax-disabled").attr("disabled",true)})},start:function(){a(this).find(".ax-uploadall:not(:disabled)").click()},clear:function(){this.find(".ax-clear:not(:disabled)").click()}, destroy:function(){return this.each(function(){var b=a(this);b.removeData("settings");b.html("")})}};a.fn.axuploader=function(b,q){if(o[b])return o[b].apply(this,Array.prototype.slice.call(arguments,1));else if(typeof b==="object"||!b)return o.init.apply(this,arguments);else a.error("Method "+b+" does not exist on jQuery.axuploader")}})(jQuery);
