
var booBrowserSupported = document.getElementById;	// determines in the browser supports a modern-enough DOM
var iDurationOfPauseBetweenMessages = 7000; 		// in milliseconds
var iDurationOfIncremement = 40; 					// in milliseconds
var objFaderTimer;									// Clock
var iMessageIndex = -1;								// index of message being displayed within the message array
var iScrollerWidth = 475; 							// width of scroller in pixels
var iScrollerHeight = 80; 							// height of scroller in pixels
var arrTextColorInitial = new Array(255,255,255); 	// color definition (red, green, blue)
var arrTextColorFinal = new Array(0,0,0); 			// color definition (red, green, blue)
var iTotalIncrementsInTransition = 70; 				// total number of changes to color that produces the fade


function ChangeColorOfAnchors(iIncrement) {
	var colElems = document.getElementById("scrollbox").getElementsByTagName("a");
  	if (colElems.length > 0 ) {
    	for (var i = 0; i < colElems.length; i++)
      		colElems[i].style.color = GetColor(iIncrement);
  		}
	}
	
function ChangeColorOfEmphasis(iIncrement) {
	var colElems = document.getElementById("scrollbox").getElementsByTagName("em");
  	if (colElems.length > 0 ) {
    	for (var i = 0; i < colElems.length; i++)
      		colElems[i].style.color = GetColor(iIncrement);
  		}
	}
	
function DisplayMessage() {

	var iCount;
	var bValid;
	var sMsgText;

	if (booBrowserSupported) {

	
		bValid = false;
		while (!bValid) {
		
			bValid = true;
			if ((Math.random()*1000) < 667) {
				iCount = arrAdvertMsg.length;
				iMessageIndex = parseInt(Math.random()*iCount);
				if (iMessageIndex > iCount) bValid = false;
				if (iMessageIndex < 0) bValid = false;
				if (typeof(arrAdvertMsg[iMessageIndex]) == "undefined") bValid = false;
				if (bValid) 
					sMsgText = arrAdvertMsg[iMessageIndex];
				}
			else {
				iCount = arrMessage.length;
				iMessageIndex = parseInt(Math.random()*iCount);
				if (iMessageIndex > iCount) bValid = false;
				if (iMessageIndex < 0) bValid = false;
				if (typeof(arrMessage[iMessageIndex]) == "undefined") bValid = false;		
				if (bValid) 
					sMsgText = arrMessage[iMessageIndex];
				}
			}

//sMsgText = arrAdvertMsg[0];	
    	document.getElementById("scrollbox").style.color="rgb("+arrTextColorInitial[0] + ", " + arrTextColorInitial[1] + ", "+arrTextColorInitial[2]+")";
    	document.getElementById("scrollbox").innerHTML=sMsgText;
    	FadeContent(1);
		}
	}

	
function FadeContent(iIncrement) {
	if(iIncrement <= iTotalIncrementsInTransition) {	
    	document.getElementById("scrollbox").style.color = GetColor(iIncrement);
   		ChangeColorOfAnchors(iIncrement);
		ChangeColorOfEmphasis(iIncrement);
    	iIncrement++;
    	objFaderTimer = setTimeout("FadeContent(" + iIncrement + ")",iDurationOfIncremement);
		} 
	else {
    	clearTimeout(objFaderTimer);
    	document.getElementById("scrollbox").style.color = "rgb(" + arrTextColorFinal[0] + ", " + arrTextColorFinal[1] + ", " + arrTextColorFinal[2]+")";
    	setTimeout("DisplayMessage()", iDurationOfPauseBetweenMessages);
		}   
	}

	
function GetColor(iIncrement) {
	var iDifference;
  	var arrTextColorNew = new Array(3);
	
  	for(var i = 0; i < 3; i++) {
    	var iDifference = (arrTextColorInitial[i] - arrTextColorFinal[i]);
		
    	if(iDifference > 0) {
      		arrTextColorNew[i] = arrTextColorInitial[i] - (iIncrement * Math.round((iDifference/iTotalIncrementsInTransition)));
    		} 
		else {
      		arrTextColorNew[i] = arrTextColorInitial[i] + (iIncrement * Math.round((Math.abs(iDifference)/iTotalIncrementsInTransition))*iIncrement);
    		}
  		}
  	return ("rgb(" + arrTextColorNew[0] + ", " + arrTextColorNew[1] + ", " + arrTextColorNew[2] + ")");
	}

	
function InstallFadingScrollbox() {

	document.write('<div id="scrollbox" border="0" class="scrollbox">'+ arrMessage[0] + '</div>');

	if (window.addEventListener)
		window.addEventListener("load", DisplayMessage, false)
	else if (window.attachEvent)
		window.attachEvent("onload", DisplayMessage)
	else if (document.getElementById)
		window.onload = DisplayMessage

	return 0;	
}