// used by load() below
function create_marker(location)
{
	var point = new GLatLng(location.geolat, location.geolon);
	var marker = new GMarker(point, { title: location.title });

	GEvent.addListener(marker, 'click', function() { showInfo(marker, location); } );

	return marker;
}

function showInfo(marker, location)
{
	var s = '<div class="infowindow">';

	s += '<div class="title">The ManKind Project of ' + location.title + '</div>';

	if (location.address)
		s += '<div class="address"><span class="label">Address:</span> ' + location.address + '</div>';

	if (location.contact)
		s += '<div class="contact"><span class="label">Contact:</span> ' + location.contact + '</div>';

	if (location.phone)
		s += '<div class="phone"><span class="label">Phone:</span> ' + location.phone + '</div>';

	if (location.site)
		s += '<div class="site"><span class="label">Web Site:</span> <a target="_blank" href="http://'
			+ location.site + '">' + location.site + '</a></div>';

	if (location.mail)
		s += '<div class="mail"><span class="label">E-Mail:</span> <a href="mailto:'
			+ location.mail + '">' + location.mail + '</a></div>';

	if (location.geoaddr)
		s += '<div class="directions">&raquo; <a target="_blank" href="http://maps.google.com?q='
			+ location.geoaddr + '">Get Directions</a> &laquo;</div>';

	s += '</div>';

	marker.openInfoWindowHtml(s);
}

// referenced by <body onload="load">
function load(cid)
{
	if (!GBrowserIsCompatible())
	{
		return;
	}

	var map = new GMap2(document.getElementById("map"));

	// Center the map. This must be done before placing markers on it or it doesn't work.

	// This location is 19.809874 degrees south of Lebanon, KS, USA.
	// Lebanon KS was chosed as the geographical center of the US.
	// 19 degrees south slides the map up a bit so that New Zealand,
	// South Africa and Australia are nicely in view at this zoom level.

	var point = new GLatLng(20, -98.560706);
	map.setCenter(point, 2);

	map.enableScrollWheelZoom();
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());

	for (var i = 0 ; i < Centers.length ; i++)
	{
		var center = Centers[i];
		var marker = create_marker(center);
		map.addOverlay(marker);

		if (center.cid == cid)
		{
			var point = new GLatLng(center.geolat, center.geolon);
			map.setCenter(point, 12);
			showInfo(marker, center);
		}
	}
}
