var $j = jQuery.noConflict();

$j(function() {
  $j('.error').hide();

  $j(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $j('.error').hide();
		var inputs = $j("#contact_form input, #contact_form textarea");
		var input_array = {};
		
		inputs.each(function() {
			input_array[this.name] = this.value;
		});
		
		if(!input_array.email.trim().match(/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/)) {
		alert('Check your email, it looks to be invalid.');
		return false;
		}

		$j.ajax({
      type: "POST",
      url: "/wp-content/themes/vaynermedia2/process.php",
      data: input_array,
	   error: function(){
	        alert('Error submitting!');
	    },
      success: function() {
        $j('#contact_form').html("<div id='message'></div>");
        $j('#message').html("<h2>Contact Form Submitted!</h2>")
        .append("<p>We will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $j('#message').append("<img id='checkmark' src='/wp-content/themes/vaynermedia2/images/check.png' />");
        });
      }
     });
    return false;
	});
});

