// JavaScript Document
var CURRENTPAGE = 1;
var updateComments = function(page, id) {
	
	if ($jQuery("#comments2").css("display") == 'none')
		$jQuery("#comments2").show();
		
	if (page != 'all') {
	
		if (page == 'next')
			var newpage = parseInt(CURRENTPAGE) + 1;
			
		if (page == 'back')
			var newpage = parseInt(CURRENTPAGE) - 1;
				
		if (newpage > TOTALPAGES) return false;
		if (newpage < 1) return false;
	
	} else {
		newpage = 'all';
	}
	
	$jQuery("#comments2").slideToggle("fast");
		
	$jQuery.get("_ajax/ajax_comments.php", { page: newpage, c_id: id },
  function(data){
    $jQuery('#comments2').html(data);
		$jQuery("#comments2").slideToggle("fast");
  });
	
	if (page == 'all') {
		$jQuery(".pagination").hide();
		$jQuery(".btn-comment-all").unbind();
		$jQuery(".btn-comment-all").text("View Paginated Comments");
		$jQuery(".btn-comment-all").click(function() {
			CURRENTPAGE = 2;
			updateComments('back', PAGEID);
		});
		
	} else {
		$jQuery(".pagination").show();
		$jQuery(".btn-comment-all").unbind('click');
		$jQuery(".btn-comment-all").text("View All Comments");
		$jQuery(".btn-comment-all").click(function() {
			updateComments('all', PAGEID);
		});
	}
	
	CURRENTPAGE = newpage;
	$jQuery("span#txt_currentpage").text(newpage);
	
}

$jQuery(document).ready(function() {
	$jQuery(".btn-comment-next").click(function() {
		updateComments('next', PAGEID);
	});
	$jQuery(".btn-comment-back").click(function() {
		updateComments('back', PAGEID);
	});
	$jQuery(".btn-comment-all").click(function() {
		updateComments('all', PAGEID);
	});
});
