/* Author: roywalker.me

*/

/*** Get in touch Modal Box ****/

// Infield labels for inputs
$(document).ready(function(){
  $("#getintouch legend label").inFieldLabels();
});

// Open the modal
$(".getInTouchModal").click(function(){
	$("#overlay, #getintouch").fadeIn(500);
	
	return false;
});

// Close the modal
$("#overlay, .closeModal").click(function(){
	$("#overlay, #getintouch").fadeOut(500);
	if ($("#getintouch p.error").is(":visible")){
		$("#getintouch p.error").slideToggle("400");
		$("#getintouch").animate({ height: '-=30' }, 400);
	}
	
	return false;
});

// Submit button
$("#getintouch form input[type=submit]").click(function(){
	var emailRegex = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	
	var email = $('#email').val();
	var name = $('#name').val();
	var subject = $('#subject').val();
	var comment = $('#comment').val();
	var blogpath = $('#blogpath').val();
	
	if(name && email && subject && comment && emailRegex.test(email)){
			
			$('#getintouch legend, #getintouch p.info, #getintouch .hideMeWhenDone').fadeTo('slow', ".5");
			
			var dataString = 'action=contactForm&'+'email='+ email +'&name='+ name + "&comment=" + comment + "&subject=" + subject;
		
			$.ajax({
				url:"/wp-admin/admin-ajax.php",
				type	: 'post',
				cache: false,
				data: dataString,
				success	: function(data){
					
					$('#getintouch legend, #getintouch p, #getintouch .hideMeWhenDone').fadeOut("slow");
					$('#getintouch .itsdone').fadeIn(1000);
					
				}
			});


	}else if ($("#getintouch p.error").is(":hidden")){
		$("#getintouch p.error").slideToggle("400");
		$("#getintouch").animate({ height: '+=30' }, 400);
	}
	
	return false;
});


/*** Select-based nav for Mobile ***/

$(".forMobile").change(function(){
	goTo = $(this).val();
	
	if(goTo == "/services"){
		window.location = "/services";
	}else if(goTo == "/team"){
		window.location = "/team";
	}else if(goTo == "/blog"){
		window.location = "/blog";
	}else if(goTo == "openModal"){
		$(window).scrollTop(0);
		$(".getInTouchModal").click();
	}
	
	$("#topMobileNav option:eq(0), #bottomMobileNav option:eq(0)").attr("selected", "selected");
	
});
