function maind()
{
	if(PBS_FlashCanPlay(5)) {
		// do nothing
	} else {
		startdate = new Date()
		now(startdate.getYear(),startdate.getMonth(),startdate.getDate(),startdate.getHours(),startdate.getMinutes(),startdate.getSeconds())
	}
}

function ChangeValue(number,pv)
{
	numberstring =""
	var j=0
	var i=0
	while (number > 1)
	 {
	    numberstring = (Math.round(number-0.5) % 10) + numberstring
	    number= number / 10
	    j++
	    if (number > 1 && j==3) {
			numberstring = "," + numberstring
			j=0}
	    i++
	 }
	 numberstring= " " + numberstring

	if (pv==1) { document.output_world.output_world.value = numberstring }
	if (pv==2) {document.output_loaded.output_loaded.value = numberstring}
}

function now(year,month,date,hours,minutes,seconds)
{
	// now date 03/05/2004 21:59:19 6352402806
	// now 2 date 03/08/2004 14:49:26 6352944542
	// now 2 - now = 252063 seconds
	
	// update 050524
	// now date  03/05/2004 16:48:23 6352359505
	// now2 date 05/24/2005 14:58:54 6443461201
	// now 2 - now = 38437831 seconds
	

	startdatepass = new Date(year,month,date,hours,minutes,seconds)
	var now = 6352359505.0
	var now2 = 6443461201.0
	
	var g_poprate = (now2 - now) / 38437831
	current_time = new Date ()
	// current_time = new Date (2005,4,24,14,58,54,0)    // for establishing now2-now second count
	basedate = new Date (2004,2,5,16,48,23,0)
	elapsed_load_t = (current_time.getTime() - startdatepass.getTime())/1000
	elapsed_base_t = (current_time.getTime() - basedate.getTime())/1000
	// alert(elapsed_base_t)
	elapsed_base_p = elapsed_base_t * g_poprate
	current_p = now + elapsed_base_p

	ChangeValue(current_p,1);
	ChangeValue(elapsed_load_t*g_poprate,2);
	timerID = setTimeout("now(startdatepass.getYear(),startdatepass.getMonth(),startdatepass.getDate(),startdatepass.getHours(),startdatepass.getMinutes(),startdatepass.getSeconds())",1000)
}

function show_home()
{
	var whichImage = Math.round(Math.random()*(3)) + 1;
	document.write('<img name=\"witbhome\" id=\"witbhome\" src=\"/wgbh/nova/worldbalance/images/worldbalance-home-'+whichImage+'.jpg\" alt=\"World in the Balance: NOVA investigates the impact of forces that are radically changing populations in both rich and poor nations. Airs on PBS April 20 at 8 pm\" width=\"800\" height=\"219\" border=\"0\" \/>');
}	

function counter_insert()
{
	// In this section we set up the content to be placed dynamically on the page.
	if(PBS_FlashCanPlay(5)) {
		// if we've detected an acceptable version
    var oeTags = '<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td bgcolor="#C3E884">'
    + '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'width="800" height="26"'
    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0">'
    + '<param name="MOVIE" value="/wgbh/nova/worldbalance/media/counter02.swf" />'
    + '<param name="PLAY" value="true" />'
    + '<param name="LOOP" value="false" />'
    + '<param name="QUALITY" value="high" />'
    + '<param name="MENU" value="false" />'
    + '<param name="bgcolor" value="#C3E884" />'
    + '<embed src="/wgbh/nova/worldbalance/media/counter02.swf" '
    + 'width="800" height="26" '
    + 'bgcolor="#C3E884" '
    + 'play="true" '
    + 'loop="false" '
    + 'quality="high" '
    + 'menu="false" '
    + 'type="application/x-shockwave-flash"'
    + 'pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
    + '\</embed>'
    + '\</object>'
    + '\</td>\</tr>\</table>';

    document.write(oeTags);   // embed the flash movie
  } else {  // flash is too old or we can't detect the plugin
		var alternateContent = '<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr><td bgcolor="#C3E884">'
    + '<table><tr>'
    + '<td><img src="/wgbh/nova/images02/spacer.gif" alt="" width="22" height="1" border="0" />\</td>'
    + '<td valign="middle"><form name="output_world"><img src="/wgbh/nova/images02/spacer.gif" width=25 height=1 border=0 alt=" ">World population:&nbsp;&nbsp;<input type="text" size="15" name="output_world" class="novanav">\</td>'
    + '<td><img src="/wgbh/nova/images02/spacer.gif" alt="" width="65" height="1" border="0" />\</td>'
    + '<td valign="middle">\</form><form name="output_loaded">Babies born since you loaded this page:&nbsp;&nbsp;<input type="text" size="3" name="output_loaded" class="novanav">\</td>'
    + '\</tr>\</table>'
    + '\</td>\</tr>\</table>';

		document.write(alternateContent);  // insert non-flash content
  }

}