// Declarations
var arrFeatureImage = new Array();
var arrFeatureText = new Array();
var lNewImage;

// Start the feature
var tid = setInterval('RotateFeature();', 7500);

// Set up the list of images and supporting text
arrFeatureImage.push('../images/cricket1.jpg');
arrFeatureText.push('Chalfont St Peter Cricket Club');
arrFeatureImage.push('../images/hockey-action.jpg');
arrFeatureText.push('Amersham and Chalfont Hockey Club');
arrFeatureImage.push('../images/wedding-inside.jpg');
arrFeatureText.push('Chalfont Park Sports Association : Wedding at the Club');
arrFeatureImage.push('../images/inside_marquee.jpg');
arrFeatureText.push('Chalfont Park Sports Association : Wedding at the Club');
arrFeatureImage.push('../images/club_and_marquee1.jpg');
arrFeatureText.push('Chalfont Park Sports Association : Wedding at the Club');


// Preload the next image
PreLoadNewImage()

// =====================================================================================

function PreLoadNewImage()
{

	// Calculate the next image
	SetNewImage()

	// Preload it
	var objImage = new Image(418, 370);
	objImage.src = 'Images/' + arrFeatureImage[lNewImage];

}

// =====================================================================================

function SetNewImage()
{

	// Calculate the next image
	lNewImage = Math.round(Math.random() * (arrFeatureImage.length - 1));

	// See if it is the same as the one that we are already showing
	while ($("#FeatureImage").attr("src") == "Images/" + arrFeatureImage[lNewImage])
	{
		// It is, pick another
		lNewImage = Math.round(Math.random() * (arrFeatureImage.length - 1));
	}

}

// =====================================================================================

function RotateFeature()
{

	// Fade it out
	$("#FeatureImage").fadeOut(500, function () {
		// Change the image
		$("#FeatureImage").attr("src", "Images/" + arrFeatureImage[lNewImage]);
		$("#FeatureImage").attr("alt", arrFeatureText[lNewImage]);

		// And text
		$("#FeatureText").text(arrFeatureText[lNewImage]);

		// And fade it in
		$("#FeatureImage").fadeIn(500);

		// Preload the next image
		PreLoadNewImage()
	});
}

