// library to perform scrolling text ("ticker") animation
// by Thomas M. Farrell

// Call the scrollingText() function to start the animation.
// Note that you are expected to provide padding (spaces) at either the 
// beginning or end of the string so that everything isn't all smashed 
// together when the text loops. Also note that the string may not contain
// any HTML code - it's just straight text.
//
// Call the scrollingTextStop() function to halt the animation.
//
// Call the initializeScrollingText() function to format the content.

// Requirements:
// You have to have a blank layer available in your document for use 
// by the animation.
//
// This library relies on the layercontrol.js library by Tom Farrell
// which must be loaded first.


//the following function starts the animation of scrolling text.
function scrollingText(layerName,message,x,y,numChars,delay) {
	var theLayer = makeAbstract(layerName);
	if ((theLayer!=null) && (message.length>0)) {
		hideLayer(theLayer);
		scrollLayerName = layerName;
		textToScroll = message;
		scrollBigString = message + message;
		charsToScroll = numChars;
		positionLayer(theLayer,x,y);
		showLayer(theLayer);
		scrollTextHandle = setInterval("scrollText()", delay);
		} //end if
	} //end function

//the following function stops the animation of scrolling text.
function scrollingTextStop() {
	clearInterval(scrollTextHandle);
	layerContent(makeContentAbstract(scrollLayerName),"");
	scrollTextHandle = null;
	} //end function

//the following function sets up the prefix and suffix for the content
//of the scrolling layer. With this prefix and suffix, you can apply 
//formatting to the scrolling content.
function initializeScrollingText(pre,suf) {
	scrollTextPrefix = pre;
	scrollTextSuffix = suf;
	} //end function

//the following global variable holds the message to be scrolled.
//don't override it, pass the message to the scrollingText() function instead.
var textToScroll = null;
//the following holds the number of characters to appear in the scroller at once.
var charsToScroll = null;
//the following global variable holds the index of the current first character.
var scrollTextBegin = 0;
//the following global variable holds the timeout handle for the scrolling text
//so that it can be stopped if desired.
var scrollTextHandle = null;
//the following is used for looping of the scrolling text. Ignore it.
var scrollBigString = null;
//the following is the name of the layer that holds the scrolling text.
var scrollLayerName = null;
//the following two are placed around the scroll text in its layer.
var scrollTextPrefix = "";
var scrollTextSuffix = "";

//the following function performs the action of scrolling the text one character.
//don't call it, call scrollingText() instead.
function scrollText() {
	//alert("running");
	if (scrollTextBegin == textToScroll.length) {
		scrollTextBegin = 0;
		} //end if
	var msg = scrollBigString.substring(scrollTextBegin,(scrollTextBegin+charsToScroll-1));
	var msgArray = msg.split(" ");
	msg = msgArray.join("&nbsp;");
	layerContent(makeContentAbstract(scrollLayerName),scrollTextPrefix + msg + scrollTextSuffix);
	scrollTextBegin += 1;
	}
