
/*--------------------------------- Color Fader --------------------------------*/
// --------------------------------------------------------------------------------
// Filename    : colorFader.js
// 
// Description : This is a utility function. Given a start and end color and
// 		     	 a percentage fade it returns a color in between the 2 colors
// --------------------------------------------------------------------------------


function getColor(start, end, percent){
	function hex2dec(hex){return(parseInt(hex,16));}
	function dec2hex(dec){return (dec < 16 ? "0" : "") + dec.toString(16);}
	var r1 = hex2dec(start.slice(0,2)), g1=hex2dec(start.slice(2,4)), b1=hex2dec(start.slice(4,6));
	var r2 = hex2dec(end.slice(0,2)),   g2=hex2dec(end.slice(2,4)),   b2=hex2dec(end.slice(4,6));
	var pc = percent/100;
	var r  = Math.floor(r1+(pc*(r2-r1)) + .5), g=Math.floor(g1+(pc*(g2-g1)) + .5), b=Math.floor(b1+(pc*(b2-b1)) + .5);
	return("#" + dec2hex(r) + dec2hex(g) + dec2hex(b));
}

//-----------------------------------------------------------------
//  Text Fader - Vars
//-----------------------------------------------------------------
var txtColors = new Array("FF0000", "FFFFFF");
var start1  = txtColors[0];
var end1    = txtColors[0];
var index1  = 0;
var cindex1 = 0;
var faderObj1 = new Array();

//-----------------------------------------------------------------
//  Div Fader - Vars
//-----------------------------------------------------------------
var divColors = new Array("000000", "FF0000");
var start2  = divColors[0];
var end2    = divColors[0];
var index2  = 0;
var cindex2 = 0;
var faderObj2 = new Array();


//-----------------------------------------------------------------
//  Text Fader - <span id="">
//-----------------------------------------------------------------
function fadeSpan(){
	if(index1 == 0){
		start1 = end1;
		end1 = txtColors[ cindex1 = (cindex1+1) % txtColors.length ];
	}
	//	document.getElementById("fadingText").style.color = getColor(start, end, index);
	for(var i=0 ; i<faderObj1.length ; i++)
		faderObj1[i].style.color = getColor(start1, end1, index1);
		index1 = (index1+5) % 100;
		setTimeout("fadeSpan()", 40);
}
function fadeAllSpans(){
	for(var i=0 ; i<arguments.length ; i++)
		faderObj1[i] = document.getElementById(arguments[i]);
		fadeSpan();
}

//-----------------------------------------------------------------
//  Div Fader - <div id="">
//-----------------------------------------------------------------
function fadeDiv(){
	if(index2 == 0){
		start2 = end2;
		end2 = divColors[ cindex2 = (cindex2+1) % divColors.length ];
	}
	//	document.getElementById("fadingDivs").style.color = getColor(start, end, index);
	for(var x=0 ; x<faderObj2.length ; x++)
		faderObj2[x].style.backgroundColor = getColor(start2, end2, index2);
		index2 = (index2+5) % 100;
		setTimeout("fadeDiv()", 40);
}
function fadeAllDivs(){
	for(var x=0 ; x<arguments.length ; x++)
		faderObj2[x] = document.getElementById(arguments[x]);
		fadeDiv();
}

//-----------------------------------------------------------------
//  Fading Objects - Text / Divs
//-----------------------------------------------------------------
function JSFX_StartEffects(){
	fadeAllSpans("sp1");
}
function regErrors(){
	fadeAllSpans("error1", "error2", "error3", "error4", "error5", "error6", "error7");
}


