$(function(){
	$('#portfolio .article:nth-child(3n-1) h3')
		.css({ 
			'background-color' : 'rgb(219, 179, 88)' 
		});
	$('#portfolio .article:nth-child(3n) h3')
		.css({ 
			'background-color' : 'rgb(132, 68, 68)',
			'color' : 'rgb(255,255,255)' 
		});
	$('#portfolio .article:nth-child(3n) h3')
		.css({ 
			'color' : 'rgb(255,255,255)' 
		});	
	$('#portfolio .article:nth-child(3n-2) h3')
		.css({
			'background-color' : 'rgb(127, 159, 191)'
		});

	$('#blog .article:nth-child(2n-1)')
		.css({ 
			'background-color' : 'rgb(219, 179, 88)' 
		});
	$('#blog .article:nth-child(2n)')
		.css({
			'background-color' : 'rgb(127, 159, 191)'
		});
		
		
	//contact form
	var sendForm = $('#contact form').attr('action');
	// when the Submit button is clicked...
	$('#contact input#submit').click(function() {

		// Gather data from the form
		var name = $('#name').val();
		var email = $('#email').val();
		var phone = $('#phone').val();
		var comment = $('#comment').val();

		// Regular expression to check the email address
		var emailOK = /[A-Za-z0-9._-]+@[A-Za-z0-9_-]+\.([a-zA-Z.]{2,5})/.test(email);

		// series of checks to make sure name and comment are not blank
		if (name != '') { //make sure name field is not blank.
			if (comment != '') { // make sure comment field is not blank
	        	if (emailOK == true) { // make sure email passed the regex check.
	        		// if all checks as passed, run ajax object.
	        		$.ajax({
	        			type: "post",
						url: sendForm,
						data: 'name=' + name + '&email=' + email + '&comment=' + comment + '&phone='+ phone,
						error: function(){
							$('.error').hide();
							$('#sendError').slideDown('slow');
						},
						success: function () {
							$('.error').hide();
							$('.success').slideDown('slow');
							$('#name').val('');
        					$('#email').val('');
					        $('#phone').val('');
							$('#comment').val('');

						}
	        		});
	        	}
				else {
					$('.error').hide();
					$('#emailError').slideDown('slow');
				}
			}
			else {
				$('.error').hide();
				$('#commentError').slideDown('slow');
			}
		} else {
			$('.error').hide();
			$('#nameError').slideDown('slow');
		}
		// stop the form from doing its default action
		return false;
	});

		
});



