function fsmotto() {
	var motto=new Array();
	motto[0] = "Virtually...the best.";
	motto[1] = "Free Spirits are willing but the flesh is weak.";
	motto[2] = "Every metre matters.";
	motto[3] = "Every meter matters";
	motto[4] = "Fat or thin, fast or slow: just row.";
	motto[5] = "Unleash the power of the Free Spirits....row better, faster, farther!";
	motto[6] = "I love rowing, I hate rowing, I love rowing, I hate rowing...";
	motto[7] = "100m or 1 million - everybody and every metre welcome.";
	motto[8] = "Pull, pull and pull again.";
	motto[9] = "Catch, drive, glide, recover, repeat.";
	motto[10] = "100m or 1 million - everybody and every meter welcome.";
	motto[11] = "By gum, Jupiter is big!";
	motto[12] = "Every metre counts, every day counts, everybody counts.";
	motto[13] = "Every meter counts, every day counts, everybody counts.";
	motto[14] = "I row, ergo, I am.";
	motto[15] = "Free Spirits - 100% proof.";
	return motto[Math.round(Math.random()*(motto.length-1))];
}

function moon_message() {
	return "<small>535 rowers who rowed 432 million metres last season.<br/>Don't worry, the meter board will return!</small>";
}


function moon() {  
	//var sMess = "";
	var meterboard = fsvars();
	var no_rowers = meterboard[2];
	var rM = ""; //race message
	var distance_to_moon = 365000000; // 1 million a day!
	var jtm = journeytothemoon(distance_to_moon);
	var mtp = moon_time_percent();
	var rMP = Math.round((jtm - mtp)*100)/100;
	if (rMP < 0)
	{ rMP = rMP*-1; rM = rMP + "% behind"; }
	else if (rMP == 0) 
	{ rM = "on target!  "; }
	else
	{ rM = rMP + "% ahead - "; }
	var leadtxt = "<a style=\"color: white; text-decoration: underline;\" href=\"http://www.meterboard.com\">" + no_rowers + "</a> people <a title=\"Graphs of the journey\"  style=\"color: white; text-decoration: underline;\" href=\"http://www.freespiritsrowing.com/content/index.php?page=moon_shot#graphs\"> trying for 1Mm a day</a>: ";
	// how many laps of the Earth?
	//var earth_circ = 40075160;
	//var team_metres = meterboard[1];
	// var timesround = Math.round(((team_metres)/earth_circ)*100)/100;
	// if (timesround > 0) { rM += timesround + " laps out of 10"; }
	return leadtxt + jtm + "% (" + rM + ")";
	//return "Stats suspended (waiting for <a style=\"color: white; text-decoration: underline;\" href=\"http://www.meterboard.com\">meterboard.com</a> to reset)";
}


function moonbackup() {
	// metres to get home: 385809003 - see http://spreadsheets.google.com/pub?key=pEox89_OagSIQAQfyhUWXFA
	var meterboard = fsvars();
	var no_rowers = meterboard[2];
	return "<small><br/>" + no_rowers + " rowers planning their journey home <img src=\"http://www.freespiritsrowing.com/forum/images/smiles/fssmall_grin.gif\" width=\"15\" height=\"15\"/> (watch this space)</small>";

}

function moon_old() {
	var meterboard = fsvars();
	var no_rowers = meterboard[2];
	var rM = ""; //race message
	var jtm = journeytothemoon();
	var mtp = moon_time_percent();
	var rMP = Math.round((jtm - mtp)*100)/100;
	if (rMP < 0)
	{ rMP = rMP*-1; rM = rMP + "% behind target"; }
	else if (rMP == 0) 
	{ rM = "bang on target!"; }
	else
	{ rM = rMP + "% ahead of target"; }
	var leadtxt = "<small><a style=\"color: white\" href=\"http://www.meterboard.com\">" + no_rowers + "</a> rowers <a title=\"Graphs of the return home\" style=\"color: white\" href=\"http://www.freespiritsrowing.com/content/index.php?page=moon_shot#graphs\">coming home</a>: ";
	return leadtxt + journeytothemoon() + "% (" + rM + ")</small>";
}



function journeytothemoon(distance_to_moon) {
	var meterboard = fsvars();
	var team_metres = meterboard[1];
	//var team_numbers = meterboard[2];
	//var distance_to_moon = 384403000;
	//var distance_to_moon = 393860997 // actually the journey home
	var percentage_of_journey = Math.round((team_metres/distance_to_moon)*10000)/100;
	//var metres_per_member = team_metres/team_numbers;
	return percentage_of_journey;
}
function moon_progress() {
	var meterboard = fsvars();
	var team_metres = meterboard[1];
	return addCommas(team_metres) + "m out of 384,403,000m"
}
function moon_time_percent() {
	var today = new Date()
	var stdate = new Date("May 01, 2011")  //adjust date, site created
	var offset = today.getTimezoneOffset() * 60 * 1000;
	var msPerDay = 24 * 60 * 60 * 1000 ;
	var daysUp = (( offset + today.getTime() - stdate.getTime() ) / msPerDay ) / 365;
	//var daysUp = (( today.getTime() - stdate.getTime() ) / msPerDay ) / 365;
	return Math.round(daysUp*10000)/100;
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
