$(function(){
  $('.error').hide();

  $('input').css({backgroundColor:"transparent"});
  $('input').focus(function(){
    $(this).css({backgroundPosition:"0 -45px"});
  });
  
  $('input').blur(function(){
    $(this).css({backgroundPosition:"0 -87px"});
  });
  
  $('textarea').focus(function(){
    $(this).css({backgroundPosition:"0 -148px"});
  });
    
  $('textarea').blur(function(){
    $(this).css({backgroundPosition:"0 0"});
  });

  $(".button").click(function() {
    $('.error').hide();
		
    var name = $("input#name").val();
    if(name == ""){
      $("label#name_error").show();
      $("input#name").focus();
      return false;
    }

    var email = $("input#email").val();
    var regexp_email=/^([a-zA-Z0-9._\-]+)@([a-zA-Z0-9.-]+).([a-zA-Z]{2,4})$/
    if((email == "") || (!regexp_email.test(email))){
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }

    var phone = $("input#phone").val();
    if(phone == ""){
      $("label#phone_error").show();
      $("input#phone").focus();
      return false;
    }
    
    var comment = $("textarea#comment").val();
    if(comment == ""){
      $("label#comment_error").show();
      $("textarea#comment").focus();
      return false;
    }

    var dataString = 'name='+ name + '&email=' + email + '&phone=' + phone + '&comment=' + comment;
    $.ajax({
      type: "POST",
      url: "contact.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h2>Thank you!</h2><h2>Your message has been successfully sent.</h2>")
        .append("<p>I will be in touch with you soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
    });

    return false;

  });
});
