//<![CDATA[

var map = null;
//<![CDATA[

// Check to see if this browser can run the Google API
var gmarkers = [];
var htmls = [];
var to_htmls = [];
var from_htmls = [];
var i=0;

// A function to create the marker and set up the event window
function createMarker(point,name,html) {
	var marker = new GMarker(point);

	// The info window version with the "to here" form open
	to_htmls[i] = html + '<br><table><tr><td><em class=blueish>DIRECTIONS</em><br><b>To SyncBASE from</b> / <a class=normal href="javascript:fromhere(' + i + ')">From SyncBASE to</a></td></tr></table>' +
	'<table><tr><td>this address:</td></tr><tr><td><form action="http://maps.google.com/maps" method="get" target="_blank">' +
	'<input type="text" SIZE=40 MAXLENGTH=48 name="saddr" id="saddr" value="" /><br>' +
	'<br><INPUT value="Get Directions" TYPE="SUBMIT">' +
	'<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() +
	// "(" + name + ")" +
	'"/>'+'</td></tr></table>';

	// The info window version with the "to here" form open
	from_htmls[i] = html + '<br><table><tr><td><em class=blueish>DIRECTIONS</em><br><a class=normal href="javascript:tohere(' + i + ')">To SyncBASE from</a> / <b>From SyncBASE to</b></td></tr></table>' +
	'<table><tr><td>this address:</td></tr><tr><td><form action="http://maps.google.com/maps" method="get"" target="_blank">' +
	'<input type="text" SIZE=40 MAXLENGTH=48 name="daddr" id="daddr" value="" /><br>' +
	'<br><INPUT value="Get Directions" TYPE="SUBMIT">' +
	'<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
	// "(" + name + ")" +
	'"/>'+'</td></tr></table>';

	// The inactive version of the direction info
        html = html + '<br><table><tr><td><em class=blueish>DIRECTIONS</em> (select which)<br><a class=normal href="javascript:tohere('+i+')">To SyncBASE from</a> / <a class=normal href="javascript:fromhere('+i+')">From SyncBASE to</a></td></tr></table>';

	GEvent.addListener(marker, "click", function() {
	marker.openInfoWindowHtml(html);
	});
	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	return marker;
}

// functions that open the directions forms
function tohere(i) {
	gmarkers[i].openInfoWindowHtml(to_htmls[i]);
}

function fromhere(i) {
	gmarkers[i].openInfoWindowHtml(from_htmls[i]);
}

// Display the map, with some controls and set the initial location
function loadGMap() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("divGMap"));
		map.addControl(new GLargeMapControl());
		//map.addControl(new GMapTypeControl());
		map.addControl(new GOverviewMapControl(new GSize(135,145)), new GControlPosition(G_ANCHOR_BOTTOM_RIGHT));
		map.addControl(new GScaleControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT));
		map.setCenter(new GLatLng(43.745813,-79.317239),14);
		// Set up markers with info windows 
		var point = new GLatLng(43.742013,-79.317239);
		var marker = createMarker(point,'SyncBASE','<br><table><tr valign=bottom><td><b>SyncBASE Inc.</b><br>85 Curlew Drive #103<br>Toronto, ON M3A 2P8</td><td>&nbsp;&nbsp;&nbsp;<img src="./GraphicsUI/welcomeMat_100x45.jpg"></td></tr></table>')
		map.addOverlay(marker);
	}
}
//]]>