// JavaScript Document

var Widget = 
[
"<h1>Buying a new home? Indoor airPLUS helps protect your environment inside and out. <br/><a target=\"_parent\" href=\"http://www.epa.gov/indoorairplus/index.html\">Learn more</a></h1>"
];

var itemNumber = 0;
var duration = 4;

function writeWidget()
{
	// for a self running display (for debugging) comment out the line below
 	// cycleclimateChange(); return;
	
	// set according to day
	var startDate = new Date();
	startDate.setFullYear(2008,6,24); // Note: month is zero-based (0 through 11)
	
	var todaysDate = new Date();
	// The commented out line below can change what "today" is for testing
    //todaysDate.setFullYear(2008,6,24);
	
	// Set the itemNumber is equal to the number of days that have elapsed since startDate.
	// days = milliseconds / 86400000 (24 hours * 60 mins * 60 secs * 1000 milisecs)
	itemNumber = Math.floor((todaysDate.getTime() - startDate.getTime()) / 86400000);
	
	// If item number is > items, then we are past the specific dates for which we wanted
	// to show the items in order, so just show a random item
	if (itemNumber >= Widget.length) 
	{
		itemNumber = Math.floor((100 * Math.random()) % Widget.length);
	}
	
	// alert(itemNumber);
	writeToDocument();
}

function cycleWidget()
{
	writeToDocument();
	itemNumber += 1;
	// Show a new one every <duration> seconds
	self.setTimeout("cycleWidget()", duration * 1000)
}

function writeToDocument()
{
	elem = document.getElementById("widget");
	elem.innerHTML = Widget[itemNumber];
}// JavaScript Document