/**
 * campaignImageRotation.js
 * @description Campaign space image rotation
 * @author Rebecca Younes
 * @date April 2008
 */

/**
 * @namespace ILR
 * @class campaignImageRotator
 */

ILR.campaignImageRotator = {

	/** 
	 * @description Initialize the object
	 * @method init
	 */
	init: function(){

		this.showRandomImage();

	},
	
	/**
	 * @description Display a randomly-selected campaign space banner image and caption.
	 * Use JavaScript for the rotation to enable CommonSpot element caching on the custom script.
	 * @method showRandomImage
	 */
	showRandomImage : function() {
		
		var campaignImage = document.getElementById("rotatingCampaignImage"),
			campaignImageCaption = document.getElementById("campaignImageCaption"),
			rand,
			index,
			caption,
			altText;
			
		// The JSON object exists only if there's more than one image - otherwise,
		// ColdFusion has just written the image tag.
		if (this.campaignImages) { 
			rand = ILR.util.number.randomIntBetween(1, this.campaignImages.COUNT);
			index = rand-1;   // images indexed from 1, array indexed from 0 
			caption = this.campaignImages.CAPTIONS[index];  
			altText = this.campaignImages.ALTTEXT[index].replace(/<[^>]*>/g, "");  
			campaignImage.innerHTML = '<img src="' + this.campaignImages.BASENAME + rand + '.jpg" class="' + this.campaignImages.CLASS + '" alt="' + altText + '" title="'+ altText + '" height="' + this.campaignImages.HEIGHT + '" width="' + this.campaignImages.WIDTH + '" border="' + this.campaignImages.BORDER + '" />'; 
			campaignImageCaption.innerHTML = caption;
		}
	}
	
};
		
YAHOO.util.Event.addListener(window, "load", ILR.campaignImageRotator.init, ILR.campaignImageRotator, true);
