function displayPosts(start_count) {
	var post_num = 1; // number of posts to display at a time
	var postList = new String();
	var appendSelector = "#blog > figure";
	
	function getPosts() {
		$.ajax({
			type: "GET",
			url: "http://dmauro.tumblr.com/api/read/json?num=" + post_num,
			dataType: "script",
			success: function(){
				appendPosts();
			}
		});
	}
	
	function appendPosts(){
		postList = "";
		$(tumblr_api_read['posts']).each(function(i){
			switch (tumblr_api_read['posts'][i]['type']) {
				case 'quote':
					displayQuote(tumblr_api_read['posts'][i]);
					break;
				case 'photo':
					displayPhoto(tumblr_api_read['posts'][i]);
					break;
				case 'link':
					displayLink(tumblr_api_read['posts'][i]);
					break;
				case 'conversation':
					displayConv(tumblr_api_read['posts'][i]);
					break;
				case 'audio':
					displayAudio(tumblr_api_read['posts'][i]);
					break;
				case 'video':
					displayVideo(tumblr_api_read['posts'][i]);
					break;
				case 'regular':
					displayText(tumblr_api_read['posts'][i]);
					break;
				case 'answer':
					displayAnswer(tumblr_api_read['posts'][i]);
					break;
			}
		});
		start_count += post_num;
		if (tumblr_api_read['posts-total'] > start_count) {
			postList += '<span onClick="displayPosts(' + start_count + ')">Older Posts</span>';
		}
		if (start_count > post_num) {
			postList += '<span onClick="displayPosts(' + (start_count - post_num*2) + ')">Newer Posts</span>';
		}
		// Going to replace instead of append so we can have an error message by default
		//$(appendSelector).append(postList);
		$(appendSelector).html(postList);
		
		// Put in some script to scroll to the top of the page
	}
	
	function displayQuote(post) {
		postList += '<div class="tumblr_quote_text">' + post['quote-text'] + '</div>';
		if (post['quote-source']) {
			postList += '<div class="tumblr_quote_source">- ' + post['quote-source'] + '</div>';
		}
	}
	function displayPhoto(post) {
		postList += '<div class="tumblr_photo_thumbnail">';
		if (post['photo-link-url']) {
			postList += '<a href="' + post['photo-link-url'] + '"><img src="' + post['photo-url-500'] + '" /></a>' + '</div>';
		} else {
			postList += '<img src="' + post['photo-url-500'] + '" />';
		}
		if (post['photo-caption']) {
			postList += '<div class="tumblr_photo_caption">' + post['photo-caption'] + '</div>';
		}
	}
	function displayLink(post) {
		postList += '<div class="tumblr_link_url"><a href="' + post['link-url'] + '">';
		if (post['link-text']) {
			postList += post['link-text'];
		} else {
			postList += post['link-url'];
		}
		postList += '</a></div>';
		if (post['link-description']) {
			postList += '<div class="tumblr_link_caption">' + post['link-description'] + '</div>';
		}
	}
	function displayConv(post) {
		if (post['conversation-title']) {
			postList += '<div class="tumblr_conv_title">' + post['conversation-title'] + '</div>';
		}
		postList += '<div class="tumblr_conv_text">' + post['conversation-text'] + '</div>';
	}
	function displayAudio(post) {
		postList += '<div class="tumblr_audio_player">' + post['audio-player'] + '</div>';
		if (post['audio-caption']) {
			postList += '<div class="tumblr_audio_caption">' + post['audio-caption'] + '</div>';
		}
	}
	function displayVideo(post) {
		postList += '<div class="tumblr_video_player">' + post['video-player'] + '</div>';
		if (post['video-caption']) {
			postList += '<div class="tumblr_video_caption">' + post['video-caption'] + '</div>';
		}
	}
	function displayText(post) {
		if (post['regular-title']) {
			postList += '<div class="tumblr_text_title">' + post['regular-title'] + '</div>';
		}
		postList += '<div class="tumblr_text_body">' + post['regular-body'] + '</div>';
	}
	function displayAnswer(post) {
		postList += '<div class="tumblr_question"><p><span class="tumblr_asker">Anonymous on Tumblr asks:</span>' + post['question'] + '</p></div>';
		postList += '<div class="tumblr_answer">' + post['answer'] + '</div>';
	}
	
	getPosts();
}

