var currentPage;
var count;

document.observe("dom:loaded", function() {

	count = $$('.commentblock');

	var countBlock = 0

	count.each(function(s) {
		countBlock++;	
		$(s).addClassName('block'+countBlock);
	});
	
	currentPage = count.length;

	$$('.commentblock').each(function(s) {
		$(s).setStyle({display: 'none'});
	});
	
	$$('.block'+currentPage).each(function(s) {
		$(s).setStyle({display: 'block'});
	});
	
	if (currentPage == count.length) {
		$('newer-top').hide();
		$('newer-bottom').hide();
	}
			
	Event.observe('older-top', 'click', olderPosts, true );
	Event.observe('newer-top', 'click', newerPosts, true );	
	Event.observe('older-bottom', 'click', olderPosts, true );
	Event.observe('newer-bottom', 'click', newerPosts, true );	
});


	function olderPosts() {
	
		if (currentPage >=2) {
			
			$$('.block'+currentPage).each(function(s) {				
				$(s).setStyle({display: 'none'});
				});
			
			currentPage--;
				
			$$('.block'+currentPage).each(function(s) {
				$(s).setStyle({display: 'block'});
			});
		}		
	
		if (currentPage == 1){
			$('older-top').hide();
			$('older-bottom').hide();
		}
		
		if (currentPage >= 2){
			$('older-top').show();
			$('older-bottom').show();
		}
		
		if (currentPage == count.length){
			$('newer-top').hide();
			$('newer-bottom').hide();
		}
		
		if (currentPage <= count.length-1){
			$('newer-top').show();
			$('newer-bottom').show();
		}		
			
	};
	
	
	
	function newerPosts() {
	
		if (currentPage <=count.length-1) {
			
			$$('.block'+currentPage).each(function(s) {				
				$(s).setStyle({display: 'none'});
				});
			
			currentPage++;
				
			$$('.block'+currentPage).each(function(s) {
				$(s).setStyle({display: 'block'});
			});
		
		}
		
		if (currentPage == count.length){
			$('newer-top').hide();
			$('newer-bottom').hide();
		}
		
		if (currentPage <= count.length-1){
			$('newer-top').show();
			$('newer-bottom').show();
		}			

		if (currentPage == 1){
			$('older-top').hide();
			$('older-bottom').hide();
		}
		
		if (currentPage >= 2){
			$('older-top').show();
			$('older-bottom').show();
		}
		
		
		if (currentPage == count.length){
			$('newer-top').hide();
			$('newer-bottom').hide();
		}
		
		if (currentPage <= count.length-1){
			$('newer-top').show();
			$('newer-bottom').show();
		}
					
	};


