// document.write("Intentional debugging output: " + t_inv_id);
window.addEvent('load', function() {
	// For testing, showing the user the current Flash version.
	// document.getElement('h3 + p').appendText(' Detected Flash ' + Browser.Plugins.Flash.version + '!');

	if ($('status_file_type_00')) {
		var swiffy = new FancyUpload2($('status_file_type_00'), $('list_file_type_00'), {
			// url: $('form_file_type_00').action,
			url: $('form_file_type_00').action,
			fieldName: 'photoupload',
			path: '_inc/_fu2/Swiff.Uploader.swf',
			limitSize: 2 * 1024 * 1024, // 2Mb
			onLoad: function() {
				$('status_file_type_00').removeClass('hide');
				$('fallback_file_type_00').destroy();

				new Request.HTML({
						url: '_inc/get_files_type_00.php',
						onSuccess: function(html) {
							//Clear the text currently inside the results div.
							$('div_files_type_00').set('text', '');
							//Inject the new DOM elements into the results div.
							$('div_files_type_00').adopt(html);
						},
						//Our request will most likely succeed, but just in case, we'll add an
						//onFailure method which will let the user know what happened.
						onFailure: function() {
							$('div_files_type_00').set('text', 'The request failed.');
						}
					}).send('inv_id='+t_inv_id);
			},
			// The changed parts!
			debug: true, // enable logs, uses console.log
			target: 'browse_file_type_00', // the element for the overlay (Flash 10 only)
			instantStart: true,
			onAllSelect: function(files, current, overall) {
				$('slide_in_file_type_00').slide_me.slideIn();
				// this.onAllSelect(files, current, overall);
			},
			onComplete: function(file, response) {
				this.removeFile(file);
	
				new Request.HTML({
					url: '_inc/get_files_type_00.php',
					onSuccess: function(html) {
						//Clear the text currently inside the results div.
						$('div_files_type_00').set('text', '');
						//Inject the new DOM elements into the results div.
						$('div_files_type_00').adopt(html);
					},
					//Our request will most likely succeed, but just in case, we'll add an
					//onFailure method which will let the user know what happened.
					onFailure: function() {
						$('div_files_type_00').set('text', 'The request failed.');
					}
				}).send('inv_id='+t_inv_id);
			},
			onAllComplete: function(current) {
				// this.onAllComplete(current);
				$('slide_in_file_type_00').slide_me.slideOut();
			}
		});
	
		/**
		 * Various interactions
		 */
	
		$('browse_file_type_00').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() {
			swiffy.upload();
			return false;
		});
	*/
	}
	
	if ($('status_file_type_01')) {
		var swiffy = new FancyUpload2($('status_file_type_01'), $('list_file_type_01'), {
			// url: $('form_file_type_01').action,
			url: $('form_file_type_01').action,
			fieldName: 'photoupload',
			path: '_inc/_fu2/Swiff.Uploader.swf',
			limitSize: 2 * 1024 * 1024, // 2Mb
			onLoad: function() {
				$('status_file_type_01').removeClass('hide');
				$('fallback_file_type_01').destroy();

				new Request.HTML({
						url: '_inc/get_files_type_01.php',
						onSuccess: function(html) {
							//Clear the text currently inside the results div.
							$('div_files_type_01').set('text', '');
							//Inject the new DOM elements into the results div.
							$('div_files_type_01').adopt(html);
						},
						//Our request will most likely succeed, but just in case, we'll add an
						//onFailure method which will let the user know what happened.
						onFailure: function() {
							$('div_files_type_01').set('text', 'The request failed.');
						}
					}).send('inv_id='+t_inv_id);
			},
			// The changed parts!
			debug: true, // enable logs, uses console.log
			target: 'browse_file_type_01', // the element for the overlay (Flash 10 only)
			instantStart: true,
			onAllSelect: function(files, current, overall) {
				$('slide_in_file_type_01').slide_me.slideIn();
				// this.onAllSelect(files, current, overall);
			},
			onComplete: function(file, response) {
				this.removeFile(file);
	
				new Request.HTML({
					url: '_inc/get_files_type_01.php',
					onSuccess: function(html) {
						//Clear the text currently inside the results div.
						$('div_files_type_01').set('text', '');
						//Inject the new DOM elements into the results div.
						$('div_files_type_01').adopt(html);
					},
					//Our request will most likely succeed, but just in case, we'll add an
					//onFailure method which will let the user know what happened.
					onFailure: function() {
						$('div_files_type_01').set('text', 'The request failed.');
					}
				}).send('inv_id='+t_inv_id);
			},
			onAllComplete: function(current) {
				// this.onAllComplete(current);
				$('slide_in_file_type_01').slide_me.slideOut();
			}
		});
	
		/**
		 * Various interactions
		 */
	
		$('browse_file_type_01').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() {
			swiffy.upload();
			return false;
		});
	*/
	}

});
