$(document).ready(function() {
  $('.show-contact-form')
    .click(function() {
      $('#contact-form')
        .each(function() {
          $(this)
            .modal({
              overlayClose: true,
              overlayCss: { backgroundColor: '#fff' }
            });
          
          $('#contact_name').hint('name');
          $('#contact_email').hint('email');
          $('#contact_phone').hint('phone');
        })
        .find('a')
          .click(function() {
            $.modal.close();
          });
    });

  $('form input.submit')
    .click(function() {
      var name    = $('#contact_name').val();
      var email   = $('#contact_email').val();
      var phone   = $('#contact_phone').val();
      var content = $('#contact_tell_us_more').val();
      
      $.ajax({
        type: "POST",
        url:  "deliver_contact_form.php",
        data: "name=" + name + "&email=" + email + "&phone=" + phone + "&content=" + content,
        success: function() {
          $('#contact-form .choices')
            .html('Your message has been sent, thanks!<br /><a href="#">Close</a>')
            .css({'text-align': 'center', 'font-size': '0.9em', 'color': "#888"});
          
          $('#contact-form .choices a')
            .click(function() {
              $.modal.close();
            })
          
          $('form .fields')
            .slideUp(500);
        }
      });
      
      $('#spinner').show();
      $('#contact_name').attr('disabled', true);
      $('#contact_email').attr('disabled', true);
      $('#contact_phone').attr('disabled', true);
      $('#contact_tell_us_more').attr('disabled', true);
      $('form input.submit').attr('disabled', true);
      return false;
    });
});
