/**
 * @author bdgeorge
 * 19/10/2008
 * Content Rotator for featured-artist box
 * Note: all 'featured-artists' must start with a div with class 'featured-artist_x' where x is the number eg featured-artist_1, featured-artist_2 etc
 * As this can start from a random point in the manufacturers array we look for a custom attribute wh-index to find the current displayed one
 * before we start
 */

$(document).ready(function(){		
	//Find our featured-artist-box on the page and attach a counter to it to keep track of which fact we are on, start on fact 1
	myFact = $("#featured-artist-box")
	//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 = $("#featured-artist-box div[class^='featured-artist_']").size();
	//now find which one is visible and pass that as an integer
	myFact.counter=eval($("#featured-artist-box div[class^='featured-artist_']:visible").attr('wh-index'));	
	//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
	$("#featured-artist-box a.featured-last").click(function(){
		//calculate the next fact
		myFact.counter == 1 ? myFact.nextfact=myFact.maxcount: myFact.nextfact = myFact.counter -1;
		$("#featured-artist-box .featured-artist_"+myFact.counter).fadeOut(250,function(){
					$("#featured-artist-box .featured-artist_"+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
	$("#featured-artist-box a.featured-next").click(function(){
		//calculate the next fact
		myFact.counter == myFact.maxcount ? myFact.nextfact=1: myFact.nextfact = myFact.counter+1;	
		$("#featured-artist-box .featured-artist_"+myFact.counter).fadeOut(250,function(){
					$("#featured-artist-box .featured-artist_"+myFact.nextfact).fadeIn(500);
		});
		myFact.counter=myFact.nextfact;	
		return false;
	});

});