window.addEvent('load', function() {

	if($('demo-status')) {
		var swiffy = new FancyUpload2($('demo-status'), $('demo-list'), {
			url: null,
			fieldName: 'Filedata',
			path: '/fancyupload/source/Swiff.Uploader.swf',
			limitSize: 20 * 1024 * 1024, // 20Mb
			onLoad: function() {
				$('demo-status').removeClass('hide');
			},
			// The changed parts!
			debug: true, // enable logs, uses console.log
			target: 'demo-browse' // the element for the overlay (Flash 10 only)
		});
		
		/**
		 * Various interactions
		 */
		
		$('demo-browse').addEvent('click', function() {
			/**
			 * Doesn't work anymore with Flash 10: swiffy.browse();
			 * FancyUpload moves the Flash movie as overlay over the link.
			 * (see opeion "target" above)
			 */
			swiffy.browse();
			return false;
		});
		
		/**
		 * The *NEW* way to set the typeFilter, since Flash 10 does not call
		 * swiffy.browse(), we need to change the type manually before the browse-click.
		 */
		/*$('demo-select-images').addEvent('change', function() {
			var filter = null;
			if (this.checked) {
				filter = {'Images (*.jpg, *.jpeg, *.gif, *.png)': '*.jpg; *.jpeg; *.gif; *.png'};
			}
			swiffy.options.typeFilter = filter;
		});*/
		
		$('demo-clear').addEvent('click', function() {
			swiffy.removeFile();
			return false;
		});
		
		$('demo-upload').addEvent('click', function() {
			if($('firstname').value == '' || $('surname').value == '') {
				alert('Please fill in your first and last name above before uploading');
				return false;
			}
			else {
				swiffy.options.url = '/fancyupload/source/script.php?firstname=' + $('firstname').value + '&surname=' + $('surname').value;
			}
			swiffy.upload();
			
			$('attachments').value = 'It would appear that this user has uploaded files using the file attachment form';
			
			return false;
		});
	}

});
