 //<![CDATA[
var map;
var geocoder;
var gmarkers = [];
var htmls = [];
var markerCnt = 0;
var initial_lat = 53.067627;
var initial_lng = -2.955566;
var initial_zoom_level = 6;

var pushpin,plane;






/**
 * After page has loaded draw map
 */
function load() {
	if (GBrowserIsCompatible()) {
		// create the map
		map = new GMap2(document.getElementById("map"));
		//map.addControl(new GScaleControl());
		//map.addControl(new GMapTypeControl(), new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10, -30)));
		map.addControl(new GLargeMapControl());
		//map.addControl(new GSmallMapControl(), new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(-40, 40)));
		map.addControl(new GMapTypeControl()); //
		map.addControl(new GOverviewMapControl()); //
		map.enableDoubleClickZoom();
		map.setCenter(new GLatLng(initial_lat, initial_lng), initial_zoom_level);

		var baseIcon = new GIcon();
			baseIcon.iconSize=new GSize(32,32);
			baseIcon.shadowSize=new GSize(56,32);
			baseIcon.iconAnchor=new GPoint(16,32);
			baseIcon.infoWindowAnchor=new GPoint(16,0);

		martini = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon27.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon27s.png");
		plane   = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal2/icon56.png", null, "http://maps.google.com/mapfiles/kml/pal2/icon56s.png");
		pushpin = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal5/icon14.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon14s.png");
		sun = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal4/icon41.png", null, "http://maps.google.com/mapfiles/kml/pal4/icon41s.png");
		relax = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal3/icon63.png", null, "http://maps.google.com/mapfiles/kml/pal3/icon63s.png");
		//pushpin = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal5/icon14.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon6.png");
		//pushpin = new GIcon(baseIcon, "http://maps.google.com/mapfiles/kml/pal5/icon14.png", null, "http://maps.google.com/mapfiles/kml/pal5/icon13.png");

		//readMap("map_millets.xml");
		if(window.location.search) {
			var place = window.location.search.substr(1).split(/&|;/);
			readMap("map_" +place[0]+ ".xml");
		}
	}
	else {
		document.getElementById('map').style.backgroundColor = '#DDDDDD';
		document.getElementById('map').innerHTML = 'Sorry, your Google Map cannot be displayed.';
		//alert("Sorry, the Google Maps API is not compatible with this browser");
	}
}

/**
 * A function to create the marker and set up the event window
 */
function createMarker(point,name,html,icon) {
	var marker = new GMarker(point,eval(icon));
	GEvent.addListener(marker, "click", function(){ marker.openInfoWindowHtml(html); });
	gmarkers[markerCnt] = marker;
	htmls[markerCnt] = html;
	markerCnt++;
	return marker;
}


/**
 * A function to read/parse XML the data
 */
function readMap(url) {
	//alert(url.substring(4,20).split(".")[0])
	var request = GXmlHttp.create();
	request.open("GET", url, true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var xmlDoc = request.responseXML;

			// hide the info window, otherwise it still stays open where the removed marker used to be
			map.getInfoWindow().hide();
		//	map.returnToSavedPosition();
			map.clearOverlays();

			// empty the array
			gmarkers = [];

			var placeselection ="";
			// obtain the array of markers and loop through it
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				// obtain the attribues of each marker
				var lat = parseFloat(markers[i].getAttribute("lat"));
				var lng = parseFloat(markers[i].getAttribute("lng"));
				var point = new GLatLng(lat,lng);
				var html = markers[i].getAttribute("html");
				var label = markers[i].getAttribute("label");
				var icon = markers[i].getAttribute("icon");
				// create the marker
				var marker = createMarker(point,label,html,icon);
				map.addOverlay(marker);
			}

			//recenter map view
			map.setCenter(new GLatLng(initial_lat, initial_lng), initial_zoom_level);;
			// put the assembled
           document.getElementById("placeselection").innerHTML = url.substring(4,20).split(".")[0].toUpperCase();
		}
	}
	request.send(null);
}
//