// EMPYREAN_TRANSITIONAL 
// Javascript engine for the EMPYREAN transitional front page. 
// Authored August 2011 by Corey Peterson 

var p;

$(document).ready(function() {

	init();
	
	$("#btn_prev").click(function(event) {		
		p++;
		fetchBlogEntry();
		event.preventDefault();		
	});
	
	$("#btn_next").click(function(event) {
		p--;
		fetchBlogEntry();
		event.preventDefault();
				
	});

});

function init() {
	
	p=0;
	
	$("#nav_prev p").hide();
	$("#nav_next p").hide();
	
	fetchBlogEntry();
	
} // end init 

function fetchBlogEntry() {
	
	$.ajax({

		   url: 'empyrean_homepage/blog.php?p=' + p,
		   type: 'get',
		   dataType: 'html',
		   success: function(data) {
			   
			   $("#blog_wrapper").fadeOut("fast", function() {
					
					$("#blog_wrapper").html(data);
					$(".metadata").hide();
					$("#blog_wrapper").fadeIn("fast");
					
					checkBtnVisibility();		   
				   
			   });	
			   
			   	   

			},	// end success function
		   data: null		   

	}); // end ajax		
	
	
	
} // end fetchBlogEntry

function checkBtnVisibility() {
	
	var maxBlogs = $(".max").html();

	if (p>=maxBlogs-1) {
		$("#nav_prev p").fadeOut("fast");	
	} else if ($("#nav_prev p").css("display") == 'none') {
		$("#nav_prev p").fadeIn("fast");	
	}
	if (p<=0) {
		$("#nav_next p").fadeOut("fast");	
	} else if ($("#nav_next p").css("display") == 'none') {
		$("#nav_next p").fadeIn("fast");	
	}
}
