$(function() {
//  $('.error').hide();  
  $('input.input', 'textarea.textarea').css({backgroundColor:"#DDDDDD", borderColor:"#666666"});
  $('input.input', 'textarea.textarea').focus(function(){
    $(this).css({backgroundColor:"#FFFFFF", borderColor:"#202020"});
  });
  $('input.input', 'textarea.textarea').blur(function(){
    $(this).css({backgroundColor:"#DDDDDD", borderColor:"#666666"});
  });


$(".input[@type='text']").change( function() {
  var current_id = this.id;
//  var value = $(this).val();
  var Isvisible = $('div#'+current_id+'_error').is(':visible');
  value = $(this).val();
  if (value != '') if (Isvisible) $('div#'+current_id+'_error').slideUp("fast");
});


  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').slideUp("fast");
		
  var name = $("input#name").val();
		var phone = $("input#phone").val();	  
		var email = $("input#email").val();
		var website = $("input#website").val();    
		var message = $('textarea[name="message"]').val();
			  
		if (name == "") {
      $("div#name_error").slideDown();
      $("input#name").focus();
      return false;
    }

		if (phone == "") {
      $("div#phone_error").slideDown();
      $("input#phone").focus();
      return false;
    }

		if (email == "") {
      $("div#email_error").slideDown();
      $("input#email").focus();
      return false;
    }

		if (message == "") {
      $("div#message_error").slideDown();
      $("textarea#message").focus();
      return false;
    }    
		
		var dataString = 'name=' + name + '&email=' + email + '&phone=' + phone + '&website=' + website + '&message=' + message;
//		alert (dataString);return false;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
          $('.error').slideUp("fast", function() {
        $('#contact_form').html("<div id='success_message'></div>");
        $('#success_message').html("<h2>Message successfully sent</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()

       
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
        

        });
      }
     });
    return false;
	});
	
});
runOnLoad(function(){
  $("input#name").select().focus();
});