/*
*   Created by Chump
*   For Use by PCOOA
**
 *  Last Code Update on 12/13/04
 *  Last Message Update on 05/31/08
*/

// Define/set the global variables
var msg = new Array();	// array to hold messages
var len = 0;			// for length of message
var width = 100;		// width of scroller
var pos = -width;		// current position

// Populate the array with messages
//	NOTE: _must_ be in sequential order from 0!
msg[0] = "Welcome to the PCOOA website!";
msg[1] = "If you have any questions/comments/suggestions, please send an email to: webmaster@policecarowners.com";
msg[2] = "Sign up in the Forum to post messages/classifieds.";
msg[3] = "Sign up in the Photo Gallery to put your car pictures online.";
msg[4] = "View upcoming Events to find out what's going on near you.";
msg[5] = "Be safe out there!";

// Define/set random number variables
var num = 0;
var hasnum = 0;
var newnum = 0;

function getnum() {
	newnum = Math.round(Math.random() * (msg.length - 1));
	while ((msg.length > 1) && (newnum == num)) { // no duplicates back-to-back
		newnum = Math.round(Math.random() * (msg.length - 1));
	}
	num = newnum;
	hasnum = 1;
}

function reset() {
	pos = -width;
	getnum();
}

function scroller() {
	if (hasnum == 0) {
		getnum();
	}

	txt = '';
	len = msg[num].length;

	pos++;

	if (pos == len) {
		reset();
		txt = '';
		len = msg[num].length;
	}

	if (pos <= 0) {
		for (var i = 1; i <= Math.abs(pos); i++) {txt = txt + " ";}
		txt = txt + msg[num].substring(0, width - i + 1);
	}
	else {txt = txt + msg[num].substring(pos, width + pos);}
	this.window.status = txt;
	setTimeout("scroller()", 100); // 100=1/10th of a second
}