//Copyright 2010 Empty Tomb, INC
//ph: 217-356-2262 ; e-mail: info@emptytomb.org

//This is an array, one number per year, starting at 2002.
//For example, the second line represents deaths in 2003, the third in 2004, and so on.
//The last line currently (as of 11march2011) represents those in 2011.
//To add a number to this array:
// 1.  Add a comma after the last number (but before any // on the line)
// 2.  Press 'ENTER' ('RETURN') to add a new line.
// 3.  Type the next number to add to the list.
// 4.  If desired, follow it with a space, //, and the number of the year.
// TAKE DILIGENT CARE to put // (two backward slashes) before ANYTHING EXCEPT the number of deaths and a comma (if not the last line).
var deathsPerYear = new Array(
						10900000,  //2002
						10803000,  //2003
						10889000,  //2004
						10643000,  //2005
						10503000,  //2006
						10142000,  //2007
						  9733000,  //2008
						  9216000,  //2009
						  8772000,  //2010
						  8087000,  //2011
						  8087000   //2012
);
var counterWrapper;
function updateDeathCounter(domElement, /*bool*/doRepeat) {
	counterWrapper = domElement;
	year = new Date().getFullYear();
	//Assume year/4 = leapyear.  This will need to be fixed in 2100.
	// Hopefully by then we won't need this anyway.
	secondsInYear = ( year/4 == Math.floor(year/4) ) ? 3600*24*366 : 3600*24*365;
	deathsPerSecond = deathsPerYear[year-2002]/secondsInYear;
	lastNewYearDayMs = new Date(year,0,1,0,0,0,0).getTime();
	elapsedSeconds = Math.round((new Date().getTime() - lastNewYearDayMs)/1000);
	elapsedDeaths = deathsPerSecond * elapsedSeconds;

	//now format the number using commas
	el = Math.floor(elapsedDeaths).toString();
	i = 3;
	while(i < el.length) {
		el = el.substring(0, el.length-i) + "," + el.substring(el.length - i);
		i += 4;
	}

	//now wrap the number in h1 tags
	domElement.innerHTML = '<h1 style="color:black; font-weight:bold; font-family:Arial,sansSerif; font-size:250%">' + el + '</h1>';
	if(doRepeat) setTimeout("updateDeathCounter(counterWrapper,true)",1000);
}


function printSource() {
	document.write("The child-death <a href='http://www.emptytomb.org'>counter</a> for 2011 was based on 2009 data which was obtained from <i>The State of the World's Children [2011] Statistical Tables</i> (New York: UNICEF, 2009), p.11. SOWC_Spec_Ed_CRC_Statistical_Tables_EN_111809   <a href='http://www.unicef.org/sowc2011/pdfs/SOWC-2011-Statistical-tables_12082010.pdf'>http://www.unicef.org/sowc2011/pdfs/SOWC-2011-Statistical-tables_12082010.pdf</a>. The 8,087,000 annual child deaths were divided by the number of seconds in the year.");
}

