/* Author: Collectively 2011 */

function activate(i) {
	$('nav ul li').removeClass('active');
	$('#description').fadeOut('fast');
	$('#dataServices').fadeOut('fast');
	$('#dataServicesAll').fadeOut('fast');
	$('#dataAbout').fadeOut('fast');
	$('#dataTeam').fadeOut('fast');
	$('#dataContact').fadeOut('fast');

	$(i).addClass('active');
	$('#data'+$(i).attr('id')).delay(200).fadeIn();
}

$(document).ready(function(){
	
	$('nav ul li').hover(function(){$(this).addClass('activeHover');}, function(){$(this).removeClass('activeHover');} );
	
	$('nav ul li a').click(function() {
		activate($(this).parent());
	});

	$('.icons .icon').click(function() {
		//$('.service').fadeOut('fast');
		//$(this).parent('.service').delay(200).fadeIn('fast', function() {
		//	$(this).children('p').fadeIn('fast');
		//});
		$('.seeAll').fadeIn('fast');

		$('.icons').isotope({ 
			itemSelector: '.service',
			filter: $(this).parent() 
		});
		$(this).parent().children('p').fadeIn('slow');
	});
	
	$('.seeAll').click(function() {
		$('.seeAll').fadeOut('fast');
		$('.service p').hide();
		$('.icons').isotope({ 
			itemSelector: '.service',
			filter: '*'
		});
	});


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

		// validate and process form
		// first hide any error messages
		$('.error').hide();
		
		var name = $("input#name").val();
		if (name == "") {
		  $('#status').html("<h2 class='error'>Please fill out all fields.</h2>")
		  $("input#name").focus();
		  return false;
		}
		var email = $("input#email").val();
		if (email == "") {
		  $('#status').html("<h2 class='error'>Please fill out all fields.</h2>")
		  $("input#email").focus();
		  return false;
		}
		var message = $("textarea#message").val();
		if (message == "") {
			$('#status').html("<h2 class='error'>Please fill out all fields.</h2>")
			$("textarea#message").focus();
			return false;
		}
		
		var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
		//alert (dataString);return false;
		
		$.ajax({
		  type: "POST",
		  url: "/process-email.php",
		  data: dataString,
		  success: function() {
			$('#status').html("<h2>Thanks for your interest. We'll be in touch soon.</h2>")
		  }
		});
		
		return false;
	});

});



