// Script to load and position a KML/XML Google Map
// See www.reviewmylife.co.uk for details.

var kml;
var lat;
var lng;
var zoom;
var mapxml;

function LoadGoogleMap(){
	// Find mapinfo span and get name attribute
	mapxml = document.getElementById('mapxml').getAttribute('name');
	if (document.getElementById('lat'))
		{
		lat = document.getElementById('lat').getAttribute('name');
		}
	if (document.getElementById('lng'))
		{
		lng = document.getElementById('lng').getAttribute('name');
		}
	if (document.getElementById('zoom'))
		{
		zoom = parseInt(document.getElementById('zoom').getAttribute('name'));
		}
	kml = new GGeoXml(mapxml, PositionMapCallback);
}

function PositionMapCallback(){
	var map = new GMap2(document.getElementById("map"));
	map.addMapType(G_PHYSICAL_MAP);
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	if (typeof lat=="undefined" || typeof lng=="undefined"){
		kml.gotoDefaultViewport(map);
	}
	else{
		map.setCenter(new GLatLng(lat, lng));
	}
	if (typeof zoom!="undefined"){
		map.setZoom(zoom);
	}
	map.addOverlay(kml);
	if (mapxml.toLowerCase().indexOf("all_routes") >= 0){
		map.setMapType(G_PHYSICAL_MAP);
	}
}

