/*Message swapper for alerts.*/

var msgs;
var currentIndex = 0;
var block;
var currentMsg;
var firstTime = true;
var untypeID;
var swapID;
var myInterval;

var colorArray = new Array('000000','333333','666666','999999','CCCCCC','FFFFFF');
var currentColor = 0;

function swap() {
	if(firstTime) {
		firstTime=false;
		nextMessage();
	}
	else {
		untypeID = window.setInterval("untype()",100);
	}
}

function nextMessage() {
	incMessage();
	currentMsg = msgs[currentIndex];
	block.innerHTML = currentMsg;
	setTimeout("swap()",myInterval);
}

function incMessage() {
	currentIndex++;
	if(currentIndex == msgs.length) {
		currentIndex = 0;
	}
}

function untype() {
	if(currentColor == colorArray.length) {
		currentColor = 0;
		block.style.color = colorArray[currentColor];
		currentColor++;
		clearInterval(untypeID);
		nextMessage();
		return;
	}
	else {
		block.style.color = colorArray[currentColor];
		if(block.children) {
			block.children[0].style.color = colorArray[currentColor];
		}
		currentColor++;
	}
}

function messageSwapper(interval,msgsArray) {
	msgs = msgsArray;
	myInterval = interval;
	block = document.getElementById("msgBody");
	swap();
}
