var gmarkers = [];
var htmls = [];
var to_htmls = [];
var from_htmls = [];
var i=0;
var fullHtml;
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// chooseLocation
	//
	//
	//
function chooseLocation() {
	if(!document.getElementById("gMap")) return false;
	var lat = 28.459354;
	var lon = -81.490488;
	var name = 'Bay Hill Eyecare';
	var initHtml = '<b>Address:</b><br/>7051 Dr. Phillips Blvd., Suite 7<br/>Orlando, FL 32819<br/>';
	prepareMap(lat, lon, 13, name, initHtml);
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// prepareMap()
	//
	//
	//
function prepareMap(lat, lon, zoom, name, initHtml) {
    if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("gMap"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(lat, lon), zoom); 
		
		var point = new GLatLng(lat, lon);
		var marker = createMarker(point, name, initHtml);
		map.addOverlay(marker);
		marker.openInfoWindowHtml(fullHtml);
		
		point = new GLatLng(28.451000,-81.493600);
		marker = createMarker(point,'Bay Hill Occhiali','<b>Address:</b><br/>7988 Via Delagio Way, Suite 104<br/>Orlando, FL 32819<br/>');
		map.addOverlay(marker);
		
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// createMarker()
	//
	//
	//
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><b>Get directions:</b> <b>To here</b> - <a href="javascript:fromhere(' + i + ')">From here</a>' +
	   '<br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
	   '<input type="text" SIZE=40 MAXLENGTH=80 name="saddr" id="saddr" value="" /><br>' +
	   '<INPUT value="Get Directions" TYPE="SUBMIT">' +
	   '<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() + 
	   '"/>';
	
	// The info window version with the "to here" form open
	from_htmls[i] = html + '<br><b>Get directions:</b> <a href="javascript:tohere(' + i + ')">To here</a> - <b>From here</b>' +
	   '<br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
	   '<input type="text" SIZE=40 MAXLENGTH=80 name="daddr" id="daddr" value="" /><br>' +
	   '<INPUT value="Get Directions" TYPE="SUBMIT">' +
	   '<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +
	   '"/>';
	
	// The inactive version of the direction info
	html = html + '<br><b>Get directions:</b> <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a>';
	
	GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html);});
	gmarkers[i] = marker;
	htmls[i] = html;
	i++;
	fullHtml = html;
	return marker;
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// tohere();
	//
	//
	//
function tohere(i) {
  gmarkers[i].openInfoWindowHtml(to_htmls[i]);
}
////////////////////////////////////////////////////////////////////////////////////////////////
	//
	//
	//
	// fromhere
	//
	//
	//
function fromhere(i) {
  gmarkers[i].openInfoWindowHtml(from_htmls[i]);
}
addLoadEvent(chooseLocation);