function google_maps()
{
	var map = null;	// where the map actually lives.
	var points = new Array;	// points we have added

	this.use_ne = false;
	this.init = function(map_div,existing_map)
	{
		if (!GBrowserIsCompatible()) return false;
		if (existing_map) {
			map = existing_map;
			return;
		}
		var d = document.getElementById(map_div);
		if (!d) return false;
		map = new GMap2(d);
		if (!map) {
			return false;	// doesn't exist so drop
		}
		return true;
	}
	this.hybrid = function()
	{
		map.setMapType(G_HYBRID_MAP);
	}
	this.make_map = function(lat,lng,zoom)
	{
		if (!map) return;
		if (this.use_ne) {
			var p = this.convert_coords(lat,lng);
			lat = p[0];
			lng = p[1];
		}
		map.setCenter(new GLatLng(lat, lng), zoom);
		return;
	}
	this.gpoint = function(lat,lng,name)
	{
		if (this.use_ne) {
			var p = this.convert_coords(lat,lng);
			lat = p[0];
			lng = p[1];
		}
		this.lat = lat;
		this.lng = lng;
		this.name = name;
		this.title = "";
		this.html = "";
		this.location = "";
		this.data = "";
		this.color = false;
		return this;
	}
	this.add_point = function(name,lat,lng)
	{
		if (this.use_ne) {
			var p = this.convert_coords(lat,lng);
			lat = p[0];
			lng = p[1];
		}
		points[name] = new this.gpoint(lat,lng,name);
	}
	this.set_html = function(name,html_text)
	{
		points[name].html = html_text;
	}
	this.set_title = function(name,title_text)
	{
		points[name].title = title_text;
	}
	this.on_click = function(name,location)
	{
		points[name].location = location;
	}
	this.load_onclick = function(name,location)
	{
		points[name].data = location;
	}
	this.set_color = function(name,color)
	{
		points[name].color = color;
	}
	this.resolve_all = function()
	{
		var p;
		var marker;
		var the_title;

		if (!map) return;
		for(var key in points) {
			p = points[key];
			var l;
			e = new GLatLng(p.lat,p.lng);
//			the_title = p.title ? p.title : null;
			if (p.color) {
				marker = new GMarker(e, { icon: MapIconMaker.createMarkerIcon({primaryColor: p.color}), title: p.title} )
			} else {
				marker = new GMarker(e,{title: p.title});
			}
			map.addOverlay(marker);
			if (p.html != "") {
				var f = this.buildhtmlclosure(p.html);
				GEvent.addListener(marker, "click", f);
			}
			if (p.location != "") {
				var f = this.buildhrefclosure(p.location);
				GEvent.addListener(marker, "click", f);
			}
			if (p.data != "") {
				var f = this.builddataclosure(key,p.data);
				GEvent.addListener(marker, "click", f);
			}
		}
	}
	this.builddataclosure = function(key,href)
	{
		var f = function(e) {
			var l = document.createElement("div");
			var d = document.createElement("div");
			l.appendChild(d);
			d.id = key;
			d.className = "storytext";
			var s = new remote_call(); 
			s.getData(href,d);
			map.openInfoWindow(e,l,{maxWidth:400});
		}
		return f;
	}
	this.buildhtmlclosure = function(txt)
	{
		var f = function(e) {
			var d = document.createElement("div");
			d.innerHTML = txt;
			map.openInfoWindow(e,d);
		}
		return f;
	}
	this.buildhrefclosure = function(loc)
	{
		var f = function(e) {
			document.location.href = loc;
		}
		return f;
	}
	this.convert_coords = function(northing,easting)
	{
		var os1w = new OSRef(northing,easting);
		var ll1w = os1w.toLatLng(os1w);
		ll1w.OSGB36ToWGS84();
		return [ ll1w.lat,ll1w.lng ];
	}
	this.addcontrol = function()
	{
		map.addControl(new GLargeMapControl());
	}
}
