function initGoogleMap( mapDiv, mapItems, iconUrl, defaultZoomAdjustment ) {
  if ( GBrowserIsCompatible() ) {
  
    var map = new GMap2( mapDiv );

		map.addControl( new GSmallMapControl() );
		map.addControl( new GMapTypeControl() );

    var bounds;

    mapItems.each (
      function( mapItem, index ) {
	
        if ( mapItem.latitude && mapItem.longitude ) {
          if ( index == 0 ) {
            bounds = new GLatLngBounds( new GLatLng( mapItem.latitude, mapItem.longitude ), new GLatLng( mapItem.latitude, mapItem.longitude ) );
            map.setCenter( bounds.getCenter() ); // required to give the map some context before adding markers
	    	
          } else {
            bounds.extend( new GLatLng( mapItem.latitude, mapItem.longitude ) )
          }

          addMarker( map, mapItem, iconUrl );
        }
      }
    );
		
    if (mapItems.length > 0) {
      map.setCenter( bounds.getCenter() );

      if ( mapItems.length == 1 ) {
        map.setZoom(14);
      } else {
        var boundszoom = map.getBoundsZoomLevel( bounds, map.getSize() );
        if ( defaultZoomAdjustment ) boundszoom += defaultZoomAdjustment;
        map.setZoom( boundszoom );
      }
    } else {

      var ct = new GLatLng(54.93022, -1.032715);
      map.setCenter(ct, 4);

    }
  }

}


function addMarker( map, mapItem, iconUrl ) {

  var mapDivId = map.getContainer().id;
  var tooltipId = mapDivId + '_tooltip_' + mapItem.id;
  var markerId = mapDivId + '_' + mapItem.id;

  // Create the marker. I'm setting the id so that I can grab 
  // the relevant Dom element and attach a tooltip to it 
  // later.

  var icon = new GIcon(G_DEFAULT_ICON);

  if ( iconUrl ) {
    icon.image = iconUrl;
  } else {
    icon.image = "/stylesheets/map/images/map_icon.png";
  }
  icon.iconSize = new GSize(25,40);
  icon.shadowSize = new GSize(43,39);
  /*
  icon.dragCrossSize = new GSize(, );
  icon.dragCrossAnchor = new GPoint(,);
  */
  icon.imageMap = [12,0,17,1,21,4,24,8,24,17,19,22,16,26,13,31,13,35,12,35,12,31,9,26,3,20,0,15,0,8,3,4,6,1];
  var marker = new GMarker( new GLatLng( mapItem.latitude, mapItem.longitude ), { id: markerId, icon : icon } );

  if (mapItem.url != null) {
    GEvent.addListener( marker, 'click', function() { window.location = mapItem.url; } );
  }

  map.addOverlay( marker );

  // Add the tooltip.  Using 'mtgt_' plus the id I set earlier
  // probably isn't a good idea (it isn't part of the published
  // API so Google could change it at any time...)
  var tooltip = new MapTooltip( 'mtgt_' + markerId, tooltipId );

}


// Make sure we tidy up
Event.observe( window, "unload", GUnload );
