jQuery(function($) {
	
	// Clear Form on Submit
	$.fn.clearForm = function() {
	  return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
		  return $(':input',this).clearForm();
		if (type == 'text' || tag == 'textarea')
		  this.value = '';
	  });
	};

	// Contact Form 
  $('#contactForm').submit(function() {
  	// Form Variables
		var errors = 0;
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;		
  	// Remove Error Class
  	$('input, textarea').removeClass('validation-failed');
  	
  	// Validate Name
  	if ($("#cname").val() == "" || $("#cname").val() == 'Your Name') {
	  	$("#cname").addClass("validation-failed");
	  	errors++;
	  }			
		// Validate Email
		if(!reg.test($("#cemail").val())) {
      $("#cemail").addClass("validation-failed"); 
      errors++;
    }
    // Validate Comments
    if ($("#ccomments").val() == "" || $("#ccomments").val() == 'Tell us about your project') {
	  	$("#ccomments").addClass("validation-failed");
	  	errors++;
	  }
	  if (errors !== 0) {
			return false;
    }
    // Ajax Submit
    $.ajax({
      data: $(this).serialize(),
      url: this.action,
      timeout: 2000,
      error: function() {
        console.log("Failed to submit");
      },
      success: function() {
        $('#thank_you_right').slideDown(500, function() {
          $('#thank_you_right');
        });
        $('#contactForm').clearForm();
      }
    })
    return false;
  })
  // End Contact Form
})

jQuery(document).ready(function($) {
	// Replace Form Values
	$(function() {
		$.fn.clearOnFocus = function(){
			return this.focus(function(){
			  this.value = this.value === this.defaultValue ? '' : this.value;
			}).blur(function(){
			  this.value = this.value === '' || /^\s+$/.test(this.value) ? this.defaultValue : this.value;
			});
		}
		$(function(){
			$('input, textarea').clearOnFocus()
			.each(function(){
				var input = $(this);
				input.parents('form:eq(0)').submit(function(){
				   return input[0].value !== input[0].defaultValue;
				});
			});
		});
	});
});
// End Document Ready