var bannerArray = new Array();
var bannerAArray = new Array();

// Adds an image banner to the Array 
function addImageBanner(fileName, hrefLink, altText)
{
	var href = "";
	var hrefClose = "";
	if ((hrefLink != null) && (hrefLink != "")) {
	   href = "<a href='"+hrefLink+"'>";
	   hrefClose = "</a>";
	}
	var bannerContents = href + "<img border='0' alt='"+altText+"' src='"+fileName+"'>" + hrefClose;
	addBanner(bannerContents);
}

function addAImageBanner(fileName, hrefLink, altText)
{
	var href = "";
	var hrefClose = "";
	if ((hrefLink != null) && (hrefLink != "")) {
	   href = "<a href='"+hrefLink+"'>";
	   hrefClose = "</a>";
	}
	var bannerContents = href + "<img border='0' alt='"+altText+"' src='"+fileName+"'>" + hrefClose;
	addABanner(bannerContents);
}

// Adds any user-specified contents to the Array
function addBanner(bannerContents)
{
	bannerArray.push(bannerContents);
}

// Adds any user-specified contents to the Array
function addABanner(bannerContents)
{
	bannerAArray.push(bannerContents);
}

// Displays the next banner in the list
function displayBanners(bannerId)
{
	count++;
	count %= bannerArray.length;
	showBanner(bannerId, count);
}

// Displays the next banner in the list
function displayABanners(bannerId)
{
	countA++;
	countA %= bannerAArray.length;
	showABanner(bannerId, countA);
}

// Displays a single banner by replacing the contents of the DIV
function showBanner(bannerId, bannerIndex)
{
	var bannerObject = document.getElementById(bannerId);
	bannerObject.innerHTML = bannerArray[bannerIndex];
}

// Displays a single banner by replacing the contents of the DIV
function showABanner(bannerId, bannerIndex)
{
	var bannerAObject = document.getElementById(bannerId);
	bannerAObject.innerHTML = bannerAArray[bannerIndex];
}

// Shuffles the banner so that the order is random
function shuffleBanners()
{
	var shuffledNumberArray = new Array();
	var newBannerArray = new Array();
	
	for (var i = 0; i < bannerArray.length; i++)
	{
		var isRandomNumberGood = false;
		while (isRandomNumberGood == false)
		{
			var randomNumber = Math.floor(Math.random()*bannerArray.length);
			if (_isNumberAlreadyUsed(randomNumber, shuffledNumberArray) == false)
			{
				shuffledNumberArray[i] = randomNumber;
				isRandomNumberGood = true;
				newBannerArray[i] = bannerArray[randomNumber];
			}
		}
	}
	
	bannerArray = newBannerArray;
}

// Tests to ensure that every banner is only displayed once in the rotation
function _isNumberAlreadyUsed(randomNumber, shuffledNumberArray)
{
	for (var i = 0; i < shuffledNumberArray.length; i++)
	{
		if (shuffledNumberArray[i] == randomNumber)
			return true;
	}
	return false;
}

