google.load("maps", "2");
var map;
var entries = new Array();
var point;


function initmaps() {
	geo_lat = 32;
	geo_lon = 0;
	map = new google.maps.Map2(document.getElementById("google_map"));
	map.addControl(new GSmallMapControl());
    map.setCenter(new google.maps.LatLng(geo_lat,geo_lon), 2);
    map.setMapType(G_NORMAL_MAP);
}

function add_markers_to_map(mapObj,data) {
	var latlngbounds = new GLatLngBounds();
    for (x in data) {
	    point = new GLatLng(data[x].coords[1],data[x].coords[0]);
	    latlngbounds.extend(point);
	    //latlngbounds.extend(new GLatLng(data[x].coords[1]+10,data[x].coords[0]+2));
	    var html = '<h3>'+data[x].company_name+'</h3>'+
	    '<p>'+data[x].address_1+'</p>'+
	    '<p>'+data[x].address_2+'</p>'+
	    '<p>'+data[x].address_3+'</p>'+
	    '<p>'+data[x].postcode+'</p>'+
	    '<p>'+data[x].country+'</p>';
	    if (data[x].url && data[x].url != 'http://') html = html+'<p><a href="'+data[x].url+'">'+data[x].url+'</a></p>';
	    if (data[x].telephone) html = html+'<p>Tel: '+data[x].telephone+'</p>';
		entries[x] = new GMarker(point);
		entries[x]['html'] = html;
		mapObj.addOverlay(entries[x]);
		GEvent.addListener(entries[x], 'click', function() {
				this.openInfoWindowHtml(this['html']);
		});
	}
	
	var c = latlngbounds.getCenter();
	var cx = new GLatLng(c.lat()+10,c.lng()); // hacky thing to ensure the northern-most point is visible
	//alert(cx);
	map.setCenter(cx, map.getBoundsZoomLevel(latlngbounds));
}