// Declarations
var arrFeatureImage = new Array();
var arrFeatureText = new Array();
var lNewImage;

// Start the feature
var tid = setInterval('RotateFeature();', 5000);

// Set up the list of images and supporting text
arrFeatureImage.push('kanderhar-hospital.jpg');
arrFeatureText.push('Afghanistan Medical Facilities J & J Pneumatics designed and built this Medical Air System for Kandahar Hospital.');
arrFeatureImage.push('wind-in-sails.jpg');
arrFeatureText.push('J and J Pneumatics specified and supplied a new Air Compressor package for this Luxury Sailing Boats Air System.');

// 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()
	});
}

