function GoogleMapProvider()
{
	this.name = 'Google Maps';
	this.LoadMap = gmpLoadMap;
	this.DisposeMap = gmpDisposeMap;
	this.LatLong = gmpLatLong;
	this.AddMarker = gmpAddMarker;
	this.ClearMap = gmpClearMap;
	this.SetCentreAndZoom = gmpSetCentreAndZoom;
}
GoogleMapProvider.prototype = new MapProvider;

function gmpLoadMap(div_name)
{
	if (GBrowserIsCompatible()) {
		this.div = div_name;
		this.map = new GMap2(document.getElementById(div_name));
		this.map.setCenter(new GLatLng(50.614617438266265, -4.3231201171875035), 8);
		this.map.enableContinuousZoom();
		this.map.enableScrollWheelZoom();
		this.map.addControl(new GSmallMapControl());
		this.map.addControl(new GMapTypeControl());
	}
}

function gmpDisposeMap()
{
	/* Dispose the existing map */
	deleteContent(document.getElementById(this.div));
	this.map = null;
	GUnload();
}

function gmpLatLong(lat, long)
{
	var point = new GLatLng(lat, long);
	return point;	
}

function gmpAddMarker(id, pos, title, desc, icon, iconstyle, allowclick)
{
	if (this.map != null) {
		var ico = new GIcon();
		ico.image = icon;
		ico.shadow = 'img/map_shadow.png';
		if (allowclick) {
			ico.iconSize = new GSize(33, 40);
			ico.shadowSize = new GSize(70,40);
			ico.iconAnchor = new GPoint(17, 40);
			ico.infoWindowAnchor = new GPoint(5, 1);
			ico.transparent = icon.substring(0, icon.length - 4) + '_alpha.png';
			ico.imageMap = [0,0,0,37,40,37,40,0];
		} else {
			ico.iconSize = new GSize(20, 20);
			ico.shadowSize = new GSize(43,20);
			ico.iconAnchor = new GPoint(10, 20);
			ico.infoWindowAnchor = new GPoint(5, 1);
			ico.transparent = icon.substring(0, icon.length - 4) + '_alpha.png';
			ico.imageMap = [0,0,0,20,20,20,20,0];
		}
		var opts = new Object(); 
		opts.maxWidth = 250;

		var marker = new GMarker(pos, ico);
		GEvent.addListener(marker, "mouseover", function() {
	    	marker.openInfoWindowHtml("<h5>" + title + "</h5><p>" + desc + "</p>", opts);
	  	});
		GEvent.addListener(marker, "mouseout", function() {
	    	marker.closeInfoWindow();
	  	});
		if (allowclick)
			GEvent.addListener(marker, "click", function() {
            	startAsyncTransfer('incident_details', 'IncidentDetails.aspx?iid=' + id, 'IncidentDetails');
			});
		this.map.addOverlay(marker);
	}
} 

function gmpClearMap()
{
	if (this.map != null) {
		this.map.clearOverlays();
		this.map.setCenter(new GLatLng(50.614617438266265, -4.3231201171875035), 8);
	}
}

function gmpSetCentreAndZoom(pos, level)
{
	if (this.map != null) {
		this.map.setCenter(pos, level);
	}
}
