// JavaScript Document

var numshown = 3; //non exclusive counting. ie starts at 1
var countitems = 0; //non exclusive counting. ie starts at 1
var showpointer = 1; //non exclusive counting. ie starts at 1
var oldpointer = 1;
var fadespeed = 200;

var items = [];


function showNewItems(){
	
	
	//set all of next items to show
	var i = showpointer-1;
	var count = 0;
	while(i < countitems && count <= numshown){
		
		$(items[i]).show();
		i++;
		count++;
		//alert(items[i]);
	}
	
	
	
	$('#itemcont2').fadeIn(fadespeed);
	
}


function updateView(){
	
	if(showpointer+numshown > countitems){
		$('#view-later').addClass("later-disabled");
		$('#view-later a').css("color","#cecdcd");
	}else{
		$('#view-later').removeClass("later-disabled");
		$('#view-later a').css("color","#000");
	}
	
	if(showpointer == 1){
		$('#view-earlier').addClass("earlier-disabled");
		$('#view-earlier a').css("color","#cecdcd");
	}else{
		$('#view-earlier').removeClass("earlier-disabled");
		$('#view-earlier a').css("color","#000");
	}
	
	
	
	if(oldpointer != showpointer){
	$('#itemcont2').fadeOut(fadespeed, function(){
	
		$('.item').each(function(){
			$(this).hide();
		});
		
		showNewItems();
		
	});
	}
}


function showEarlier(){
	
	oldpointer = showpointer;
	showpointer = showpointer - numshown-1;
	
	if(showpointer < 1){
		showpointer = 1;
	}
}

function showLater(){

	oldpointer = showpointer;
	if(showpointer+numshown-1 < countitems){	
		showpointer = showpointer + numshown;
	}
	
	
	
}


$(document).ready(function () {
	
	
	$('.item').each(function(){
		countitems = countitems + 1;
		items[countitems] = this;
	});
	

	
	$('#view-later a').click(function(e){
		e.preventDefault();
		showLater();
		updateView();
	});
	
	$('#view-earlier a').click(function(e){
		e.preventDefault();
		showEarlier();
		updateView();
	});
	
	updateView();
	

	
	
});
