/**
 * News ticket for the Tasman homepage.
 */
NewsTicker = {

	_current: 0,
	_numNewsArticles: 0,

	/**
	 * Intializes the news ticket with the number of articles.
	 */
	init: function(numNewsArticles)
	{
		/* save number of news articles */
		this._numNewsArticles = numNewsArticles;

		/* show the next one in 5 seconds */
		setTimeout(NewsTicker.hideCurrent, 5000);
	}, // function init

	/**
	 * Fades out the current and then invokes showNext.
	 */
	hideCurrent: function()
	{
		MochiKit.Visual.fade($("news-ticker-" + NewsTicker._current), {
			"duration": 0.5,
			"afterFinish": NewsTicker.showNext
		});
	}, // function hideCurrent

	/**
	 * Shows the next news article
	 */
	showNext: function()
	{
		/* get the next news article */
		NewsTicker._current++;
		if (NewsTicker._current >= NewsTicker._numNewsArticles)
		{
			NewsTicker._current = 0;
		}

		MochiKit.Visual.appear($("news-ticker-" + NewsTicker._current), {
			"duration": 0.5,
			"afterFinish": function() {
				setTimeout(NewsTicker.hideCurrent, 5000);
			}
		});
	} // function showNext

}; // class NewsTicker
