// 
// JavaScript RandomImageLink
//

// Constructor for RandomImageLink object
function RandomImageLink(randomImageLinkId)
{
	this.randomImageLinkId = randomImageLinkId;
	this.images = [];
	this.imageBasePath = "";
}

// Constructor for random image object
function RandomImage(imageSource, toolTip, cssClass, linkUrl)
{
	this.imageSource = imageSource;
	this.toolTip = toolTip;
	this.cssClass = cssClass;
	this.linkUrl = linkUrl;
}

// RandomImageLink method to add a new random image
RandomImageLink.prototype.add = function(imageSource, toolTip, cssClass, linkUrl)
{
	this.images[this.images.length] = new RandomImage(imageSource, toolTip, cssClass, linkUrl);
}

// RandomImageLink method to output HTML string
RandomImageLink.prototype.toString = function()
{
	var randomIndex = Math.floor(Math.random() * this.images.length);
	
	var output = '';
	
	if(this.images[randomIndex].linkUrl != '')
	{
	 	output += '<a href="';
		output += this.images[randomIndex].linkUrl;
		output += '">';
	}
	
	output += '<img src="';
	output += this.imageBasePath + this.images[randomIndex].imageSource;
	output += '" alt="';
	output += this.images[randomIndex].toolTip;
	output += '" class="';
	output += this.images[randomIndex].cssClass;
	output += '" />';
	
	if(this.images[randomIndex].linkUrl != '')
	{
	 	output += '</a>';
	}

	return output;
}