/*
NOTE: Tips text are stored in a javascript file linked to in the head section of the HTML page.
*/

//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       = "<h2>Did you know...</h2>";

var theTips = new Array();

//update or add tips here, single quotes are OK


theTips[0] = "Cleve West has decided to leave his trees behind after discovering families of blackbirds and blue-tits nesting in them.";
theTips[1] = "Seven of the 19 show gardens won gold medals, a further five received Silver-Gilt Flora medals.";
theTips[2] = "The Daily Telegraph Garden won Best in Show. More results can be found on the gardens pages.";
theTips[3] = "In the Great Pavilion 44 nurseries and plant exhibitors won gold medals.";
//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' id='tickerAnchor'></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();