//<![CDATA[
var openGyms = [
	{
		"name": "Independence High School",
		"address": "6602 N. 75th Ave., Glendale, AZ 85303",
		"addlLocInfo": "On Maryland Ave., Between Glendale Rd. & Bethany Home Rd.  The gym is located next to the football field.",
		"hours": "Tuesdays from 7:00pm to 10:00pm",
		"contact": "<a href=\"mailto:azsmash@gmail.com\">Arizona Badminton Club</a>",
		"courts": "8",
		"fee": "<a href=\"docs/azbcform.pdf\" target=\"_blank\">Membership</a>"
	},
	{
		"name": "Foothills Recreation &amp; Aquatics Center",
		"address": "5600 W. Union Hills Dr., Glendale, AZ 85308",
		"addlLocInfo": "",
		"hours": "Sundays from 11:00am to 1:45pm",
		"contact": "(623) 930-4600",
		"courts": "4",
		"fee": "$5/person for Glendale residents, $6/person for non-Glendale residents"
	},
	{
		"name": "Goelet A.C. Beuf Community Centre",
		"address": "3435 W. Pinnacle Peak, Phoenix, Arizona 85027-1021",
		"addlLocInfo": "SE Corner of Pinnacle Peak and 34th Ave.",
		"hours": "Saturdays from 5:45pm to 7:45pm",
		"contact": "(602) 534-4754",
		"courts": "4",
		"fee": "$2/person (exact change only)"
	},
	{
		"name": "Deer Valley Community Centre",
		"address": "2001 W. Wahalla Lane, Phoenix, AZ 85027",
		"addlLocInfo": "SW corner of Loop 101 and 19th Avenue.",
		"hours": "Mondays from 7:00pm to 8:45pm and Saturdays from 3:00pm to 5:30pm",
		"contact": "(602) 495-3735",
		"courts": "4",
		"fee": "$2/person"
	},
	{
		"name": "Central Christian Church",
		"address": "933 N. Lindsay Rd, Mesa AZ 85213-6048",
		"addlLocInfo": "SW corner of Lindsay and Brown Rds. The gym is located at the rear of the campus.",
		"hours": "Sundays from 2:30PM to 5:00PM",
		"contact": "<a href=\"mailto:markscarano@juno.com\">Mark Scarano</a>",
		"courts": "8",
		"fee": "None at this time"
	},
	{
		"name": "Downtown Phoenix YMCA",
		"address": "350 N. 1st Ave, Phoenix, AZ 85003",
		"addlLocInfo": "Between Van Buren & Fillmore. The gym is located on the 2nd floor next to racquetball and basketball courts.",
		"hours": "Tuesdays and Thursdays from 1:15pm to 3:15pm, Saturdays from 10:00am to 1:00pm, Sundays from 12:00pm to 2:00pm",
		"contact": "(602) 257-5138",
		"courts": "3",
		"fee": "$25 one-time fee + $30 program fee (good for 12 visits)"
	},
	{
		"name": "McQueen Park Activity Centre",
		"address": "510 N. Horne Street, Gilbert, AZ 85233",
		"addlLocInfo": "",
		"hours": "Wednesdays and Fridays from 5:45pm to 8:45pm, Saturdays from 1:00pm to 5:00pm",
		"contact": "(480) 503-6294",
		"courts": "3",
		"fee": "$2/person for Gilbert residents, $3/person for non-Gilbert residents"
	},
	{
		"name": "Pecos Activity Centre",
		"address": "17010 South 48th Street, Phoenix, AZ 85048",
		"addlLocInfo": "Must enter the Park from 48th Street, via Chandler Blvd.  No access off of Pecos Parkway.",
		"hours": "1st and 3rd Saturdays of the month from 7:00pm to 9:00pm",
		"contact": "(602) 262-6111",
		"courts": "3",
		"fee": "Free"
	},
	{
		"name": "Ahwatukee Foothills Family YMCA",
		"address": "1030 E. Liberty Lane, Phoenix, AZ 85048",
		"addlLocInfo": "",
		"hours": "Sundays 3:00pm to 7:30pm",
		"contact": "(480) 759-6762",
		"courts": "3",
		"fee": "$10/person"
//	},
//	{
//		"name": "Chandler High School",
//		"address": "350 N. Arizona Ave., Chandler, AZ 85225-4578",
//		"addlLocInfo": "In the Payne Gymnasium.",
//		"hours": "Tuesdays through Fridays from 6:00pm to 9:00pm",
//		"contact": "",
//		"courts": "8",
//		"fee": "$2/person"
//	},
//	{
//		"name": "Horizon High School",
//		"address": "5601 E Greenway Rd., Scottsdale, AZ 85254",
//		"addlLocInfo": "",
//		"hours": "Mondays 6:30pm to 8:30pm.  From March 30th to May 11th. only",
//		"contact": "",
//		"courts": "8",
//		"fee": "Free"
	}
];

var map;

