

UploadUtil = Class.create(plupload.Uploader,

		{ init: function(settings) {
			
				settings 			= settings==undefined ? {} : settings;
				settings.runtimes 		= settings.runtimes!=undefined ? settings.runtimes : 'html5,flash,silverlight,html4';
				settings.max_file_size 		= settings.max_file_size!=undefined ? settings.max_file_size : '10mb';
				settings.flash_swf_url 		= settings.flash_swf_url!=undefined ? settings.flash_swf_url : '/lib/js/uncom/plupload/js/plupload.flash.swf';
				settings.silverlight_xap_url 	= settings.silverlight_xap_url!=undefined ? settings.silverlight_xap_url : '/lib/js/uncom/plupload/js/plupload.silverlight.xap';
				settings.container 		= settings.container!=undefined ? settings.container : "upload-container";
				settings.browse_button 		= settings.browse_button!=undefined ? settings.browse_button : "upload-browse-button";
				
				this.sup(settings);
				
				if(settings.single_selection)
					this.enable_single_selection();
		
				this.bind("PostInit", function(up, params) {
					$("input#" + this.id + "_html5").css({ padding:0, margin:0, height: "100%", cursor: "pointer" });	
					$("div#" + this.id + "_html5_container").css({ cursor: "pointer" });	
				});				
			},
			
			bind_default_filelist: function(filelist) {

				this.bind("Error", function(up, err) {
					filelist.append("<div>Error: " + err.message + (err.file ? " " + err.file.name : "") + "</div>");

					up.refresh();
				});		

				this.bind("Init", function(up, params) {
					filelist.html("");
				});

				this.bind("FilesAdded", function(up, files) {
				
					if(this.settings.multi_selection==false)
						filelist.html("");
				
					$.each(files, function(i, file) {
						filelist.append('<div id="file-list-' + file.id + '" class="file-list-item">' + file.name + ' (' + plupload.formatSize(file.size) + ') <span class="file-list-status"></span>' + '</div>');
					});

					up.refresh();
				});
				
				this.bind("UploadProgress", function(up, file) {
					$("#file-list-" + file.id + " span").html(file.percent + "%");
				});
				
				this.bind("FileUploaded", function(up, file) {
					$("#file-list-" + file.id + " span").html("100%");
				});				
			},
			
			enable_single_selection: function() {
			
				this.settings.multi_selection = false;
				
				this.bind("FilesAdded", function(up, files) {

					up.refresh();

					f = up.files;

					$.each(f, function(i1, file1) {

						has_file = false;

						$.each(files, function(i2, file2) {
							if(file1.id==file2.id)
								has_file = true;
						});

						if(has_file==false) 
							up.removeFile(file1);

					});			
				});
			}
		});


