/* Create an indexed array of n elements with length property */
function mklist(n)
{
	this.length=n;
	for (var c=1 ; c <= n ; c++) {
		this[c]=0;
	}
	return this;
}

/* Gets a browser platform specific delay calibration for scrolling messages */
function browserdelay()
{
	var retval=500;
	if (navigator.userAgent.indexOf("Win") != 0) {		/* Windows based Netscape */
		retval=150;
	}
	else if (navigator.userAgent.indexOf("Mac") != 0) {	/* Mac based Netscape */
		retval=500;
	}
	else if (navigator.userAgent.indexOf("X11") != 0) {	/* XWindows based Netscape */
		retval=750;
	}
	return retval;
}

/* Create the configuration object for scrollit */
function mkcfg(n)
{
	this.num=1;				/* Which message we're on */
	this.seed=0;				/* Used for scrolling types */
	this.list=new mklist(n);		/* List of messages to display */
	this.type=new mklist(n);		/* Display method indicators */
	this.delay=browserdelay();		/* Browser platform specific delay */
	this.timer=0;				/* System event timer */
	this.showurl=(5 * 1000);		/* Timeout for urlfix functionality */
	this.looping=true;			/* Continuously rotate messages? */
	this.msgdisp=(5 * 1000);		/* How long to display non-scrolling messages */
	this.barwidth=100;			/* How many character to size the status bar */
	return this;
}


/* This function is used from within the page to display the url for a link */
function urlfix(obj)
{
	window.clearTimeout(window.config.timer);
	window.defaultStatus=obj.href;
	window.config.timer=window.setTimeout("sbprint()",window.config.showurl);
	return true;
}

/* This function handles the right to left scrolling */
function scrollit_r2l()
{
	var out=" ";
	var c=0;

	if (window.config.seed <= window.config.barwidth && window.config.seed > 0) {
		for (c=0 ; c < window.config.seed ; c++) {
			out+=" ";
		}
		out+=window.config.list[window.config.num];
		window.config.seed--;
		window.status=out;
		window.config.timer=window.setTimeout("scrollit_r2l()",window.config.delay);
	}
	else if (window.config.seed <= 0) {
		if (-window.config.seed < window.config.list[window.config.num].length) {
			out+=window.config.list[window.config.num].substring(-window.config.seed,window.config.list[window.config.num].length);
			window.config.seed--;
			window.status=out;
			window.config.timer=window.setTimeout("scrollit_r2l()",window.config.delay);
		}
		else {
			window.status=" ";
			window.config.num++;
			window.config.timer=window.setTimeout("sbprint()",window.config.msgdisp);
		}
	}
}



/* Call the following with the number of different messages you want to run */
window.config=new mkcfg(2);
window.config.list[1]="A new, improved JavaScript ticker!";
window.config.type[1]=0;	/* Just display it, default type */
window.config.list[2]=". . . This new JavaScript ticker fixes many of the previously reported problems, no out of memory errors, and URLs now show. Courtesy of WEBSYS . . .";
window.config.type[2]=1;	/* Scrolling from right to left */

/* This function runs the status bar, cycling through your messages */
function sbprint()
{
	if (window.config.num <= window.config.list.length) {
		if (window.config.type[window.config.num] == 0) {
			window.status=window.config.list[window.config.num];
			window.config.num++;
			window.clearTimeout(window.config.timer);
			window.config.timer=window.setTimeout('sbprint()',window.config.msgdisp);
		}
		else if (window.config.type[window.config.num] == 1) {
			window.config.seed=window.config.barwidth;
			scrollit_r2l();
		}
	}
	else if (window.config.looping) {
		window.config.num=1;
		window.clearTimeout(window.config.timer);
		window.config.timer=window.setTimeout('sbprint()',window.config.delay);
	}
}