function createMarkers() {
	var mgr = new GMarkerManager(map);
	var geocoder = new GClientGeocoder();
	var markers = [];

	for (var i in openGyms) {
		geocoder.getLatLng(openGyms[i].address, function(point) {
			var marker = new GMarker(point);

			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml(openGyms[i].name + "<br><br>" + openGyms[i].address);
			});

			markers.push(marker);
		});
	}

	mgr.addMarkers(markers);
	mgr.refresh();
}

function createMarker(openGym) {
	var geocoder = new GClientGeocoder();
	var infoTabs = createInfoTabs(openGym);

	geocoder.getLatLng(openGym.address, function(point) {
		var marker = new GMarker(point);

		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowTabsHtml(infoTabs);
		});

		map.addOverlay(marker);
	});
}

function createInfoTabs(openGym) {
	var locationTab =
		"<table border=0 cellpadding=0 cellspacing=0 style='width:240px;'>" +
		"	<tr style='padding-bottom:5px;'>" +
		"		<td style='font-weight:bold;text-align:left;'>" + openGym.name + "</td>" +
		"	</tr>" +
		"	<tr style='padding-bottom:5px;'>" +
		"		<td style='text-align:left;'>" + openGym.address + "</td>" +
		"	</tr>";

	if (openGym.addlLocInfo != "") {
		locationTab +=
			"	<tr style='padding-bottom:5px;'>" +
			"		<td style='text-align:left;'>(" + openGym.addlLocInfo + ")</td>" +
			"	</tr>";
	}

	locationTab += "</table>";

	var detailsTab =
		"<table border=0 cellpadding=0 cellspacing=0 style='width:240px;'>" +
		"	<tr style='padding-bottom:5px;'>" +
		"		<td style='vertical-align:top;text-align:left;width:1px;'>Schedule:</td>" +
		"		<td style='width:1px;'>&nbsp;&nbsp;</td>" +
		"		<td style='text-align:left;'>" + openGym.hours + "</td>" +
		"	</tr>" +
		"	<tr style='padding-bottom:5px;'>" +
		"		<td style='vertical-align:top;text-align:left;width:1px;'>Fee:</td>" +
		"		<td style='width:1px;'>&nbsp;&nbsp;</td>" +
		"		<td style='text-align:left;'>" + openGym.fee + "</td>" +
		"	</tr>" +
		"	<tr style='padding-bottom:5px;'>" +
		"		<td style='vertical-align:top;text-align:left;width:1px;'>Contact:</td>" +
		"		<td style='width:1px;'>&nbsp;&nbsp;</td>" +
		"		<td style='text-align:left;'>" + openGym.contact + "</td>" +
		"	</tr>" +
		"	<tr style='padding-bottom:5px;'>" +
		"		<td style='vertical-align:top;text-align:left;width:1px;'>Courts:</td>" +
		"		<td style='width:1px;'>&nbsp;&nbsp;</td>" +
		"		<td style='text-align:left;'>" + openGym.courts + "</td>" +
		"	</tr>" +
		"</table>";

	var infoTabs = [
		new GInfoWindowTab("Location", locationTab),
		new GInfoWindowTab("Details", detailsTab)
	];

	return infoTabs;
}

function load() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));

//		GEvent.addListener(map, "moveend", function() {
//			var center = map.getCenter();
//			document.getElementById("message").innerHTML = center.toString();
//		});


//		map.addControl(new GLargeMapControl());
//		map.addControl(new GMapTypeControl());
//		map.addControl(new GOverviewMapControl());
		map.addControl(new GScaleControl());

		for (var i in openGyms) {
			createMarker(openGyms[i]);
		}

		map.setCenter(new GLatLng(33.5184992376561, -111.99600219726562), 10);
	}
}

function displayOpenGym(openGym) {
	document.writeln("<table class=\"openGyms\">");
	document.writeln("<tr>");
	document.writeln("<th>" + openGym.name + "</th>");
	document.writeln("</tr>");
	document.writeln("<tr>");
	document.writeln("<td>");
	document.writeln("<table class=\"openGymDetail\">");
	document.writeln("<tr>");
	document.writeln("<td style=\"width:15%;\">Address:</td>");
	document.writeln("<td style=\"width:85%;\">" + openGym.address + "</td>");
	document.writeln("</tr>");

	if (openGym.addlLocInfo != "") {
		document.writeln("<tr>");
		document.writeln("<td></td>");
		document.writeln("<td>" + openGym.addlLocInfo + "</td>");
		document.writeln("</tr>");
	}

	document.writeln("<tr>");
	document.writeln("<td>Schedule:</td>");
	document.writeln("<td>" + openGym.hours + "</td>");
	document.writeln("</tr>");
	document.writeln("<tr>");
	document.writeln("<td>Fee:</td>");
	document.writeln("<td>" + openGym.fee + "</td>");
	document.writeln("</tr>");
	document.writeln("<tr>");
	document.writeln("<td>Contact:</td>");
	document.writeln("<td>" + openGym.contact + "</td>");
	document.writeln("</tr>");
	document.writeln("<tr>");
	document.writeln("<td>Courts:</td>");
	document.writeln("<td>" + openGym.courts + "</td>");
	document.writeln("</tr>");
	document.writeln("</table>");
	document.writeln("</td>");
	document.writeln("</tr>");
	document.writeln("</table>");
}
//]]>
