// Original:  WarpGear Software (jsfader@warpgear.com)
// Web Site:  http://www.warpgear.com/developer


var texts = new Array(
"<div style=\"color:{COLOR};\" class='Question_title'>&quot;Who are you?&quot;</div><div style=\"color:{COLOR2};\" class='Question_txt'>We're Experian. See our credentials, learn our history, read a few testimonials - there's a lot of ways you can get to know us better.</div><div id=\"Question_btn\"><a href=\"WhoWeAre.aspx\"><img src=\"images/FindOutMore_btn.gif\" width=\"126\" height=\"25\" alt=\"Find Out More\"></a></div>",
"<div style=\"color:{COLOR};\" class='Question_title'>&quot;Why isn't this free?&quot;</div><div style=\"color:{COLOR2};\" class='Question_txt'>Get your questions answered, understand the value of your membership and learn what you can do to make the most of it.</div><div id=\"Question_btn\"><a href=\"TakeAction.aspx\"><img src=\"images/FindOutMore_btn.gif\" width=\"126\" height=\"25\" alt=\"Find Out More\"></a></div>",
"<div style=\"color:{COLOR};\" class='Question_title'>&quot;How does this work?&quot;</div><div style=\"color:{COLOR2};\" class='Question_txt'>See how your Member Homepage and Email Alerts work together to help you better understand your personal credit information.</div><div id=\"Question_btn\"><a href=\"HowItWorks.aspx\"><img src=\"images/FindOutMore_btn.gif\" width=\"126\" height=\"25\" alt=\"Find Out More\"></a></div>", 
"<div style=\"color:{COLOR};\" class='Question_title'>&quot;Why do I need this?&quot;</div><div style=\"color:{COLOR2};\" class='Question_txt'>See what your membership has to offer, why you should care and what could happen if you don't.</div><div id=\"Question_btn\"><a href=\"WhatYouGet.aspx\"><img src=\"images/FindOutMore_btn.gif\" width=\"126\" height=\"25\" alt=\"Find Out More\"></a></div>");

var bgcolor = "#ffffff"; // background color, must be valid browser hex color (not color names)
var fcolor = "#003d6a";  // foreground or font color
var fcolor2 = "#6a9cc0"; 
var steps = 20; // number of steps to fade
var description = 20;
var show = 5000; // milliseconds to display message
var sleep = 30; // milliseconds to pause inbetween messages
var loop = true; // true = continue to display messages, false = stop at last message

var colors = new Array(steps);
getFadeColors(bgcolor,fcolor,colors);
var colors2 = new Array(description);
getFadeColors2(bgcolor,fcolor2,colors2);
var color = 0;
var text = 0;
var step = 1;

// fade: magic fader function
function fade()
{
	// insert fader color into message
	var text_out = texts[text].replace("{COLOR}", colors[color]); // texts should be defined in user script, e.g.: var texts = new Array("<font color='{COLOR}' sized='+3' face='Arial'>howdy</font>");
	text_out = text_out.replace("{COLOR2}", colors2[color]);

    // actually write message to document
	htmlWrite(text_out, "fader");
	
	// select next fader color
	color += step; 
	
	// completely faded in?
	if (color >= colors.length-1) 
	{ 
		step = -1; // traverse colors array backward to fade out
		
		// stop at last message if loop=false
		if (!loop && text >= texts.length-1) return; // loop should be defined in user script, e.g.: var loop=true;
	}
	
	// completely faded out?
	if (color == 0)
	{
		step = 1; // traverse colors array forward to fade in again
		
		// select next message
		text += 1;
		if (text == texts.length) text = 0; // loop back to first message
	}
	
	// subtle timing logic...
	setTimeout("fade()", (color == colors.length-2 && step == -1) ? show : ((color == 1 && step == 1) ? sleep : 50)); // sleep and show should be defined in user script, e.g.: var sleep=30; var show=500;
}

// helper function to make fader cross browser compatible
function htmlWrite(html,id)
{
	var obj;
	if (document.getElementById) // IE 5+ & Netscape 6+
	{
		obj = document.getElementById(id);
		obj.innerHTML = html;
	}
	else if (document.all) // IE 4+
	{
		obj = document.all[id];
		obj.innerHTML = html;
	}
	else if (document.layers) // Netscape 4+
	{
		obj = document.layers[id];
		obj.document.open();
		obj.document.write(html);
		obj.document.close();
	}
}

// getFadeColors: fills Colors (predefined Array)
// with color hex strings fading from ColorA to ColorB
// note: Colors.length equals the number of steps to fade
function getFadeColors(ColorA, ColorB, Colors)
{
	var len = Colors.length; 
	
	// strip '#' signs if present 
	if (ColorA.charAt(0)=='#') ColorA = ColorA.substring(1);
	if (ColorB.charAt(0)=='#') ColorB = ColorB.substring(1);

	// substract rgb compents from hex string 
	var r = HexToInt(ColorA.substring(0,2));
	var g = HexToInt(ColorA.substring(2,4));
	var b = HexToInt(ColorA.substring(4,6));
	var r2 = HexToInt(ColorB.substring(0,2));
	var g2 = HexToInt(ColorB.substring(2,4));
	var b2 = HexToInt(ColorB.substring(4,6));

	// calculate size of step for each color component
	var rStep = Math.round((r2 - r) / len);
	var gStep = Math.round((g2 - g) / len);
	var bStep = Math.round((b2 - b) / len);
	
	// fill Colors array with fader colors
	for (i = 0; i < len-1; i++)
	{
		Colors[i] = "#" + IntToHex(r) + IntToHex(g) + IntToHex(b);
		r += rStep;
		g += gStep;
		b += bStep;
	}
	Colors[len-1] = "#" + ColorB; // make sure we finish exactly at ColorB
}

function getFadeColors2(ColorA, ColorB, Colors) {
var len = Colors.length;

// strip '#' signs if present
if (ColorA.charAt(0)=='#') ColorA = ColorA.substring(1);
if (ColorB.charAt(0)=='#') ColorB = ColorB.substring(1);

// substract rgb compents from hex string
var r = HexToInt(ColorA.substring(0,2));
var g = HexToInt(ColorA.substring(2,4));
var b = HexToInt(ColorA.substring(4,6));
var r2 = HexToInt(ColorB.substring(0,2));
var g2 = HexToInt(ColorB.substring(2,4));
var b2 = HexToInt(ColorB.substring(4,6));

// calculate size of step for each color component
var rStep = Math.round((r2 - r) / len);
var gStep = Math.round((g2 - g) / len);
var bStep = Math.round((b2 - b) / len);

// fill Colors array with fader colors
for (i = 0; i < len-1; i++) {
Colors[i] = "#" + IntToHex(r) + IntToHex(g) + IntToHex(b);
r += rStep;
g += gStep;
b += bStep;
}
Colors[len-1] = ColorB; // make sure we finish exactly at ColorB
}

// IntToHex: converts integers between 0-255 into a two digit hex string.
function IntToHex(n) 
{
	var result = n.toString(16);
	if (result.length==1) result = "0"+result;
	return result;
}

// HexToInt: converts two digit hex strings into integer.
function HexToInt(hex) 
{
	return parseInt(hex, 16); 
}


