//<![CDATA[
// 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();
	}
}

// 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); 
}


function textfader(divname) {
    this.divname = divname;
    this.color = 0;
	this.steps = 20;
	this.colors = new Array(this.steps);
	this.text=0;
	this.step = 1;
 //   this.texts = new Array("Family<br />Reunions","Hostess<br />Gifts","Corporate<br />Training","Game<br />Nights","Party<br />Favors");
	this.texts=["<em>Birthday presents &amp; teachers gifts</em><br />- Susan F.",
                "<em>Girls' weekend</em><br />- Laura B.",
				"<em>Christmas eve</em><br />- Lynne",
				"<em>At wedding receptions</em><br />- Buddy R.",
				"<em>In the classroom</em><br />- Karen L.",
				"<em>For business meetings</em><br />- Anne H.",
				"<em>Family night activity</em><br />- A. Marshal",
				"<em>To get to know my kids better</em><br />- Janet M.",
				"<em>As the perfect gift</em><br />- Lynn",
				"<em>In speech therapy</em><br />- Amy E.",
				"<em>During counseling sessions</em><br />- Rita",
				"<em>For church groups</em><br />- Amy H",
				"<em>Talking instead of texting</em><br />- Christopher",
				"<em>For English class, prompts for writing essays</em><br />- Chad A.",
				"<em>Dinner conversations for all ages</em><br />- Lisa P.",
				"<em>Kids birthday party game</em><br />- Angelique",
				//"<em>To help children be more comfortable starting conversations</em><br />- Tamara G.",
				"<em>Long distance phone calls with relatives</em><br />- Amy",
				"<em>To practice sign language</em><br />- Amy M.",
				"<em>A tool for English as a second language</em><br />- Teresa G.",
				"<em>During long car rides</em><br />- Stephanie E.",
				"<em>Coffee table decor and game</em><br />- Mary C.",
				"<em>Thanksgiving dinner</em><br />- Mary",
				"<em>To get to know new friends</em><br />- J. Patton"];	
	this.show = 1000; // milliseconds to display message
    this.sleep = 30; // milliseconds to pause inbetween messages
//	this.textformathdr="<font color='{COLOR}' size='10pt'>"; // can be any formatting, but has to include "{COLOR)'
//  this.textformatftr="</font>";
	this.textformathdr="<p style='font-weight: normal; text-decoration: none; text-align: center; font-size: 16px; line-height: 18px;'><a href='\giftguide.htm' style='text-decoration:none; color:{COLOR};'>";
    this.textformatftr="</a></p>";
    this.loop = true; // true = continue to display messages, false = stop at last message
    this.getText = function() {
        return this.textformathdr.replace("{COLOR}", this.colors[this.color])+this.texts[this.text]+this.textformatftr; 	
    };
}

// fade: this does the actual fading. Make sure you call setTimeOut recursively!
textfader.prototype.fade=function()
{
    // actually write message to document
	htmlWrite(this.getText(), this.divname);	
	// select next fader color
	this.color += this.step; 
	// completely faded in?
	if (this.color >= this.colors.length-1) 
	{ 
		this.step = -1; // traverse colors array backward to fade out
		
		// stop at last message if loop=false
		if (!this.loop && this.text >= this.texts.length-1) return; // loop should be defined in user script, e.g.: var loop=true;
	}
	
	// completely faded out?
	if (this.color == 0)
	{
		this.step = 1; // traverse colors array forward to fade in again
		
		// select next message
		this.text += 1;
		if (this.text == this.texts.length) this.text = 0; // loop back to first message
	}
	
	// subtle timing logic...
	setTimeout("PennyStonesFader.fade()", (this.color == this.colors.length-2 && this.step == -1) ? this.show : ((this.color == 1 && this.step == 1) ? this.sleep : 50)); 
}

// setColors: fills Colors (predefined Array)
// with color hex strings fading from ColorA to ColorB
// note: Colors.length equals the number of steps to fade
textfader.prototype.setColors=function(ColorA, ColorB)
{
	len = this.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++)
	{
		this.colors[i] = "#" + IntToHex(r) + IntToHex(g) + IntToHex(b);
		r += rStep;
		g += gStep;
		b += bStep;
	}
	this.colors[len-1] = "#" + ColorB; // make sure we finish exactly at ColorB
}


PennyStonesFader=new textfader('fader');
PennyStonesFader.setColors("#BDB1D5","#5F519E"); //"#000000"); // background, foreground


    //]]>