(function(f){var c="undefined",d="function",e,b,a=function(i){var g=0,h=[];this.complete=function(){g+=1;if(g===h.length+1){i(h);g=0;h=[]}};this.push=function(j){h.push(j)};this.getList=function(){return h}};e=function(i,k){var h=this,j,l,n=new a(function(o){h.hideProgressBarAll(function(){h.resetProgressBarAll();if(typeof h.onCompleteAll===d){h.onCompleteAll(o)}})}),m=function(o){return typeof o.uploadTable===d?o.uploadTable(o):o.uploadTable},g=function(o){return typeof o.downloadTable===d?o.downloadTable(o):o.downloadTable};this.requestHeaders={Accept:"application/json, text/javascript, */*; q=0.01"};this.dropZone=i;this.imageTypes=/^image\/(gif|jpeg|png)$/;this.previewMaxWidth=this.previewMaxHeight=80;this.previewLoadDelay=100;this.previewAsCanvas=true;this.previewSelector=".file_upload_preview";this.progressSelector=".file_upload_progress div";this.cancelSelector=".file_upload_cancel button";this.cssClassSmall="file_upload_small";this.cssClassLarge="file_upload_large";this.cssClassHighlight="file_upload_highlight";this.dropEffect="highlight";this.uploadTable=this.downloadTable=null;this.buildUploadRow=this.buildDownloadRow=null;this.progressAllNode=null;this.loadImage=function(r,q,v,w,o,u){var t,p,x,s;if(o&&!o.test(r.type)){return null}p=function(y){var z=document.createElement("canvas"),A=Math.min((v||y.width)/y.width,(w||y.height)/y.height);if(A>1){A=1}y.width=parseInt(y.width*A,10);y.height=parseInt(y.height*A,10);if(u||typeof z.getContext!==d){return y}z.width=y.width;z.height=y.height;z.getContext("2d").drawImage(y,0,0,y.width,y.height);return z};t=document.createElement("img");x=typeof URL!==c?URL:typeof webkitURL!==c?webkitURL:null;if(x&&typeof x.createObjectURL===d){t.onload=function(){x.revokeObjectURL(this.src);q(p(t))};t.src=x.createObjectURL(r)}else{if(typeof FileReader!==c&&typeof FileReader.prototype.readAsDataURL===d){t.onload=function(){q(p(t))};s=new FileReader();s.onload=function(y){t.src=y.target.result};s.readAsDataURL(r)}else{q(null)}}};this.addNode=function(o,p,q){if(o&&o.length&&p&&p.length){p.css("display","none").appendTo(o).fadeIn(function(){if(typeof q===d){try{q()}catch(r){p.stop();throw r}}})}else{if(typeof q===d){q()}}};this.removeNode=function(o,p){if(o&&o.length){o.fadeOut(function(){o.remove();if(typeof p===d){try{p()}catch(q){o.stop();throw q}}})}else{if(typeof p===d){p()}}};this.replaceNode=function(q,o,p){if(!(o&&o.length)){return h.removeNode(q,p)}if(q&&q.length){q.fadeOut(function(){o.css("display","none");q.replaceWith(o);o.fadeIn(function(){if(typeof p===d){try{p()}catch(r){q.stop();o.stop();throw r}}})})}else{if(typeof p===d){p()}}};this.resetProgressBarAll=function(){if(h.progressbarAll){h.progressbarAll.progressbar("value",0)}};this.hideProgressBarAll=function(o){if(h.progressbarAll&&!f(m(h)).find(h.progressSelector+":visible:first").length){h.progressbarAll.fadeOut(o)}else{if(typeof o===d){o()}}};this.onAbort=function(r,q,o,s,p){p.removeNode(p.uploadRow,p.hideProgressBarAll)};this.cancelUpload=function(s,r,p,t,q){var o=t.readyState;t.abort();if(typeof o!=="number"||o<2){q.onAbort(s,r,p,t,q)}};this.initProgressBar=function(o,p){if(!o||!o.length){return null}if(typeof o.progressbar===d){return o.progressbar({value:p})}else{o.addClass("progressbar").append(f("<div/>").css("width",p+"%")).progressbar=function(q,r){return this.each(function(){if(q==="destroy"){f(this).removeClass("progressbar").empty()}else{f(this).children().css("width",r+"%")}})};return o}};this.destroyProgressBar=function(o){if(!o||!o.length){return null}return o.progressbar("destroy")};this.initUploadProgress=function(p,o){if(!p.upload&&o.progressbar){o.progressbar.progressbar("value",100)}};this.initUploadProgressAll=function(){if(h.progressbarAll&&h.progressbarAll.is(":hidden")){h.progressbarAll.fadeIn()}};this.onSend=function(r,q,o,s,p){p.initUploadProgress(s,p)};this.onProgress=function(r,q,o,s,p){if(p.progressbar&&r.lengthComputable){p.progressbar.progressbar("value",parseInt(r.loaded/r.total*100,10))}};this.onProgressAll=function(o,p){if(h.progressbarAll&&o.lengthComputable){h.progressbarAll.progressbar("value",parseInt(o.loaded/o.total*100,10))}};this.onLoadAll=function(o){n.complete()};this.initProgressBarAll=function(){if(!h.progressbarAll){h.progressbarAll=h.initProgressBar((typeof h.progressAllNode===d?h.progressAllNode(h):h.progressAllNode),0)}};this.destroyProgressBarAll=function(){h.destroyProgressBar(h.progressbarAll)};this.loadPreviewImage=function(q,o,p){o=o||0;p.uploadRow.find(p.previewSelector).each(function(){var r=f(this),s=q[o];setTimeout(function(){p.loadImage(s,function(t){p.addNode(r,f(t))},p.previewMaxWidth,p.previewMaxHeight,p.imageTypes,!p.previewAsCanvas)},p.previewLoadDelay);o+=1})};this.initUploadRow=function(r,q,o,t,p){var s=p.uploadRow=(typeof p.buildUploadRow===d?p.buildUploadRow(q,o,p):null);if(s){p.progressbar=p.initProgressBar(s.find(p.progressSelector),0);s.find(p.cancelSelector).click(function(u){p.cancelUpload(u,q,o,t,p);u.preventDefault()});p.loadPreviewImage(q,o,p)}};this.initUpload=function(r,q,o,t,p,s){p.initUploadRow(r,q,o,t,p);p.addNode(m(p),p.uploadRow,function(){if(typeof p.beforeSend===d){p.beforeSend(r,q,o,t,p,s)}else{s()}});p.initUploadProgressAll()};this.parseResponse=function(p,o){if(typeof p.responseText!==c){return f.parseJSON(p.responseText)}else{return f.parseJSON(p.contents().text())}};this.initDownloadRow=function(t,s,p,v,r){var q,o;try{q=r.response=r.parseResponse(v,r)}catch(u){if(typeof r.onError===d){r.originalEvent=t;r.onError(u,s,p,v,r)}else{throw u}}o=r.downloadRow=(typeof r.buildDownloadRow===d?r.buildDownloadRow(q,r):null)};this.onLoad=function(t,s,p,v,q){var o=m(q),r=g(q),u=function(){if(typeof q.onComplete===d){q.onComplete(t,s,p,v,q)}n.complete()};n.push(Array.prototype.slice.call(arguments,1));q.initDownloadRow(t,s,p,v,q);if(o&&q.uploadRow&&q.uploadRow.length&&(!r||o.get(0)===r.get(0))){q.replaceNode(q.uploadRow,q.downloadRow,u)}else{q.removeNode(q.uploadRow,function(){q.addNode(r,q.downloadRow,u)})}};this.dropZoneEnlarge=function(){if(!l){if(typeof h.dropZone.switchClass===d){h.dropZone.switchClass(h.cssClassSmall,h.cssClassLarge)}else{h.dropZone.addClass(h.cssClassLarge);h.dropZone.removeClass(h.cssClassSmall)}l=true}};this.dropZoneReduce=function(){if(typeof h.dropZone.switchClass===d){h.dropZone.switchClass(h.cssClassLarge,h.cssClassSmall)}else{h.dropZone.addClass(h.cssClassSmall);h.dropZone.removeClass(h.cssClassLarge)}l=false};this.onDocumentDragEnter=function(o){h.dropZoneEnlarge()};this.onDocumentDragOver=function(o){if(j){clearTimeout(j)}j=setTimeout(function(){h.dropZoneReduce()},200)};this.onDragEnter=this.onDragLeave=function(o){h.dropZone.toggleClass(h.cssClassHighlight)};this.onDrop=function(o){if(j){clearTimeout(j)}if(h.dropEffect&&typeof h.dropZone.effect===d){h.dropZone.effect(h.dropEffect,function(){h.dropZone.removeClass(h.cssClassHighlight);h.dropZoneReduce()})}else{h.dropZone.removeClass(h.cssClassHighlight);h.dropZoneReduce()}};this.init=function(){h.initProgressBarAll();if(typeof h.initExtended===d){h.initExtended()}};this.destroy=function(){if(typeof h.destroyExtended===d){h.destroyExtended()}h.destroyProgressBarAll()};f.extend(this,k)};b={init:function(g){return this.each(function(){f(this).fileUpload(new e(f(this),g))})},option:function(h,i,g){if(!h||(typeof h==="string"&&typeof i===c)){return f(this).fileUpload("option",h,i,g)}return this.each(function(){f(this).fileUpload("option",h,i,g)})},destroy:function(g){return this.each(function(){f(this).fileUpload("destroy",g)})},upload:function(h,g){return this.each(function(){f(this).fileUpload("upload",h,g)})}};f.fn.fileUploadUI=function(g){if(b[g]){return b[g].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof g==="object"||!g){return b.init.apply(this,arguments)}else{f.error('Method "'+g+'" does not exist on jQuery.fileUploadUI')}}}}(jQuery));
