//////////////////////////////////////////////////////////////
// Focus Item functions
// v1.00 (Budd Wright)
//
// Description:
//////////////////////////////////////////////////////////////
// Contains focus item functions
//////////////////////////////////////////////////////////////
//
// Usage:
//////////////////////////////////////////////////////////////
// <script language="javascript" src="js/focusItems.js"></script>
//////////////////////////////////////////////////////////////
//
// v1.00 Notes
// -----------
//
//
// Known Issues
// ------------
// 
//////////////////////////////////////////////////////////////





/* DisplayRandomFocusItem */
// Writes a random focus item to the document
function DisplayRandomFocusItem( focusItemArray )
{
	if( focusItemArray.focusItems.length == 0 )
		return;

	// Get random focus item
	var focusItem = focusItemArray.GetRandom();

	// Compile the HTML to be output
	if( focusItem.url != "" )
	{
		var html = "<a href=\"" + focusItem.url + "\">";
			html += "<img src=\"" + focusItem.imageUrl + "\" border=\"0\" alt=\"" + focusItem.label + "\" />";
			html += "</a>";
	}
	else
	{
		// No link, just the image
		var html = "<img src=\"" + focusItem.imageUrl + "\" border=\"0\" alt=\"" + focusItem.label + "\" />";
	}

	// Write the focus item's HTML to the document
	document.write( html );
}





/////////////////////////////////////
// Object Constructors
/////////////////////////////////////


/* FocusItem object */
function FocusItem(label, url, imageUrl, frame)
{
	this.label = label;									// label
	this.url = url;										// focus item's link
	this.imageUrl = imageUrl;							// focus item's image path
	this.frame = frame;									// frame to send links into
}


/* FocusItemArray object */
function FocusItemArray()
{
	this.focusItems = new Array();						// array of FocusItem items

	this.Add = FocusItemArray_Add;
	this.GetRandom = FocusItemArray_GetRandom;
}



/* FocusItemArray.Add() */
// Adds a new FocusItem into the focus item array at the next index
function FocusItemArray_Add(label, url, imageUrl, frame)
{
	var index = this.focusItems.length;

	this.focusItems[index] = new FocusItem(label, url, imageUrl, frame);

	return this.focusItems[index];
}


/* FocusItemArray.GetRandom() */
// Returns a random FocusItem
function FocusItemArray_GetRandom()
{
	var size = this.focusItems.length;
	var index = Math.floor( Math.random() * size )					// 0 - size (array is zero-based)

	return this.focusItems[index];
}