


$(document).ready(function() {

	$('.content.home h2, .content.home h3').lettering();
	$('a.tipstricks span, .post-bucket-resources h2').lettering();

	$('#caseStudies').click(scrollDown);

        $('#resourceSubmit').click(function() {
	    $.cookie('resource', 'file');
            //alert('Cookie: '+ $.cookie("resource"));
        });
	
	$('.post-bucket-resources a:not(#caseStudies)').click(checkDownload);
	$('.post-bucket-resources-case-studies a').click(checkDownload);
	
	$('#morePosts').click(loadMorePosts);

	


});


function scrollDown() {

	var arrow = $(this).children('input[type="hidden"]').val();

	var target = $('a[name="case-studies"]').offset();
	
	$('html,body').animate({
		scrollTop: target.top-25
	}, 750);
	
		
	return false;
}

function checkDownload() {
	
	var file = $(this).children('input[type="hidden"]').val();
	
	if ($.cookie('resource')) {
		//alert('Cookie: '+ jQuery.cookie('resource'));
		window.location = file;
	} else {
		$('.action-mask').show();
		$('#resourceSignup').fadeIn();
		
	//	$('#resourceSubmit').click(function() {
		
		
		// validate signup form on keyup and submit
			
			
					
	//	});
		
		$('#resourceCancel').click(function() {
			$('.action-mask').hide();
			$('#resourceSignup').fadeOut();
		});
		
		$(document).keydown(function(e) {
		if (e.keyCode == 27) {
			
			$('.action-mask').hide();
			$('#resourceSignup').fadeOut();
		}
		});
			
	}
	
	return false;
}

function loadMorePosts() {

	var postGroup = parseInt($(this).attr('group'));
	
	if ($('.postgroup-'+postGroup).length) {
	
		$('.postgroup-'+postGroup).fadeIn();
		$(this).attr('group',postGroup+1);

		if ($('.postgroup-'+(postGroup+1)).length == 0) {
			$(this).children('span').text('No more posts to show');
			$(this).addClass('disabled');
		}
	}
	
}

