// JavaScript Document

		window.addEvent('domready', function(){
			//-vertical
			
			if ( $('metaedit'))
			{
				var mySlide = new Fx.Slide('metaedit');
				mySlide.hide();			
				$('toggle').addEvent('click', function(e){
					e = new Event(e);
					mySlide.toggle();
					e.stop();
				});
			}
			
			if ( $('box_edit') )
			{
				var editSlide = new Fx.Slide('box_edit');
				var noeditSlide = new Fx.Slide('box_no_edit');
				editSlide.hide();	
				$('boxedit').addEvent('click', function(e){
					e = new Event(e);
					editSlide.toggle();
					noeditSlide.toggle();
					e.stop();
				});
			}
						
			if ( $('product_id') )
			{
				$('product_id').hide();
				
				$('JobJobType').addEvent('change',function(){
				
				if($('JobJobType').value == 'proof')
				{
					$('product_id').show();
				}
				
				if($('JobJobType').value == 'print')
				{
					$('product_id').hide();
				}
				
				});
			}
			

	// our uploader instance 
	if ( $('uploader') )
	{
	var up = new FancyUpload2($('status'), $('list'), { // options object
		// we console.log infos, remove that in production!!
		verbose: true,
		
		timeLimit: 10000,
		
		// url is read from the form, so you just have to change one place
		url: $('uploader').action,
		
		// path to the SWF file
		path: '/js/fu/Swiff.Uploader.swf',
		
		// remove that line to select all files, or edit it, add more items
		typeFilter: {
			'Images (*.jpg, *.jpe, *.jpeg, *.tif, *.tiff)': '*.jpg; *.jpe; *.jpeg; *.tif; *.tiff'
		},

		// duplicate filenames
//		allowDuplicates: true;
		
		// this is our browse button, *target* is overlayed with the Flash movie
		target: 'browse',
		
		// graceful degradation, onLoad is only called if all went well with Flash
		onLoad: function() {
			$('status').removeClass('hide'); // we show the actual UI
			//$('fallback').destroy(); // ... and hide the plain form
			
			// We relay the interactions with the overlayed flash to the link
			this.target.addEvents({
				click: function() {
					return false;
				},
				mouseenter: function() {
					this.addClass('hover');
				},
				mouseleave: function() {
					this.removeClass('hover');
					this.blur();
				},
				mousedown: function() {
					this.focus();
				}
			});

			// Interactions for the 2 other buttons
			
			$('clear').addEvent('click', function() {
				up.remove(); // remove all files
				
				//remove the option ils
				$$('.file-options').destroy();
				
				return false;
			});

			$('upload').addEvent('click', function() {
				up.start(); // start upload
				return false;
			});
		},
		
		
		onBeforeStart: function() {
			
			up.setOptions({
				data: $('uploader').toQueryString()
			});
		},
		
		onComplete: function() {
			window.location.href='/jobs/finish/' + $('job_id').value;
		},
		
		
		// Edit the following lines, it is your custom event handling
		
		/**
		 * Is called when files were not added, "files" is an array of invalid File classes.
		 * 
		 * This example creates a list of error elements directly in the file list, which
		 * hide on click.
		 */ 
		onSelectFail: function(files) {
			files.each(function(file) {
				new Element('li', {
					'class': 'validation-error',
					html: file.validationErrorMessage || file.validationError,
					title: MooTools.lang.get('FancyUpload', 'removeTitle'),
					events: {
						click: function() {
							this.destroy();
						}
					}
				}).inject(this.list, 'top');
			}, this);
		},
		
		onSelectSuccess: function(files) {
			up.onSelectSuccess();
			var i = 0;
			files.each(function(file) {
				if($('job_type').value == 'proof')
				{
					var cubs = file.element.getChildren();
					for(var i = 2; i < 6; i++) 
					{
						cubs[i].setStyle('display', 'none');
					}
				}
				if(file.name.search(/&/) > 0 || file.name.search(/\+/) > 0)
				{
					new Element('li', {
						'class': 'validation-error',
						html: 'Cant have & or + in filename',
						title: MooTools.lang.get('FancyUpload', 'removeTitle'),
						events: {
							click: function() {
								this.destroy();
							}
						}
					}).inject(this.list, 'top');
				}
			}, this);
		},
		
		/**
		 * This one was directly in FancyUpload2 before, the event makes it
		 * easier for you, to add your own response handling (you probably want
		 * to send something else than JSON or different items).
		 */
		onFileSuccess: function(file, response) {
			var json = new Hash(JSON.decode(response, true) || {});
			var children = file.element.getChildren();
			for(var i = 0; i < 9; i++) 
			{
				children[i].setStyle('display', 'none');
			}
			
			if (json.get('status') == '1') {
				file.element.addClass('file-success');
			file.info.set('html', '<strong>Image was uploaded:</strong> (' + json.get('width') + ' x ' + json.get('height') + 'px, <em>' + json.get('mime') + '</em>)');
			} else {
				file.element.addClass('file-failed');
				file.info.set('html', '<strong>An error occured:</strong> ' + (json.get('error') ? (json.get('error') + ' #' + json.get('code')) : response));
			}
		},
		
		/**
		 * onFail is called when the Flash movie got bashed by some browser plugin
		 * like Adblock or Flashblock.
		 */
		onFail: function(error) {
			switch (error) {
				case 'hidden': // works after enabling the movie and clicking refresh
					alert('To enable the embedded uploader, unblock it in your browser and refresh (see Adblock).');
					break;
				case 'blocked': // This no *full* fail, it works after the user clicks the button
					alert('To enable the embedded uploader, enable the blocked Flash movie (see Flashblock).');
					break;
				case 'empty': // Oh oh, wrong path
					alert('A required file was not found, please be patient and we will fix this.');
					break;
				case 'flash': // no flash 9+ :(
					alert('To enable the embedded uploader, install the latest Adobe Flash plugin.')
			}
		}
		
	});
	}
			
}); 



