
	
	var SearchBox = Class.create();

	SearchBox.prototype = {
		initialize: function() {
		},
		
		start: function() {
			if($('searchText'))
			{
				$('searchText').observe('focus', this.toggleBox.bindAsEventListener(this));
				$('searchText').observe('blur', this.toggleBox.bindAsEventListener(this));
			}
		},
		
		toggleBox: function(ev, el) {
			window.setTimeout(function(){$('contactInfoPopup').toggle();},300);
		}
	};

	var searchBox = new SearchBox();
	
	
	var FileUploader = Class.create();
	/*
	 * Inspired by this: http://www.matlus.com/html5-file-upload-with-progress/
	 */
	FileUploader.prototype = {
		initialize: function() {
			this.supportsXHR2 = (new XMLHttpRequest().upload) ? true : false;
			
		},
		
		submit: function(form) {
			$('formWarning').hide();
			
			if(!Form.check($(form)))
				$('formWarning').show();
			else
			{
				if(this.supportsXHR2)
					this.upload();
				else
					$(form).submit();
			}
		},
		
	    upload: function() 
		{
			var fd = new FormData();
			fd.append('name', $F('your_name'));
			fd.append('email', $F('email'));
			fd.append('phone', $F('phone'));
			fd.append("file", document.getElementById('file').files[0]);
			var xhr = new XMLHttpRequest();
			xhr.upload.addEventListener("progress", this.uploadProgress, false);
			xhr.addEventListener("load", this.uploadComplete, false);
			xhr.addEventListener("error", this.uploadFailed, false);
			xhr.open("POST", ajaxUrl+'?action=send-file-upload');
			xhr.send(fd);
			
			$('uploadButton').disable();
			showLoading('progressBar');
			$('progressBar').show();
		},

	    uploadProgress: function (evt) 
		{
			$('progressBar').show();
			if (evt.lengthComputable) 
			{
				var percentComplete = Math.round(evt.loaded * 100 / evt.total);
				if(percentComplete > 5)
				{
					$('progressBar').style.width = percentComplete+'%';
					$('progressBar').update(percentComplete+'%');
				}
					
			}
			else 
			{
				$('progressBar').style.width = '100%';
				$('progressBar').update('Uploading...');
			}
	    },

	    uploadComplete: function (evt) 
		{
			/* This event is raised when the server send back a response */
			if(evt.target.responseText == 'true')
			{
				// $('progressBar').update('Done.');
				$('fileForm').replace("<p><strong>Thank you!</strong><br />Your file has been uploaded successfully.</p>");
			}
			else
			{
				$('uploadButton').enable();
				alert("Sorry, but there's been a problem uploading your file. Please try again.");
			}
	    },

	    uploadFailed: function(evt) 
		{
			$('uploadButton').enable();
			alert("Sorry, but there's been a problem uploading your file. Please try again.");
	    }
	};

	var fileUploader = new FileUploader();
	
	

