$(document).ready(function(){
	/* This code is executed after the DOM has been completely loaded */
	
	$('a.up').click(function(e){
										  
		// If a link has been clicked, scroll the page to the link's hash target:
		
		$.scrollTo(0, 200);
		e.preventDefault();
	});

	$('nav a').click(function(e){
										  
		// If a link has been clicked, scroll the page to the link's hash target:
		
		$.scrollTo( this.hash, 1200, {easing:'elasout'});
		e.preventDefault();
	});

	$.easing.elasout = function(x, t, b, c, d) {
		var s=1.70158;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};
	
	
	
	$('.error').hide();
	
	/* email */
	$("#submit").click(function(){
	
		$('.error').hide();  
		
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;

		var emailFrom = $("#emailFrom").val();
		var subject = $("#subject").val();
		var message = $("#message").val();
		
		
		
		/* error checking */
		if(emailFrom == '') {
			$("label#fromErrorBlank").show();  
		    $("input#emailFrom").focus(); 
			return false;
		} else if(!emailReg.test(emailFrom)) {
			$("label#fromErrorWrong").show();  
		    $("input#emailFrom").focus(); 
			return false;
		}
		
		if(message == '') {
			$("label#messageError").show();  
		    $("input#message").focus(); 
			return false;
		}
		
		
		var dataString = 'emailFrom='+ emailFrom + '&subject=' + subject + '&message=' + message;
		  //alert (dataString);return false;
		  $.ajax({
			type: "POST",
			url: "email/process.php",
			data: dataString,
			success: function() {
			  $('#email_form').html("<div id='message'></div>");
			  $('#message').html("<h2>Message Submitted!</h2>")
			  .append("<p>I will be in touch soon.</p>")
			  .hide()
			  .fadeIn(1500, function() {
				//$('#message').append("<img id='checkmark' src='img/check.png' />");
			  });
			}
		  });

		  return false;
  	});
  	
});

