/**
*	ticker.js
*	simple HTML ticker. Ticker speed can be customized.
*	onMouseOver/onMouseOut/onClick commands suppored.
*	Supports any number of tickers.
*
*	Test in browsers:
*					FireFox
*					IE 5.5/6/7/8
*
*	written by Gal Chen 09/09/2009

To use:

JS:
TICKER_STEP_SIZES[X] = 2;
TICKER_STEP_INTERVALS[X] = 20;
TICKER_HEIGHTS[X] = 300;

CSS:
<style type="text/css">
.ticker { position: absolute; height: 300px; height: 20px; overflow: hidden; }
.ticker_text { position: absolute; height: 20px; white-space:nowrap; }
</style>

HTML:
<body onload="tickerInit(X);">
<div id="ticker_X" class="ticker" onmouseover="tickerStop(X,this);" onmouseout="tickerStart(X,this);"><div id="ticker_text_X" class="ticker_text">Enter here any text you wish to be ticked.</div></div>


X is to be replaced with any number

*/


var TICKER_STEP_SIZES = new Array();
var TICKER_STEP_INTERVALS = new Array();
var TICKER_HEIGHTS = new Array();

function $(obj) {
	return document.getElementById(obj);
}

function tickerInit(tickerId,height) {
	if ($('ticker_'+tickerId) && $('ticker_text_'+tickerId)) {
		TICKER_STEP_SIZES[tickerId] = 1;
		TICKER_STEP_INTERVALS[tickerId] = 40;
		$('ticker_'+tickerId).style.height = height;
		TICKER_HEIGHTS[tickerId] = height;
		var bottom = $("ticker_text_"+tickerId).offsetHeight;
		tickerRec(tickerId,bottom,TICKER_HEIGHTS[tickerId]);
	}
}// of tickerInit()

function tickerRec(tickerId,bottom,topPad) {
	if (topPad <= -bottom) topPad = TICKER_HEIGHTS[tickerId];
	topPad -= TICKER_STEP_SIZES[tickerId];
	$("ticker_text_"+tickerId).style.top = topPad + "px";
	var t = setTimeout("tickerRec('"+tickerId+"','"+bottom+"','"+topPad+"');",TICKER_STEP_INTERVALS[tickerId]);
}// of tickerRec()

function tickerSpeed(tickerId,speed){
	TICKER_STEP_SIZES[tickerId] = speed;
}// of tickerSpeed()

function tickerStop(tickerId){
	tickerSpeed(tickerId,0);
	$("ticker_"+tickerId).onclick = function () { tickerStart(tickerId); }
}// of tickerStop()

function tickerStart(tickerId){
	tickerSpeed(tickerId,1);
	$("ticker_"+tickerId).onclick = function () { tickerStop(tickerId); }
}// of tickerStart()
