window.addEvent('domready', function()
{
	
	var form_items = $$('div.fieldbox');
	form_items.each(function(element, index)
	{	
		  var theDesc = element.getElement('.field_desc');
		  var theLabel = element.getElement('label');
		  var theInput = element.getElement('input');
		  var msg = 'Fill out the form on the left to gain access to the upload form. ';
		  $('msg').innerHTML = msg;
		  
		  if(theInput == null)
		  {
				var theInput = element.getElement('textarea');	
				if(theInput == null)
				{
						var theInput = element.getElement('select');	
				}
		  }
		  
		  theInput.addEvents({
				'focus': function(){
					  $('msg').innerHTML = theDesc.innerHTML
				},
				
				'blur': function(){
					 $('msg').innerHTML = msg;
				}
		  });
	});

	
	var links = $$('.goto');
	links.each(function(element, index)
	{
		element.addEvent('click',function(event){
			   event.stop();
			   document.location=element.get('link');
			});
	});
	
	new FormCheck('step');
	
	if ($('artworkfiles'))
	{
		$('artworkfiles').addEvent('change',function(event)
		{
			   event.stop();
			   
			   $('submit').disabled= false;
			   $('artworkfiles_con').empty();
			   fonts = Array();
			   
			   
			   for(i=0; i < parseFloat($('artworkfiles').value); i++ )
			   {
			    
				wrap = new Element('div',
				{
					'class': 'artworkinfo'
				});
				
			    div = new Element('div',
				{
					'class': 'fieldbox'
				});
				
				div2 = new Element('div',
				{
					'class': 'fieldbox'
				});
				
				div3 = new Element('div',
				{
					'class': 'fieldbox'
				});
				
				div4 = new Element('div',
				{
					'class': 'fieldbox'
				});
				
				div5 = new Element('div',
				{
					'class': 'fieldbox'
				});
				
				div6 = new Element('div',
				{
					'class': 'fieldbox'
				});
				
				div7 = new Element('div',
				{
					'class': 'fieldbox'
				});
				
				label = new Element('label',
				{
					'html': 'Title:'
				});
				
				title = new Element('input',
				{
					'type': 'text',
					'name': 'title_' + i,
					'class': "validate['required']"
				});
				
				size = new Element('label',
				{
					'html': 'Artwork Size:'
				});
				
				var width = new Element('input',
				{
					'type': 'text',
					'class': "half validate['required']",
					'name': 'width_' + i
				});
				
				var x = new Element('span',
				{
					'html': 'x',
					'class': 'half'
				});
				
				var height = new Element('input',
				{
					'type': 'text',
					'class': "half validate['required']",
					'name': 'height_' + i
				});
				
				var variationsl = new Element('label',
				{
					'html': 'Variations:'
				});
				
				var variations = new Element('input',
				{
					'type': 'text',
					'name': 'variations_' + i,
					'class': "validate['required']"
				});
				
				var scalel = new Element('label',
				{
					'html': 'Scale Percentage:'
				});
				
				var scale = new Element('input',
				{
					'type': 'text',
					'value': '100%',
					'name': 'scale_' + i,
					'class': "validate['required']"
				});
				
				var filetypel = new Element('label',
				{
					'html': 'Filetype:'
				});
				
				var filetype = new Element('select',
				{
					'type': 'text',
					'name': 'filetype_' + i,
					'class': "validate['required']"
				});
				
				filetype.options.add(new Option('', ''))
				filetype.options.add(new Option('Flattened Image (e.g jpeg, tiff etc)','Image'))
				filetype.options.add(new Option('PDF (preferred format)', 'PDF'))
				filetype.options.add(new Option('Encapsulated Postscript', 'EPS'))
				filetype.options.add(new Option('Corel Draw','CDR'))
				filetype.options.add(new Option('Adobe Photoshop','PS'))
				filetype.options.add(new Option('Adobe Illustrator','AI'))
				
				var fontsl = new Element('label',
				{
					'html': 'Fonts:'
				});
				
				fonts = new Element('select',
				{
					'type': 'text',
					'name': 'fonts_' + i,
					'class': "validate['required'] fonts"
				});
								
				fonts.options.add(new Option('', ''))
				fonts.options.add(new Option('Embedded', 'Embedded'))
				fonts.options.add(new Option('Converted to Curves', 'Converted to Curves'))
				fonts.options.add(new Option('Flattened', 'Flattened'))
				fonts.options.add(new Option('Unknown', 'Unknown'))
				
				
				
				
				var coloursl = new Element('label',
				{
					'html': 'Colours:'
				});
				
				var rgb = new Element('input',
				{
					'type': 'checkbox',
					'name': 'rgb_' + i
				});
				
				var rgbl = new Element('label',
				{
					'html': 'RGB'
				});
				
				rgbl.adopt(rgb);
				
				var cmyk = new Element('input',
				{
					'type': 'checkbox',
					'name': 'rgb_' + i
				});
				
				var cmykl = new Element('label',
				{
					'html': 'CMYK'
				});
				
				cmykl.adopt(cmyk);
				
				var spot = new Element('input',
				{
					'type': 'checkbox',
					'name': 'rgb_' + i
				});
				
				var spotl = new Element('label',
				{
					'html': 'SPOT'
				});
				
				spotl.adopt(spot);
				
				div6.adopt(coloursl,rgbl,cmykl,spotl)
				
				div.adopt(label,title);
				
				div2.adopt(size,width,x,height);
				
				div3.adopt(variationsl,variations);
				
				div4.adopt(fontsl,fonts);
				
				div5.adopt(filetypel,filetype);
				
				div7.adopt(scalel,scale);
				
				wrap.adopt(div,div2,div3,div7,div5,div4,div6);
				
				$('artworkfiles_con').adopt(wrap);
				p = $('artworkfiles_con').getElement('p');
				
				if (p)
				{
					p.destroy();
				}
				
				new FormCheck('step2');
				
				
			   }
			   
			   $$('.fonts').each(function(element,index)
			   {
					element.addEvent('change',function(event)
					{
						
						if(element.options.selectedIndex == 1)
						{
						   SqueezeBox.initialize({
								size: {x: 250, y: 225}
							});

						
							 SqueezeBox.open('embedded.html'); 
						}
					});
			   });

			   
			   
		});
	}
	
});