﻿function d3modEvents_GoogleMapObj(containerName)
{
    this.ContainerName = containerName;
    this.Map;
    this.Geocoder;
    var me = this;
    
    // methods
    
    this.InitMap = function()
    {
        if (GBrowserIsCompatible()) {
            // map
            this.Map = new GMap2(document.getElementById(this.ContainerName));
            this.Map.setCenter(new GLatLng(50.728748, -1.847307), 8);
            this.Map.addControl(new GSmallMapControl());
            this.Map.enableScrollWheelZoom();
            var mapControl = new GMapTypeControl();
            this.Map.addControl(mapControl);
            // geocoder
		    this.Geocoder = new GlocalSearch();
		    this.Geocoder.setSearchCompleteCallback(null, this.GMapCallback);
        }
    }
    
    this.AddMarker = function(searchTerm)
    {
        if (searchTerm != '') this.Geocoder.execute(searchTerm + ', UK');
    }
    
    this.GMapCallback = function()
    {
        var resultLat = me.Geocoder.results[0].lat;
        var resultLng = me.Geocoder.results[0].lng;
        var point = new GLatLng(resultLat,resultLng);
        if (point != null)
        {
            var marker = new GMarker(point);
            
            me.Map.addOverlay(marker);
            if(document.getElementById(me.ContainerName + 'Annotation'))
                if(document.getElementById(me.ContainerName + 'Annotation').innerHTML != '')
                    marker.openInfoWindowHtml(document.getElementById('EventMapAnnotation').innerHTML);
            
            me.Map.setCenter(point, 15);
        }
    }
    
    this.InitMap();
}
