$(document).ready(function(){

	// This is for the lightbox
	$('a[rel^="prettyPhoto"]').prettyPhoto();

	// Remove pre-existing values inputs when the user clicks in them, and restore
	// the value when the user clicks out if a new value has not been entered.
	var old_val = '';
	$('.remove_input').live('focus', function() {
		old_val = $(this).prev("label").text()
		if($(this).val() == old_val) {
			$(this).val('');
		}
	}).live('blur', function() {
		if($(this).val() == '') {
			$(this).val(old_val);
		}
	});
	
	// Submit the form
	$('#contact_us').live('submit', function(e) {
		var data = '1=1&';
		e.preventDefault();
		
		$('form').find(':input').each(function(i) {
			data += '&' + this.name + '=' + this.value;
		});
		$.ajax({
			url: 'contact_process.php',
			type: 'post',
			data: data,
			success: function(result) {
				var jsonResult = jQuery.parseJSON(result);
				if (jsonResult[0] == 1) {
					//Success
					$('#contact_copy').hide('slow').after($('<div>').html(jsonResult[1]));
				}
				else {
					$('.error').show();
					$('.error').html(jsonResult[1]);
				}
				
			}
		});
	});

});
