$(function() {
	$('.error').hide();
	$('input.text-input').css({backgroundColor:"#FFFFFF"});
	$('input.text-input').focus(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
		$(this).css({color:"#000000"});
	});
	$('input.text-input').blur(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
		$(this).css({color:"#000000"});
	});
	$('textarea').css({backgroundColor:"#FFFFFF"});
	$('textarea').focus(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
		$(this).css({color:"#000000"});
	});
	$('textarea').blur(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
		$(this).css({color:"#000000"});
	});

	$(".button").click(function() {
		// validate and process form
		// first hide any error messages
		$('.error').hide();
		
		var name = $("input#name").val();
		if (name == "") {
			$("label#name_error").show();
			$("input#name").focus();
			return false;
		}
		var email = $("input#email").val();
		if (email == "") {
			$("label#email_error").show();
			$("input#email").focus();
			return false;
		}
		var comment = $("textarea#comment").val();
		if (comment == "") {
			$("label#comment_error").show();
			$("input#comment").focus();
			return false;
		}

		var dataString = 'name='+ name + '&email=' + email + '&comment=' + comment;
		//alert (dataString);return false;

		$.ajax({
			type: "POST",
			url: "contact/submit",
			data: dataString,
			success: function() {
				$('#contact_form').html("<div id='message'></div>");
				$('#message').html("<h2>Thank you for your contact</h2>")
				.append("<p>We will be in touch soon.</p>")
				.hide()
				.fadeIn(1500, function() {
					$('#message').append("<img id='checkmark' src='http://static.avfestival.co.uk/images/2010/contact/check.png' />");
				});
			}
 		});
		return false;
	});
});
runOnLoad(function(){
	$("input#name").select().focus();
});
