
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);
		
		var myIcon = new GIcon(G_DEFAULT_ICON);
        myIcon.image = "/assets/images/map-icon.png";
        myIcon.iconSize = new GSize(32, 32);
        myIcon.shadow = "/assets/images/map-icon-shadow.png";
        myIcon.shadowSize = new GSize(60, 32);
        myIcon.iconAnchor = new GPoint(0, 20);
        myIcon.infoWindowAnchor = new GPoint(16, 0);
        myIcon.printImage = "/assets/images/map-icon-print.gif";
        myIcon.mozPrintImage = "/assets/images/map-icon-mozprint.gif";
        myIcon.printShadow = "/assets/images/map-icon-printshadow.gif";
        myIcon.transparent = "/assets/images/map-icon-transparent.png";
        myIcon.imageMap = [ 0,15, 4,5, 15,0, 26,5, 31,15, 26,27, 16,31, 4,27 ]; 
		

		// The info window version with the "to here" form open
		to_htmls[i] = html + '<div style="font-size: 12px; font-family: Verdana, Geneva, sans-serif;text-align:left; line-height:normal;"><br>Directions: <b>To here</b> - <a href="javascript:fromhere(' + i + ')">From here</a>' +
		'<br><br>Start address:<form action="http://maps.google.com/maps" method="get" target="_blank">' +
		'<input type="text" SIZE=25 MAXLENGTH=40 name="saddr" id="saddr" value="" /> ' +
		'<INPUT value="Get Directions" TYPE="SUBMIT" class="button">' +
		//'<input type="hidden" name="daddr" value="' + point.lat() + ',' + point.lng() +  "(" + 'Cole Gavelas, PC' + ")" + '"/></div>';
		'<input type="hidden" name="daddr" value="2401 West Centre Avenue, Portage, Michigan 49024 (ColeGavlas, PC)" /></div>'

		
		// The info window version with the "to here" form open
		from_htmls[i] = html + '<div style="font-size: 12px; font-family: Verdana, Geneva, sans-serif;text-align:left; line-height:normal;"><br>Directions: <a href="javascript:tohere(' + i + ')">To here</a> - <b>From here</b>' +
		'<br><br>End address:<form action="http://maps.google.com/maps" method="get"" target="_blank">' +
		'<input type="text" SIZE=25 MAXLENGTH=40 name="daddr" id="daddr" value="" /> ' +
		'<INPUT value="Get Directions" TYPE="SUBMIT" class="button">' +
		//'<input type="hidden" name="saddr" value="' + point.lat() + ',' + point.lng() +  "(" + 'Cole Gavelas, PC' + ")" + '"/></div>';
		'<input type="hidden" name="saddr" value="2401 West Centre Avenue, Portage, Michigan 49024 (ColeGavlas, PC)" /></div>';
        // The inactive version of the direction info
		html = html + '<div style="font-size: 12px; font-family: Verdana, Geneva, sans-serif;text-align:left; padding-left:39px;"><br>Directions: <a href="javascript:tohere('+i+')">To here</a> - <a href="javascript:fromhere('+i+')">From here</a></div>';
		
		var marker = new GMarker(point,myIcon);

		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 load() {
	if (GBrowserIsCompatible()) {
	  
		var map = new GMap2(document.getElementById("map"));
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(42.200992,-85.617399), 13);

		// Set up markers with info windows 
    
		var point = new GLatLng(42.200992,-85.617399);
	  
		var marker = createMarker(point,'Cole Gavlas, PC','<div style="font-size: 12px; font-family: Verdana, Geneva, sans-serif;text-align:left; line-height:normal;"><img src="/assets/images/map-logo.gif" width="181" height="40" alt="Cole Gavlas, PC" title="Cole Gavlas, PC" /><br/><div style="padding-left:39px;">2401 West Centre Avenue<br>Portage, Michigan 49024<br><br>Tel: (269) 329-6600 | Fax: (269) 329-6608</div></div>')

		map.addOverlay(marker);
	  
		myclick(0)
	}
}

function myclick(i) {
	GEvent.trigger(gmarkers[i],"click");
}


window.onload = load;
window.onunload = GUnload;
