$(document).ready(function() {
	$("figure").click(function() {
		if($(this).width() == 310) {
			
			$(this).siblings("figure").animate({
			    width: ['310px', 'linear'],
			  }, 500, 'linear', function() {
			  		$(this).siblings("figure").children("img").hide();
			  		
			  });		
			
			$(this).children("img").show();
			$(this).animate({
			    width: ['100%', 'linear'],
			  }, 500, 'linear', function() {
			  $(this).children("img").show();
			  });	
			  
		} else {

				$(this).animate({
				    width: ['310px', 'linear'],
				  }, 500, 'linear', function() {
				  		 $(this).children("img").hide();
				  });			
		}
	});
	

	$("a[href=#top]").click(function() {
		$("html, body").animate({
			scrollTop: $($(this).attr("href")).offset().top + "px"
		}, {
			duration: 500,
			easing: "swing"
		});
		return false;
	});
	
	$('article.excerpt').click(function() {
	
		window.location = $(this).children('h2').children('a').attr("href");
	});
		
	$(".various").fancybox({
		
			closeClick	: false,
			openEffect	: 'elastic',
			closeEffect	: 'elastic',
			openEasing : 'easeOutBack',
			closeEasing : 'easeInBack'
		});	
		
		$('form').submit(function() {
			if($(this).children("fieldset").children(".error.clearbox").length > 0 || $(this).children(".error.clearbox").length > 0) {
				return false;
			}
			
			return true;
		});
		 
		 $('input[aria-required=true], textarea, input.required').keyup(function() {
			if($(this).val().trim() == "") {
				$(this).closest('.clearbox').removeClass('good');
				$(this).closest('.clearbox').addClass('error');
			}
		           
		 	else if($(this).attr("type") == "email") {
			 var regex = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/i;
				 
				 if(!regex.test($(this).val())) {
				   $(this).closest('.clearbox').removeClass('good');
				   $(this).closest('.clearbox').addClass('error');
				 } else {
				 	$(this).closest('.clearbox').addClass('good');
				    $(this).closest('.clearbox').removeClass('error');
				 }
			} else {
				$(this).closest('.clearbox').addClass('good');
				$(this).closest('.clearbox').removeClass('error');
			}
		 });	
});
