//Allow IE4 to work with us.
if(!document.getElementById && document.all){
	document.getElementById = function(id) {return document.all[id];}
	}

/*ticker functions adapted from BBC News site*/

var theCharacterTimeout = 50;
var theStoryTimeout     = 3000;
var theWidgetOne        = "_";
var theWidgetTwo        = "-";
var theWidgetNone       = "";
var theLeadString       = "";

var theTips = new Array();

	//update or add tips here, single quotes are OK

	theTips[0] = "Change or clean your<br />filter once a month";

theTips[1] = "Install a<br />programmable thermostat";

theTips[2] = "Install more<br />attic insulation.";

	theTips[3] = "Seal up your<br />home before winter ";

theTips[4] = "Use thick curtains  ";

theTips[5] = "Take showers<br />instead of baths";

theTips[6] = "Don't run the dishwasher<br />unless you have a full load ";
	

	theTips[7] = "Switch from light<br />bulbs to CFC bulbs";

	
	theTips[8] = "Install light dimmers ";
	
	theTips[9] = "Unplug devices<br />from electrical outlets.";

	//end tips
	
var theItemCount = theTips.length;

if ((document.getElementById) && (document.body.innerHTML)) {
	//write div for dhtml broswers to display tips
	document.write("<div class='ticker'><a id='tickerAnchor' href='#' target='_top'></a></div>");
	}else{
	//write div for non-dynamic browsers and display random tip	
	document.write("<div class='ticker'>" + theLeadString + theTips[Math.round(Math.random() * (theTips.length -1))] + "</div>");
	}	

	
// Ticker startup
function startTicker()
{
	// Define run time values
	theCurrentStory     = -1;
	theCurrentLength    = 0;
	// Locate base objects
	if (document.getElementById) {	
		    theAnchorObject     = document.getElementById("tickerAnchor");
			runTheTicker();   	
		 }	
}

// Ticker main run loop
function runTheTicker()
{
	var myTimeout;  
	// Go for the next story data block
	if(theCurrentLength == 0)
	{	
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = theTips[theCurrentStory].replace(/&quot;/g,'"');				
		thePrefix 	     = "<span class=\"tickerLeadString\">" + theLeadString + "</span>";
	}
	// Stuff the current ticker text into the anchor
	theAnchorObject.innerHTML = thePrefix + 
	theStorySummary.substring(0,theCurrentLength) + whatWidget();
	// Modify the length for the substring and define the timer
	if(theCurrentLength != theStorySummary.length)
	{
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else
	{
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}

// Widget generator
function whatWidget()
{
	if(theCurrentLength == theStorySummary.length)
	{
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}

startTicker();
