var map;
var resultText = "";
var markers = new Array();
var htmls = new Array();
var i=1;
function createMarker(point, title, html){
	var myIcon;
	myIcon = new GIcon();
	myIcon.image = "http://www.travelplatz.com/js/iconb/iconb"+ i + ".png";
	myIcon.iconSize = new GSize(20, 34);
	myIcon.shadow = "../js/shadow50.png";
	myIcon.shadowSize = new GSize(37, 34);
	myIcon.iconAnchor = new GLatLng(34, 10);
	myIcon.infoWindowAnchor = new GPoint(5, 5);

	var marker = new GMarker(point, myIcon);
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
	markers[i] = marker;
	htmls[i] = html;
	resultText =  resultText + "<a href=javascript:changePlace("+ i +")>"+ i + " " + title +"</a><br />";
	i++; if(i==17){i=1}
	return marker;
}
function clearMarker(){
	map.clearOverlays();
}
function changePlace(i) {
   markers[i].openInfoWindowHtml(htmls[i]);
}
function loadMap(url){
	var request = GXmlHttp.create();
	request.open("GET", url, true);
	request.onreadystatechange = function(){
		if(request.readyState==4){
			var xml = request.responseXML;
			var place = xml.documentElement.getElementsByTagName("items");
				resultText="";
				for(var i=0; i<place.length; i++){
				var lat = parseFloat(place[i].getElementsByTagName("lat")[0].firstChild.nodeValue);
				var lng = parseFloat(place[i].getElementsByTagName("lon")[0].firstChild.nodeValue);
				var point = new GLatLng(lat, lng);
				var html = "<div style='width:250px'>";
				if(place[i].getElementsByTagName("name").length != 0){
				html += "<b style='color: navy; font-size: small; font-weight: 400; font-style: normal;'>";
				var name = place[i].getElementsByTagName("name")[0].firstChild.nodeValue;
				}
				if(place[i].getElementsByTagName("url").length != 0){
					var link = place[i].getElementsByTagName("url")[0].firstChild.nodeValue;
					html += "<a href='" + link + "' target='_blank'>" + name + "</a></b><br />";
				}else{
					html += name;
					html += "</b><br /><br />";
				}
				if(place[i].getElementsByTagName("info").length != 0){
					html += "<font size='-1'>";
					html += place[i].getElementsByTagName("info")[0].firstChild.nodeValue;
					html += "<br/><a href=javascript:map.zoomIn()>zoomIn</a> | <a href=javascript:map.zoomOut()>zoomOut</a></font></div>";
				}else{
					html += "";
					html += "</div>";
				}
				var title = place[i].getElementsByTagName("name")[0].firstChild.nodeValue;
				var marker = createMarker(point, title, html);
				map.addOverlay(marker);
				}
				document.getElementById("map_right").innerHTML = resultText;
			}
		}
	request.send('');
}
function load(){
	if (GBrowserIsCompatible()) {
		var physWithLabels = [ G_PHYSICAL_MAP.getTileLayers()[0], G_HYBRID_MAP.getTileLayers()[1] ];
var physWithLabelsMap = new GMapType(physWithLabels, G_PHYSICAL_MAP.getProjection(), "Hybrid Terrain");
		map = new GMap2(document.getElementById("map"));
		map.addMapType(G_PHYSICAL_MAP);
		map.addMapType(physWithLabelsMap);
		map.setCenter(new GLatLng(51.50307952226442, -0.13235092163085938), 15, G_SATELLITE_MAP);
		var mapControl = new GHierarchicalMapTypeControl();
		mapControl.clearRelationships();
		mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
		mapControl.addRelationship(G_PHYSICAL_MAP, physWithLabelsMap, "Labels", false);
		map.addControl(mapControl);
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
	}
}

function describeLine1(){
var walk = [];
walk.push(new GLatLng(51.50695283322676, -0.12827396392822266));
walk.push(new GLatLng(51.50203767899114, -0.14016151428222656));
walk.push(new GLatLng(51.502171249972626, -0.14204978942871094));
walk.push(new GLatLng(51.50096909704507, -0.14069795608520508));
walk.push(new GLatLng(51.50028786297641, -0.1410841941833496));
walk.push(new GLatLng(51.49953982952447, -0.1430797576904297));
walk.push(new GLatLng(51.49857805418856, -0.14400243759155273));
walk.push(new GLatLng(51.49849790532775, -0.14353036880493164));
walk.push(new GLatLng(51.49943296660051, -0.14290809631347656));
walk.push(new GLatLng(51.50028786297641, -0.14071941375732422));
walk.push(new GLatLng(51.50127631692086, -0.12973308563232422));
walk.push(new GLatLng(51.5011026711586, -0.1273512840270996));
walk.push(new GLatLng(51.49987377454688, -0.12709379196166992));
walk.push(new GLatLng(51.499740196831546, -0.12723326683044434));
walk.push(new GLatLng(51.499766912405946, -0.1287674903869629));
walk.push(new GLatLng(51.499326103426, -0.12878894805908203));
walk.push(new GLatLng(51.49988045342238, -0.12888550758361816));
walk.push(new GLatLng(51.500201038294854, -0.12738347053527832));
walk.push(new GLatLng(51.50013424996572, -0.1259458065032959));
walk.push(new GLatLng(51.503132949482534, -0.12593507766723633));
walk.push(new GLatLng(51.5049895064036, -0.1263749599456787));
walk.push(new GLatLng(51.50631175621886, -0.12712597846984863));
walk.push(new GLatLng(51.5071798791708, -0.12744784355163574));
			var start = 0;
			var end;
			var section= 9;
			while(start<walk.length-1){
				end=start+section+1;
				if(walk.length<end){
					end=walk.length;
				}
			map.addOverlay(new GPolyline(walk.slice(start,end),'#FF0000',7,0.5));
			start+=section;
			}
}

onload=load;
onunload=GUnload;
