/**
 * @author bdgeorge
 * Content Rotator for Ramalama fact box
 * Note: all 'facts' must start with a class 'fact_x' where x is the number eg fact_1, fact_2 etc
 */

$(document).ready(function(){		
	//Find our factbox on the page and attach a counter to it to keep track of which fact we are on, start on fact 1
	myFact = $("#factbox")
	myFact.counter = 1;
	myFact.nextfact = 2;
	
	//Count how many facts we have on the page and save that as max count
	//All facts must start with a class name 'fact_x' where x is the fact number
	myFact.maxcount = $("#factbox p[class^='fact_']").size();	
	//Create a next fact function, this will hide the current fact and show the next one, if we are on the last fact then go to the first
	$(".boxfoot a.boxleft").click(function lastFact(){
		//calculate the next fact
		myFact.counter == 1 ? myFact.nextfact=myFact.maxcount: myFact.nextfact = myFact.counter -1;
		//
		$("#factbox .fact_"+myFact.counter).fadeOut(250,function(){
					$("#factbox .fact_"+myFact.nextfact).fadeIn(500);
		});
		myFact.counter=myFact.nextfact;
		return false;
		
	});	
	//Create a last fact function, this will hide the current fact and show the previous one, if we are on the first fact then go the last
	$(".boxfoot a.boxright").click(function nextFact(){
		//calculate the next fact
		myFact.counter == myFact.maxcount ? myFact.nextfact=1: myFact.nextfact = myFact.counter+1;		
		$("#factbox .fact_"+myFact.counter).fadeOut(250,function(){
					$("#factbox .fact_"+myFact.nextfact).fadeIn(500);
		});
		myFact.counter=myFact.nextfact;	
		return false;
	});

});