
    function DmbMap()
    {
        this.map = null;
        this.markers = new Array(0);

        // Make a basic icon for reuse later
        //this.baseIcon = new GIcon();
        //this.baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
        //this.baseIcon.iconSize = new GSize(20, 34);
        //this.baseIcon.shadowSize = new GSize(37, 34);
        //this.baseIcon.iconAnchor = new GPoint(9, 34);
        //this.baseIcon.infoWindowAnchor = new GPoint(9, 2);
        //this.baseIcon.infoShadowAnchor = new GPoint(18, 25);
        this.baseIcon = new GIcon();
        this.baseIcon.shadow =  "flagpoleshadow3.png";
        this.baseIcon.iconSize = new GSize(30, 33);
        this.baseIcon.shadowSize = new GSize(43, 33);
        this.baseIcon.iconAnchor = new GPoint(2, 33);

        this.baseIcon.infoWindowAnchor = new GPoint(9, 2);
        this.baseIcon.infoShadowAnchor = new GPoint(18, 25);

        this.browserIsCompatible = function()
        {
            return GBrowserIsCompatible();
        }
        


        this.InitaliseMap = function (location, latlongmsgarea)
        {
           var locationElement = document.getElementById(location);

           if (locationElement != null)
           {
               if ( ! this.browserIsCompatible())
               {
                   locationElement.innerHTML = "Sorry - your browser is not compatible.";
               }
               else
               {
                    this.map = new GMap(locationElement);
                    
    
                    this.map.addControl(new GLargeMapControl());  // Allow pan/zoom the map 
                    this.map.addControl(new GMapTypeControl()); // Allow switch between Map and Satellite mode
    
                    var latlongmsgelement = document.getElementById(latlongmsgarea);
                    if ((latlongmsgelement != undefined) && (latlongmsgelement != null))
                    {
                         
                        theMap = this.map;
                       
                        // Set a listener to give the lat/long after a drag
                        GEvent.addListener(theMap, "moveend", function()  //"moveend"
                           {
                               var center = theMap.getCenterLatLng();
                               latlongmsgelement.innerHTML = 'Map centre: (' + center.y + ', ' + center.x + ')';
                           });
                    }
    
               }
           }
           
        }
        
        // Creates a marker whose info window displays the given number
        this.createMarker = function (x, y, markerName, iconName, markerType)
        {
				      // Have to use parentNode.innerHTML bcause firefox doesn't support .outerHTML
              // Means each popup Div *has* to be in its own hidden DIV (if several popup DIVs
              // share the same hidden Div, parentNode.innerHTML, may not drill back down on the correct one :(
              // document.getElementById(markerName).parentNode.innerHTML
    
              var popupElement = document.getElementById(markerName); 
							
							var markerHTML = ((popupElement == null) ? "Bad popup - please notify webmaster" : popupElement.innerHTML);
                               
							this.createMarkerHTML(x, y, markerName, markerHTML, iconName, markerType);								 
				}
				
				// Creates a marker whose info window displays the given number
        this.createMarkerHTML = function (x, y, markerName, markerHTML, iconName, markerType)
        {
					
            if ( this.map != null)
            {
            
              var icon = new GIcon(this.baseIcon);
              icon.image = iconName; 
    
              var marker = new GMarker(new GPoint(x,y), icon);
    
							var popupHTML =  "<div class='dialpopupformat'>"+
							                 markerHTML +
															 "</div>";

              marker.dmbPopupHTML = popupHTML;
              marker.dmbMarkerName = markerName;
              marker.dmbMarkerType = markerType;
              marker.dmbDisplayed = false;

              // Show this marker's text in the info window when it is clicked
              GEvent.addListener(marker, "click", function()
                                {
                                   //marker.openInfoWindowHtml(text);
                                   marker.openInfoWindowHtml(marker.dmbPopupHTML);
                                }
              );
    //          GEvent.addListener(marker, "infowindowopen", function(){alert("opened - "+markerName+" - "+document.getElementById(markerName));});
    //        GEvent.addListener(marker, "infowindowclose", function(){alert("closed");});
    
              this.markers[markerName] = marker;
           }
       }
 
        
        this.setMarkerTypeStatus = function(show, markerType)
        {
            if ( this.map != null)
            {
               this.map.closeInfoWindow(); 
               
               for (var markername in this.markers)
               {
                   var marker = this.markers[markername];
                   
                   if (marker.dmbMarkerType == markerType)
                   {
                        if (show && (!marker.dmbDisplayed))
                        {
                           this.map.addOverlay(marker);
                           marker.dmbDisplayed = true;
                        }
                        else if ((!show) && marker.dmbDisplayed )
                        {
                           this.map.removeOverlay(marker);
                           marker.dmbDisplayed = false;
                        }
                   }
               }
            }
       }

       this.getMarkerType = function(markername)
       {
           if ( this.map != null)
           {
               var marker = this.markers[markername];
               if (marker != null)
               {
                   return marker.dmbMarkerType;
               }
           }
           return null; 
       }


       this.centreAndZoomCoord = function(x, y, zoom)
       {
           if ( this.map != null)
           {
               this.map.closeInfoWindow();
               this.map.centerAndZoom( new GPoint(x,y), zoom);
               return true;
           }

           return false;
       }

       this.centreAndZoomMarkerName = function(markerName, zoom)
       {
           if ( this.map != null)
           {
               var marker = this.markers[markerName];
               if (marker != null)
               {
                   this.centreAndZoom(marker, zoom);
                   marker.openInfoWindowHtml(marker.dmbPopupHTML);
               }
           }
       }

       this.centreAndZoom = function(marker, zoom)
       {
           if ( (this.map != null) && (marker != null))
           {
               this.map.closeInfoWindow();
               this.map.centerAndZoom( marker.point, zoom);
           }
       }

    }
