/*
======================================================================
JavaScript Marquee class
Author: Alessandro Lacava http://www.alessandrolacava.com
Created: Jul 25th, 2006.
Description: Build a marquee element with the array passed in to the
update function. This class is meant to be used in 
conjunction with the ContentRetriever class that is defined inside 
the contentRetriever.js file.
======================================================================
*/

//NOTE: REMEMBER TO INCLUDE ajax.js, htmlBuilder.js and contentRetriever.js IN THE CLIENT CODE 

//Marquee class

function Marquee(elemId, scrollamount, stopOnMouseOver)
{
	//id of the ticker element to display information in
	this.elemId = elemId; 
	//scrollamount of the marquee.
	this.scrollamount = scrollamount; 
	//boolean indicating if the marquee stops when mouse is over
	this.stopOnMouseOver = stopOnMouseOver;
	//data array
	this.dataArray = [];
	//error message
	this.errorMessage = "No news available";
}

// This is the callback function called by the Observee (ContentRetriever).
// Fill the element with a marquee containing the items
Marquee.prototype.update = function(dataArray)
{
	if(dataArray === null || dataArray.length === 0)
	{
		//an error occurred
		this.dataArray = [this.errorMessage];
	}
	else
	{
		//no error
		this.dataArray = dataArray;
	}
	this.buildMarquee();
};

//build the marquee with the items retrieved
Marquee.prototype.buildMarquee = function()
{
	//reference to the DIV element
	var elem = document.getElementById(this.elemId);
	//join all the items as a single string separating them with a horizontal rule
	var tickerContent = this.dataArray.join("<hr />");
	var stopping = "";
	//stop on mouse over?
	if(this.stopOnMouseOver)
	{
		stopping = "onmouseover='javascript:this.stop();' onmouseout='javascript:this.start();'";
	}
	//build the marquee...
	var marquee = "<marquee name='marqueeNews' id='marqueeNews' " +
								"scrollamount='" + this.scrollamount + "' " +
								"loop='true' direction='up' " +
								stopping + " >" + tickerContent + "</marquee>";
	//...put it inside the element
	elem.innerHTML = marquee;
};
