// Add the default callBack-handler:
Widget.addCallBack("SWFUploader", function(params) {
	//V// "uploadHandler" => "./Framework/Widgets/SWFUploader/uploader/php",
	//V// "uploadDir" => $owner->getContentPath(). "/Files",		
	//V// "fileTypes" => "*.*",
	//V// "fileDescription" => "All files",
	//V// "sizeLimit" => "1 MB",
	//V// "maxFiles" => 1,
	//V// "btnSprite" => "./Framework/Widgets/SWFUploader/Graphics/Buttons/XPButtonUploadText_61x22.png",
	//V// "btnWidth" => 62,
	//V// "btnHeight" => 22
	
	alert(params.uploadHandler);
	
	// Define the SWFUpload extension settings:
	var settings = {
			// Basic settings:
			debug: params.debug,
			upload_url: "./Framework/Widgets/SWFUploader/uploader.php",//params.uploadHandler,
			flash_url: "./Framework/Extensions/SWFUpload/swfupload.swf",
			flash9_url: "./Framework/Extensions/SWFUpload/swfupload_fp9.swf",
			
			// Post params (for the PHP upload handler):
			post_params: { "uploadDir": params.uploadDir, "PHPSESSID": params.sessionId },
			
			// File settings:
			file_types: params.fileTypes,
			file_types_description: params.fileDescription,
			file_size_limit: params.sizeLimit,
			file_upload_limit: params.maxFiles,
			file_queue_limit: 0,
			
			// Button settings:
			button_image_url: params.btnSprite,
			button_width: params.btnWidth,
			button_height: params.btnHeight,
			button_placeholder_id: params.widgetId + "_button",
			
			// Define the SWFUpload handlers:
			swfupload_preload_handler: function() {
					if (!this.support.loading) {
						alert("You need the Flash Player 9.028 or above to use SWFUpload.");
						
						return false;
					}
				},
			
			swfupload_load_failed_handler: function() {
					alert("Something went wrong while loading SWFUpload. If this were a real application we'd clean up and then give you an alternative");
				},
			
			file_queue_error_handler: function(file, errorCode, message) {
					alert("File queue error handler message: '" + message + "' (code: " + errorCode + ")!");
				},
			
			file_dialog_complete_handler: function(numFilesSelected, numFilesQueued) {
					try {
						this.startUpload();
					} catch (ex)  {
						Debugger.write(ex);
					}
				},
			
			upload_start_handler: function(file) {
					return true;
				},
			
			upload_error_handler: function(file, errorCode, message) {
					alert("File upload error message: '" + message + "' (code: " + errorCode + ")!");	
				},
			
			upload_success_handler: function(file, serverData) {
					alert("File " + file.name + " uploaded...");
				}
		};
	
	// Create & store the SWFUpload extension object:
	SWFUploader.createInstance(params.widgetId, settings);
});

/**
 * The SWFUploader static class.
 * 
 * @version 2010-10-04
 * @author <a href="mailto:r.tennapel@griponservice.nl?SUBJECT=SWFUploader script.js">R. ten Napel, ing.</a>
 **/
function SWFUploader() {}

// This is where all the SWFUpload instances are stored:
SWFUploader.widgets = [];

/**
 * Create and store an instance of the SWFUpload object.
 * 
 * @param widgetId			The widget ID.
 * @param settings			The SWFUpload settings object.
 * 
 * @return					The SWFUpload object.
 **/
SWFUploader.createInstance = function(widgetId, settings) {
	var swfu = new SWFUpload(settings);
	
	// Store the new instance:
	SWFUploader.widgets[widgetId] = swfu;
	
	return swfu;
};
