/* US Digital Partners / fading callouts script */

var counter = 0;		// Used for navigation calculations
var curCallout = 1;
var nextCallout = 1;
var rotate = null;


function usdpCallouts(autorotate, delay) {
	if (autorotate) {
		rotate = setInterval("fadeCallouts('auto')",delay);
	}
}

function fadeCallouts(rotateDirection, index) {
	
	// Get the number of callouts
	var totalCallouts = $('.callouts').size();
	
	if (rotateDirection == "auto") {
		counter++;
		nextCallout++;
		if (counter >= totalCallouts) { // Wrap back to the beginning
			counter = 0;
			nextCallout = 1;
		}
	}
	
	// Fade out the current callout; Fade in the next callout
	$("#callout" + curCallout).fadeOut("medium", function () { 	// counter+1 is used because the callouts numbering is not zero based
		$("#callout" + nextCallout).fadeIn("medium", function() { 
			$("#callout" + nextCallout).css("display", "block");
		}); 
	});
	curCallout = nextCallout;
}