var JSUploader=Class.create();JSUploader.prototype={initialize:function(b,e,d,a,c){this.currentTheme=b;this.selectedFileContainer=d;this.supportsHTML5MultiFile=(window.File&&window.FileReader&&window.FileList)&&!app.isIE&&!app.isSafari&&!app.isChrome;this.selectedFileCount=0;this.nextFileChooserID=1;this.maxSelectableFiles=c?c:-1;this.addFileChooser(e);this.currentFileChooser=e;if(app.isChrome||app.isSafari){a.hide()}},addFileChooser:function(a){a.jsuploader=this;if(this.maxSelectableFiles!=-1&&this.selectedFileCount>=this.maxSelectableFiles){a.disabled=true}else{a.name="fileSelector"+this.nextFileChooserID;this.nextFileChooserID++;Event.observe(a,"change",this.onFileSelection.bindAsEventListener(this),false)}this.currentFileChooser=a},onFileSelection:function(b){var c=Event.element(b);if(this.supportsHTML5MultiFile){$("selectedFileContainer").update(Builder.node("div"));for(var a=0;a<c.files.length;a++){this.selectedFileCount++;var e=document.createElement("div");e.innerHTML=c.files[a].fileName;$("selectedFileContainer").appendChild(e)}}else{if(!app.isSafari&&!app.isChrome){this.selectedFileCount++;var d=document.createElement("input");d.type="file";d.multiple="true";this.addFileChooser(d);c.parentNode.insertBefore(d,c);this.addFileSelection(c);c.style.position="absolute";c.style.left="-1000px"}}},removeSelectedFile:function(a){var b=Event.element(a);b.parentNode.fileChooser.parentNode.removeChild(b.parentNode.fileChooser);b.parentNode.parentNode.removeChild(b.parentNode);this.selectedFileCount--;if(this.currentFileChooser.disabled){this.currentFileChooser.disabled=false;Event.observe(this.currentFileChooser,"change",this.onFileSelection.bindAsEventListener(this),false)}},addFileSelection:function(b){var c=Builder.node("div");var a=Builder.node("img");a.src=this.currentTheme+"/images/icons/delete-normal.png";a.setStyle({cursor:"pointer"});a.onmouseout=function(){this.src=this.currentTheme+"/images/icons/delete-normal.png"}.bind(this);a.onmouseover=function(){this.src=this.currentTheme+"/images/icons/delete-hover.png"}.bind(this);c.fileChooser=b;Event.observe(a,"click",this.removeSelectedFile.bindAsEventListener(this),false);c.innerHTML=b.value;c.appendChild(a);this.selectedFileContainer.appendChild(c)}};
