//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       = "Did you know...?&nbsp;";

var theTips = new Array();

	//update or add tips here, single quotes are OK

	theTips[0] = "By turning your thermostat down by one degree, you could reduce your gas bill by 10%.";

theTips[1] = "Flushing the toilet with the lid up ejects an aerosol-like plume of germs around the bathroom that float for up to two hours.";

theTips[2] = "40% of all heat lost in the home is through the loft and walls.";

	theTips[3] = "The average dish cloth contains a million times more bacteria than a toilet seat.";

theTips[4] = "85% of electricity is used by TVs and VCRs when they are on standby.  ";

theTips[5] = "A clean doormat can capture 70% of the dirt walked into a home.";

theTips[6] = "The average mattress can house up to 10 million dust mites.";
	

	theTips[7] = "We lose about a pint of sweat during sleep every night and 5g of skin each week.";

	
	theTips[8] = "One gram of house dust can contain up to 500 dust mites.";
	
	theTips[9] = "25% of a two-year-old pillow can be made up of dust mites and their faeces.";

	theTips[10] = "76% of women make beds daily compared to 46% of men.";

	
	theTips[11] = "A year's bed-making is equivalent to a four-mile walk.";

	theTips[12] = "25% of the contents of a vacuum cleaner is human skin.";


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