// ####################################################################
//	Title:	fade_blink01.js
//	Auth:	JCM Software
//	Purp:	Javascript variables and routines for fading the color of texts.
// 
//	Copyright ©2005, JCM Software, http://www.drdoz.com/jcm, All rights reserved.
//
// *****   NOTE:  body tag must include: onload="fade()" bgcolor="#000000"
// ####################################################################

//  texts:
//  Messages may contain regular html tags but
//  must at least contain: [ <font color='{COLOR}'> ]
//  Use single quotes [ ' ] in your html only. If you need
//  a double quote in the message itself use an escape
//  sign like this: [ \" ]  (not including the brackets)

var texts01 = new Array(
//"<font size='1' color='{col}' face='verdana,ariel,helvetica,sans-serif'><strong>©&nbsp;BridgeMusico.com&nbsp;</strong></font>"
//"<font color='{col}'><b>Congratulations to the GRAND PRIZE WINNER - Nikki!</b></font>"
"<font color='{col}'><b>NEW CONTEST!</b></font>"
);

var bgcolor01 = "#FFFFFF"; // background color, must be valid browser hex color (not color names)
var fcolor01 = "#AA0000";  // foreground or font color

//var steps01 = 60; // number of steps to fade
var steps01 = 20; // number of steps to fade
//var show01 = 2500; // milliseconds to display message
var show01 = 250; // milliseconds to display message
var sleep01 = 90; // milliseconds to pause inbetween messages
var loop01 = true; // true = continue to display messages, false = stop at last message

//-------------------------------------------------------------------------------------------------------------------------------------------
// ----------  Do Not Edit Below This Line  ---------------
var colors01 = new Array(steps01);
getFadeColors01(bgcolor01,fcolor01,colors01);
var color01 = 0;
var text01 = 0;
var step0 = 1;
var step01 = step0;


//-------------------------------------------------------------------------------------------------------------------------------------------
// fade: magic fader function
function fade_blink01() {

// insert fader color into message
var text_out = texts01[text01].replace("{col}", colors01[color01]);

// actually write message to document
if (document.all) fader_blink01.innerHTML = text_out; // document.all = IE only
if (document.layers) { document.fader_blink01.document.write(text_out); document.fader_blink01.document.close(); } // document.layers = Netscape only

// select next fader color
color01 += step01;

// completely faded in?
if (color01 >= colors01.length-1) {
step01 = -step0; // traverse colors array backward to fade out

// stop at last message if loop=false
if (!loop01 && text01 >= texts01.length-1) return; // loop should be defined in user script, e.g.: var loop=true;
}

// completely faded out?
if (color01 == 0) {
step01 = step0; // traverse colors array forward to fade in again

// select next message
text01 += 1;
if (text01 == texts01.length) text01 = 0; // loop back to first message
}

// subtle timing logic...
setTimeout("fade_blink01()", (color01 == colors01.length-2 && step01 == -step0) ? show01 : ((color01 == 1 && step01 == step0) ? sleep01 : 15)); // sleep and show should be defined in user script, e.g.: var sleep=30; var show=500;
}

//-------------------------------------------------------------------------------------------------------------------------------------------
// 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 getFadeColors01(ColorA, ColorB, Colors) {
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 = HexToInt01(ColorA.substring(0,2));
var g = HexToInt01(ColorA.substring(2,4));
var b = HexToInt01(ColorA.substring(4,6));
var r2 = HexToInt01(ColorB.substring(0,2));
var g2 = HexToInt01(ColorB.substring(2,4));
var b2 = HexToInt01(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] = "#" + IntToHex01(r) + IntToHex01(g) + IntToHex01(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 IntToHex01(n) {
var result = n.toString(16);
if (result.length==1) result = "0"+result;
return result;
}

//-------------------------------------------------------------------------------------------------------------------------------------------
// HexToInt: converts two digit hex strings into integer.
function HexToInt01(hex) {
return parseInt(hex, 16);
}

// *****   NOTE:  body tag must include: onload="fade()" bgcolor="#000000" 

