$(document).ready(function() {	
	
	$('nav li:last').addClass('last');
	
	$('.cases ul').isotope({
		itemSelector: 'li'
	});
	
	$('.tags a').click(function(){
		
		$('.tags li.active').removeClass('active');
		$(this).parent('li').addClass('active');
		
		var selector = $(this).attr('data-filter');
		$('.cases ul').isotope({ filter: selector });
		return false;
	});
	
	$(".cases a").hover(
	  function () {
	    $(this).stop().animate({opacity: 1}, 500);
	    $(this).children('span').animate({opacity: 1}, 500);
	  }, 
	  function () {
	    $(this).stop().animate({opacity: 0}, 500);
	    $(this).children('span').animate({opacity: 0}, 500);
	  }
	);
	
	//SIDEBAR HEIGHT ADJUST
	var infomeizure = $(".info").length;
	if (infomeizure){
	  var sidebarHeight = $('.content .sidebar').height();
	  var infoHeight = $('.content .info').height();
	  if (sidebarHeight < infoHeight) {
	  		$('.content .sidebar').height(infoHeight);
	  	} 
	}
	
	var contactmeizure = $(".contactform").length;
	if (contactmeizure){
	  var sidebarHeight = $('.content .sidebar').height();
	  var infoHeight = $('.content .contactform').height();
	  if (sidebarHeight < infoHeight) {
	  		$('.content .sidebar').height(infoHeight);
	  	} 
	}
	
	//Do what we need to when form is submitted.	
	$('#form_submit').click(function(){
	
	//Setup any needed variables.
	var input_name = $('#form_name').val(),
		input_email = $('#form_email').val(),
		input_subject = $('#form_subject').val(),
		input_message = $('#form_message').val(),
		response_text = $('#response');
		//Hide any previous response text 
		response_text.hide();
		
		//Change response text to 'loading...'
		response_text.html('Loading...').show();
		
		//Make AJAX request 
		$.post('/cms/contact-send.php', {name: input_name, email: input_email, subject: input_subject, message: input_message}, function(data){
			response_text.html(data);
		});
		
		//Cancel default action
		return false;
	});
	
});
