$(function() {
	
	//----------------------------
	//FORM ACTIONS
	//----------------------------
	
	// Hide Error Message On Load
	$('.error').hide();
	
	// Set BG color on inputs
	$('input.text-input').css({backgroundColor:"#FFFFFF"});
	$('textarea').css({backgroundColor:"#FFFFFF"});
	
	// Focused styles
	$('input.text-input').focus(function(){
		$(this).css({backgroundColor:"#EFEFEF"});
	});
	$('textarea').focus(function(){
		$(this).css({backgroundColor:"#EFEFEF"});
	});
	
	// Blurred styles
	$('input.text-input').blur(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
	});
	$('textarea').blur(function(){
		$(this).css({backgroundColor:"#FFFFFF"});
	});

	
	// validate and process form
	$(".button").click(function() {
	
	// first hide any error messages
    $('.error').hide();
	
	// display error if no name input
	if ($("input#name").val() == "") {
      $("label#name_error").fadeIn(1500);
      $("input#name").focus();
      return false;
    }
	
	// display error if no email input
	var emailVal = $("#email").val();
	if ($("#email").val() == "") {
      $("label#email_error").fadeIn(1500);
      $("input#email").focus();
      return false;
    }
	
	// set data string for php processor
	var dataString = $("#contact_form form").serialize();
	//alert (dataString);return false;
	
	// send data for processing and display success message
	$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<h3>Thank You!</h3>")
        .append("<p>I will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
	
	
	
	//----------------------------
	//PORTFOLIO ACTIONS
	//----------------------------
	$(".workThumbs a").click(function() {
		//Get large image ID
		var imageIDToReplace = '#' + $(this).children("img").attr("alt");
		
		//Get new image path
		var largePath = $(this).attr("href");
		
		//Swap image
		$(imageIDToReplace).fadeOut(function() {
			$(this).attr({ src: largePath });
			$(this).fadeIn();
		});
		
		return false;
	});
	
	
});
/*runOnLoad(function(){
  $("input#name").select().focus();
});*/
