$(document).ready(function() {

	// Set margin on middle project Preview		
	$(".Preview:eq(1)").css("margin", "0px 28px 30px 28px");
	$(".Preview:eq(4)").css("margin", "0px 28px 30px 28px");
	$(".Preview:eq(7)").css("margin", "0px 28px 30px 28px");
	
	// Hover changes on Preview
	$(".Preview").hover(function() {
		$(this).children(".PreviewHover").fadeIn(200);
		$(this).find("h1").animate({ color: "#1c98a0" }, 200);
	},function() { 
	    $(this).children(".PreviewHover").fadeOut(200);
	    $(this).find("h1").animate({ color: "#333333" }, 200);
	});


	// Call Popeye Image effects
    $("#Popeye").popeye();
    
    
    // Contact Form
    $('#contact-form').jqTransform();

	$("button").click(function(){

		$(".formError").hide();

	});

	var use_ajax=true;
	$.validationEngine.settings={};

	$("#contact-form").validationEngine({
		inlineValidation: false,
		promptPosition: "topRight",
		success :  function(){use_ajax=true},
		failure : function(){use_ajax=false;}
	 })

	$("#contact-form").submit(function(e){			
			if(use_ajax)
			{
				$('#loading').css('visibility','visible');
				$.post('submit.php',$(this).serialize()+'&ajax=1',
				
					function(data){
						if(parseInt(data)==-1)
							$.validationEngine.buildPrompt("#captcha","* Your math is incorrect.","error");
							
						else
						{
							$("#contact-form").hide('slow').after('<h2>Your message has been successfully sent.</h2><p>We will be in touch as soon as we can. Thanks!</p>');
						}
						
						$('#loading').css('visibility','hidden');
					}
				
				);
			}
			e.preventDefault();
	})
    
});