﻿function CreateMarker(objPoint, varIndex) {
	var objMarker = new GMarker(objPoint);
	GEvent.addListener(objMarker, "mouseover", function() {
		var objLocation = objLocations.Item(varIndex);
		objMarker.openInfoWindowHtml(objLocation.ToHtml(), {pixelOffset: new GSize(0,-32)});
	});
	return objMarker;
}

function LoadMap() {
	if (GBrowserIsCompatible()) {
		objMap = new GMap2(document.getElementById("divMap"));
		objMap.addControl(new GLargeMapControl());
		objMap.addControl(new GMapTypeControl());
		var objCentrePoint = null;
		if ((varCentreLatitude == 0) && (varCentreLongitude == 0)) {
		    objCentrePoint = new GLatLng(objLocations.Item(0).Latitude, objLocations.Item(0).Longitude);
		}
		else {
		    objCentrePoint = new GLatLng(varCentreLatitude, varCentreLongitude);
		}
		var varCurrentZoom = varZoom;
		if (varZoom == 0) {
		    varCurrentZoom = 12;
		}
		objMap.setCenter(objCentrePoint, varCurrentZoom);
		for (i = 0; i < objLocations.Count(); i++) {
			var objPoint = new GLatLng(objLocations.Item(i).Latitude, objLocations.Item(i).Longitude);
			objMap.addOverlay(CreateMarker(objPoint, i));
		}
		var objCurrentPoint = new GLatLng(objLocations.Item(0).Latitude, objLocations.Item(0).Longitude);
		objMap.openInfoWindowHtml(objCurrentPoint, objLocations.Item(0).ToHtml(), {pixelOffset: new GSize(0,-32)});
	}
}

var objMap = null;
var objLocations = new LocationCollection();