$(document).ready(function() {
	var grid = window.location.hash;
	if (grid == "#grid") {
    $('body').addClass('grid');
};
 });
 
$(document).ready(function() {
	
	$("#showAuthors").click(function(e) {
		
		var $olderPosts = $('#older-posts');
		var $showCategories = $('#showCategories');
			
		$olderPosts.addClass('loading');
		$showCategories.removeClass('selected');
		$(this).addClass('selected');
		
		
		$.ajax({
			url: adminurl, 				// Global variable set in header.php
			type: 'GET',				// For performance reasons use GET
			dataType: 'html', 			// Data type we expect to get back from request
			
			data: {						// Parameters to send
				action: 'do_ajax_action',
				request: 'get_authors'
			},
			
			success: function(data, textStatus, XMLHttpRequest){	// Callback function
				$olderPosts.removeClass('loading');
				showAuthors(data);
			}		
		});
				
		e.preventDefault();
		
		return false;
	});
	
});

function showAuthors(data)
{
	$('#older-posts').replaceWith(data);
}

$(document).ready(function() {
	
	$("#showCategories").click(function(e) {
		
		var $olderPosts = $('#older-posts');
		var $showAuthors = $('#showAuthors');
			
		$olderPosts.addClass('loading');
		$showAuthors.removeClass('selected');
		$(this).addClass('selected');
		
		$.ajax({
			url: adminurl, 				// Global variable set in header.php
			type: 'GET',				// For performance reasons use GET
			dataType: 'html', 			// Data type we expect to get back from request
			
			data: {						// Parameters to send
				action: 'do_ajax_action',
				request: 'get_categories'
			},
			
			success: function(data, textStatus, XMLHttpRequest){	// Callback function
				$olderPosts.removeClass('loading');
				showCategories(data);
			}		
		});
				
		e.preventDefault();
		
		return false;
	});
	
});

function showCategories(data)
{
	$('#older-posts').replaceWith(data);
}

// Setting the font-size of quotes on index.php dynamically from http://css-tricks.com/set-font-size-based-on-word-count/

$(function(){
	$(".home .category-quote h3").each(function(){
	    var $quote = $(this);
	
	    var $numWords = $quote.text().split(" ").length;
	
	    if (($numWords >= 2) && ($numWords < 10)) {
	        $quote.css("font-size", "42px");
	        $quote.css("line-height", "1em");
	    }
	    else if (($numWords >= 10) && ($numWords < 12)) {
	        $quote.css("font-size", "32px");
	        $quote.css("line-height", "1.2em");
	    }
	    else if (($numWords >= 12) && ($numWords < 16)) {
	        $quote.css("font-size", "26px");
	        $quote.css("line-height", "1.2em");
	    }
	    else if (($numWords >= 16) && ($numWords < 32)) {
	        $quote.css("font-size", "22px");
	        $quote.css("line-height", "1.2em");
	    }
	    else if (($numWords >= 32) && ($numWords < 40)) {
	        $quote.css("font-size", "16px");
	    }
	    else {
	        $quote.css("font-size", "16px");
	    }    
	
	});
});
