$(function() {
	//text input styles
	$('input.text-input').focus(function(){
	  	$(this).css({backgroundImage:"none"});
	  	$(this).css({backgroundColor:"#D6EBF7"});
	});
	
	$('input.text-input').error(function(){
		$(this).css({backgroundImage:"none"});
	  	$(this).css({backgroundColor:"#FFF9A0"});
	});
	
	$('input.text-input').blur(function(){
	  	$(this).css({backgroundColor:"#FFFFFF"});
	});
	
	//text area styles
	$('textarea').focus(function(){
	  	$(this).css({backgroundImage:"none"});
	  	$(this).css({backgroundColor:"#D6EBF7"});
	});
	
	$('textarea').error(function(){
	  	$(this).css({backgroundImage:"none"});
	  	$(this).css({backgroundColor:"#F9FFC5"});
	});
	
	$('textarea').blur(function(){
	  	$(this).css({backgroundColor:"#FFFFFF"});
	});
	
	//restore the background image if left empty - NAME
	$("#form_name").click(
			function() {
				if (this.value == this.defaultValue) {
			$(this).css({backgroundImage:"none"});
			}
		}
	);
	$("#form_name").blur(
		function() {
			if (this.value == '') {
			$(this).css("background-image", "url(images/form_name.png)");  
			}
		}
	);
	
	//restore the background image if left empty - EMAIL
	$("#form_email").click(
			function() {
				if (this.value == this.defaultValue) {
			$(this).css({backgroundImage:"none"});
			}
		}
	);
	$("#form_email").blur(
		function() {
			if (this.value == '') {
			$(this).css("background-image", "url(images/form_email.png)");  
			}
		}
	);
	
	//restore the background image if left empty - SUBJECT
	$("#form_subject").click(
			function() {
				if (this.value == this.defaultValue) {
			$(this).css({backgroundImage:"none"});
			}
		}
	);
	$("#form_subject").blur(
		function() {
			if (this.value == '') {
			$(this).css("background-image", "url(images/form_subject.png)");  
			}
		}
	);
	
	//restore the background image if left empty - MESSAGE
	$("#form_message").click(
			function() {
				if (this.value == this.defaultValue) {
			$(this).css({backgroundImage:"none"});
			}
		}
	);
	$("#form_message").blur(
		function() {
			if (this.value == '') {
			$(this).css("background-image", "url(images/form_message.png)");  
			}
		}
	);
  
	//button click
  	$(".form_button").click(function() {
		// validate and process form
		// first hide any error messages
		
	var name = $("input#form_name").val();
		if (name == "") {
      $("input#form_name").error();
      return false;
    }
	
	var email = $("input#form_email").val();
		if (email == "") {
      $("input#form_email").error();
      return false;
    }
	
	var subject = $("input#form_subject").val();
		if (subject == "") {
      $("input#form_subject").error();
      return false;
    }
	
	var message = $("#form_message").val();
		if (message == "") {
      $("#form_message").error();
      return false;
    }
	
		var dataString = 'name='+ name + '&email=' + email + '&subject=' + subject + '&message=' + message;
		//alert (dataString);return false;
		
		$.ajax({
      	type: "POST",
      	url: "php/process.php",
      	data: dataString,
      	success: function() {
        $('#contact_form').html("<div id='sent'></div>");
        $('#sent')
        .hide()
        .fadeIn(1500, function() {
        $('#sent');
        });
      }
     });
    return false;
	});
});

