function GoogleMap(MapElementID, InitialDataSet)
{
    var self = this;
    var BaseURL = Utilities.GetBaseURL();
    
    var map;
    var markers = {};
    var i = 0;

    $(function()
    {
        // load map
        map = new GMap2(document.getElementById(MapElementID));
        map.setCenter(new GLatLng(44.33956524809713, -95.712890625), 3);
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());
        
            
        // if dealer set exists
        if (InitialDataSet.shelters != null && InitialDataSet.shelters.length > 0)
            self.LoadMap();
        else
            map.setCenter(new GLatLng(44.33956524809713, -95.712890625), 3);
        
    });

    this.LoadMap = function()
    {
        window.scroll(0,0);
	    if (GBrowserIsCompatible())
	    {
	        var bounds = new GLatLngBounds();

            for (var i = 0; i < InitialDataSet.shelters.length; i++)
            {
                if(InitialDataSet.shelters[i].displayInMap == 'True')
                {
	                var point = new GLatLng(parseFloat(InitialDataSet.shelters[i].x),
							                parseFloat(InitialDataSet.shelters[i].y));
    			    var dealerid = InitialDataSet.shelters[i].id;
	                var marker = new GMarker(point);
	                marker.html = InitialDataSet.shelters[i].html;
        		    GEvent.addListener(marker, "click", function()
                    {
                        this.openInfoWindowHtml('<span class="text3">' + this.html + '</span>');
                    });
                    
                    markers[dealerid] = marker;
    	            
	                map.addOverlay(marker);
	                bounds.extend(point);
	            }
	            
            }
    	    
    	    var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
            var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
            
            if (InitialDataSet.shelters.length == 1)
            {
                map.setCenter(new GLatLng(clat, clng),13);
            }
            else
            {                            
                map.setCenter(new GLatLng(clat, clng), map.getBoundsZoomLevel(bounds)-1);                
            }
	    }
    }
    
    this.ZoomPoint = function(dealerid)
    {
        window.scroll(0,0);
        map.setCenter(markers[dealerid].getLatLng(),13);
        markers[dealerid].openInfoWindowHtml('<span class="text3">' + markers[dealerid].html + '</span>');
    }
    
    // A function to create the marker and set up the event window
	function createMarker(point,html)
	{
		gmarkers[i] = marker;
		htmls[i] = html;
		i++;
		return marker;
	}
}