var bannerArray = new Array();
var bannerId;

function getCurrentBannerId() {
	var eleBannerIdContainer = document
			.getElementById("BannerRotatorContainer");
	if (eleBannerIdContainer != null) {
		// Get child DIV with JSF-Generated ID
		for ( var i = 0; i < eleBannerIdContainer.childNodes.length; ++i) {
			var child = eleBannerIdContainer.childNodes[i];
			if (child.id != null && child.id.indexOf("bannerContentId") >= 0) {
				bannerId = child.innerHTML;
				// alert("Set banner Id to " + bannerId );
			}
		}
	}
}

function updateBanner() {
	// Populate the 'bannerId' variable with the content id of the current
	// banner.
	getCurrentBannerId();

	if (bannerId == null || bannerId.length == 0) {
		// alert("No banner exists");
		return;
	}

	// TODO: Safety: verify bannerArray exists, and has elements. Make sure
	// bannerId is valid and refers to something in the banner array.
	try {
		var eleImg = document.getElementById("Banner");
		if (eleImg == null) {
			// alert("Could not find banner image element");
			return;
		}

		if (bannerId != null && bannerArray[bannerId] != null) {

			// Update banner image if URL is new.
			// alert("Banner image: " + eleImg );
			if (eleImg.src.indexOf(bannerArray[bannerId].img) <= -1) {
				var newSrc = "/asset" + bannerArray[bannerId].img;
				// alert("Updating Banner from '" + eleImg.src + "' to '" +
				// newSrc + "'");
				jQuery("#Banner").fadeOut(1000, function() {
					jQuery("#Banner").attr('src', newSrc);
				}).fadeIn(1000);
			}
		}
	} catch (exc) {
		alert("Error in updateBanner(): " + exc);
	}
}