/* home page ticker version 1.0 - RB/RL */
/*
	variables (and definable arrays):
		tickText : (array) each line made up of title, url (relative OR absolute)
		
		interval : time in MS (secs * 1000) between transitions (does not include transition time! - do not set below 1000)
		fadeIncDelay : delay beween each "step" of a transition
		colorMap : (array) contains each stage of color, script will loop from colorMap[0] > length, so to speed effect remove every other state for example. to go to black uncomment lines.
		
	[future/recommended enhancments:
		should be made entirely reusable by pulling hardcoded "textlink" out of function into function arguments.]
*/

var interval = 3000;
var fadeIncDelay = 5;




var colorMap = new Array();
	/*colorMap[colorMap.length] = "1";
	colorMap[colorMap.length] = "1";
	colorMap[colorMap.length] = "2";
	colorMap[colorMap.length] = "3";
	colorMap[colorMap.length] = "4";*/
	colorMap[colorMap.length] = "5";
	colorMap[colorMap.length] = "6";
	colorMap[colorMap.length] = "7";
	colorMap[colorMap.length] = "8";
	colorMap[colorMap.length] = "9";
	colorMap[colorMap.length] = "a";
	colorMap[colorMap.length] = "b";
	colorMap[colorMap.length] = "c";
	colorMap[colorMap.length] = "d";
	colorMap[colorMap.length] = "e";
	colorMap[colorMap.length] = "f";



var timmy; //timer

function pauseTick(){
	clearTimeout(timmy);
	setCol(colorMap[0]);
}
function resumeTick(){
	setCol(colorMap[curColIndex]);
	timmy = setTimeout("tick()", 10);
}

function startTick(){
	setTickText();
	timmy = setTimeout("tick()", 1);
}

function tick(){
	//just incase errors enable this line: clearTimeout(timmy);
	if (fadeIn == true){
		if (curColIndex == 0){
			//curTick = nextTick();
			fadeIn = false;
			timmy = setTimeout("tick()", interval);
		}else{
			curColIndex--;
			setCol(colorMap[curColIndex])
			timmy = setTimeout("tick()", fadeIncDelay);
			//alert('x')
		}
	}else{
		if (curColIndex == colorMap.length-1){
			//change text
				//timmy = setTimeout("startTick()", 1000);
				nextTick();
				timmy = setTimeout("tick()", 1); // delay
				fadeIn = true;
		}else{
			curColIndex++;
			setCol(colorMap[curColIndex])
			timmy = setTimeout("tick()", fadeIncDelay);
		}
	}
}

function nextTick(){
	if (curTick == tickText.length - 1){
		curTick = -1;
	}
	curTick++;
	setTickText();
}

function setTickText(){
	document.getElementById('ticklink').href = tickText[curTick][1];
	document.getElementById('ticklink').innerHTML = tickText[curTick][0];
}

function setCol(col){
	document.getElementById('ticklink').style.color = "#"+col+col+col+col+col+col;
}



var curTick = Math.ceil(Math.random()*tickText.length-1); //starts on random number
var curColIndex = 0; //arr index from colmap
var fadeIn = true;
