//<![CDATA[
  var map = null;
  var centreMark = null;

  var latlongDiv = document.getElementById("latlong");
  var zoomLevelDiv = document.getElementById("zoomlevel");

function load(mapID)
//  Requires
//  var centrelat = , centrelong = , centrezoom = , centretype = ;
//  var markers = 
//  [ [ new GLatLng(lat, long), zoom, "Label." ],
//    [ new GLatLng(lat, long),    0, "URL." ]
//  ];
{
  var mapObj = document.getElementById(mapID);
  map = new GMap2(mapObj,{draggableCursor: "default"});
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.addControl(new GScaleControl());
  map.addMapType(G_PHYSICAL_MAP);
  map.enableContinuousZoom();
  map.hideControls();
  G_SATELLITE_MAP.getMaximumResolution = function(a) {return 22}
  G_SATELLITE_MAP.getProjection = function() {return new GMercatorProjection(23);}
  map.setCenter(new GLatLng(centrelat, centrelong), centrezoom, centretype);
  map.getPane(G_MAP_FLOAT_SHADOW_PANE).style.visibility="hidden";
  GEvent.addListener(map, "mouseover", function() { map.showControls(); } );
  GEvent.addListener(map, "mouseout", function() { map.hideControls(); map.closeInfoWindow(); } );

  GMap2.prototype.wheelZoom = function(event)
  { if(event.cancelable) event.preventDefault(); map.closeInfoWindow(); 
    if((event.detail || -event.wheelDelta) < 0) {map.zoomIn();} else {map.zoomOut();} return false; }
  GEvent.addDomListener(mapObj, "DOMMouseScroll", map.wheelZoom);
  GEvent.addDomListener(mapObj, "mousewheel", map.wheelZoom); 

  centreIcon = new GIcon();
  centreIcon.image = "images/crosshair.gif";
  centreIcon.iconSize = new GSize(17, 17);
  centreIcon.iconAnchor = new GPoint(8, 8);
  centreMark = new GMarker(map.getCenter(), {icon: centreIcon, clickable: false});
  map.addOverlay(centreMark); setResults();
  GEvent.addListener(map, "click", function(marker, point) { if(! marker) { map.setCenter(point); setCentreMark(); setResults(); } } );
  GEvent.addListener(map, "drag", function() { setCentreMark(); setResults(); } );
  GEvent.addListener(map, "resize", function() { setCentreMark(); setResults(); } );
  GEvent.addListener(map, "zoomend", function() { setCentreMark(); setResults(); } );

  var icon = null;
  var iconNumber = 1;
  var baseIcon = new GIcon();
  baseIcon.iconSize = new GSize(12, 20);
  baseIcon.iconAnchor = new GPoint(6, 20);
  baseIcon.infoWindowAnchor = new GPoint(5, 1);
  var markerIcon = new GIcon();
  markerIcon.iconSize = new GSize(20, 34);
  markerIcon.iconAnchor = new GPoint(9, 34);
  markerIcon.infoWindowAnchor = new GPoint(9, 2);
  var numberIcon = new GIcon();
  numberIcon.iconSize = new GSize(20, 34);
  numberIcon.iconAnchor = new GPoint(9, 34);
  numberIcon.infoWindowAnchor = new GPoint(9, 2);

  function createMarker(point, colour, zoomLevel, label, zoomTypeOrUrl, mapNewCentre, index)
  { if (colour == "bigone")
	{ icon = new GIcon(markerIcon); icon.image = "images/marker.png"; }
    else if (colour == "number") 
		if (iconNumber == 10) 
		{ icon = new GIcon(markerIcon); icon.image = "images/marker.png";  iconNumber = 1; }
		else
		{ icon = new GIcon(numberIcon); icon.image = "images/marker" + iconNumber + ".png"; iconNumber++; }
    else
		{ icon = new GIcon(baseIcon);   icon.image = "images/mm_20_" + colour + ".png"; }
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "mouseover", function() { marker.openInfoWindowHtml(label), {suppressMapPan: true}; } );
    if (zoomLevel == 0) { GEvent.addListener(marker, "click", function() { window.open(zoomTypeOrUrl, "_self"); } ); }
    else { GEvent.addListener(marker, "click", function() 
    { map.setCenter(point, zoomLevel, zoomTypeOrUrl); map.closeInfoWindow(); 
      if (mapNewCentre) { map.setCenter(mapNewCentre); setCentreMark(); } } ); }
    return marker;
  }

  var manager = new GMarkerManager(map);
  for (var i = 0; i < markers.length; i++) { manager.addMarker(createMarker(markers[i][0], markers[i][3], markers[i][4], markers[i][5], markers[i][6], markers[i][7], i), markers[i][1], markers[i][2] ); }
  manager.refresh();

  try { if (polyPoints1) {map.addOverlay(new GPolyline(polyPoints1, "#FF0000", 5, 0.5)); } } catch (e) {};
  try { if (polyPoints2) {map.addOverlay(new GPolyline(polyPoints2, "#00FF00", 5, 0.5)); } } catch (e) {};
  try { if (polyPoints3) {map.addOverlay(new GPolyline(polyPoints3, "#0000FF", 5, 0.5)); } } catch (e) {};

  try { if (redLinePoints1) {map.addOverlay(new GPolyline(redLinePoints1, "#FF0000", 5, 0.5)); } } catch (e) {};
  try { if (redLinePoints2) {map.addOverlay(new GPolyline(redLinePoints2, "#FF0000", 5, 0.5)); } } catch (e) {};
  try { if (redLinePoints3) {map.addOverlay(new GPolyline(redLinePoints3, "#FF0000", 5, 0.5)); } } catch (e) {};
  try { if (redLinePoints4) {map.addOverlay(new GPolyline(redLinePoints4, "#FF0000", 5, 0.5)); } } catch (e) {};
  try { if (redLinePoints5) {map.addOverlay(new GPolyline(redLinePoints5, "#FF0000", 5, 0.5)); } } catch (e) {};
  try { if (yellowLinePoints1) {map.addOverlay(new GPolyline(yellowLinePoints1, "#FFFF00", 5, 0.8)); } } catch (e) {};
  try { if (yellowLinePoints2) {map.addOverlay(new GPolyline(yellowLinePoints2, "#FFFF00", 5, 0.8)); } } catch (e) {};
  try { if (yellowLinePoints3) {map.addOverlay(new GPolyline(yellowLinePoints3, "#FFFF00", 5, 0.8)); } } catch (e) {};
  try { if (yellowLinePoints4) {map.addOverlay(new GPolyline(yellowLinePoints4, "#FFFF00", 5, 0.8)); } } catch (e) {};
  try { if (yellowLinePoints5) {map.addOverlay(new GPolyline(yellowLinePoints5, "#FFFF00", 5, 0.8)); } } catch (e) {};
  try { if (greenLinePoints1) {map.addOverlay(new GPolyline(greenLinePoints1, "#00FF00", 5, 0.5)); } } catch (e) {};
  try { if (greenLinePoints2) {map.addOverlay(new GPolyline(greenLinePoints2, "#00FF00", 5, 0.5)); } } catch (e) {};
  try { if (greenLinePoints3) {map.addOverlay(new GPolyline(greenLinePoints3, "#00FF00", 5, 0.5)); } } catch (e) {};
  try { if (greenLinePoints4) {map.addOverlay(new GPolyline(greenLinePoints4, "#00FF00", 5, 0.5)); } } catch (e) {};
  try { if (greenLinePoints5) {map.addOverlay(new GPolyline(greenLinePoints5, "#00FF00", 5, 0.5)); } } catch (e) {};
  try { if (blueLinePoints1) {map.addOverlay(new GPolyline(blueLinePoints1, "#0000FF", 5, 0.5)); } } catch (e) {};
  try { if (blueLinePoints2) {map.addOverlay(new GPolyline(blueLinePoints2, "#0000FF", 5, 0.5)); } } catch (e) {};
  try { if (blueLinePoints3) {map.addOverlay(new GPolyline(blueLinePoints3, "#0000FF", 5, 0.5)); } } catch (e) {};
  try { if (blueLinePoints4) {map.addOverlay(new GPolyline(blueLinePoints4, "#0000FF", 5, 0.5)); } } catch (e) {};
  try { if (blueLinePoints5) {map.addOverlay(new GPolyline(blueLinePoints5, "#0000FF", 5, 0.5)); } } catch (e) {};

}

function setCentreMark() { centreMark.setPoint(map.getCenter()); }

function setResults(point)
{ point = map.getCenter();
  latlongDiv.value = point.y.toFixed(5) + ", " + point.x.toFixed(5);
  zoomLevelDiv.value = map.getZoom();
}

//]]>

