var map;
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(52.51387040010162, 13.37860107421875), 13, 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 GScaleControl());
map.addControl(new GLargeMapControl());
loadMap('./xml/berlin.xml');
	}
}

function describeLine1(){
	var circle = [];
circle.push(new GLatLng(52.50384034173069, 13.331222534179688));
circle.push(new GLatLng(52.50446728743987, 13.335256576538086));
circle.push(new GLatLng(52.50148921568321, 13.343324661254883));
circle.push(new GLatLng(52.50086222750018, 13.346757888793945));
circle.push(new GLatLng(52.50551217708474, 13.352422714233398));
circle.push(new GLatLng(52.50974372615093, 13.351736068725586));
circle.push(new GLatLng(52.50974372615093, 13.363237380981445));
circle.push(new GLatLng(52.51063177731809, 13.368558883666992));
circle.push(new GLatLng(52.50911685569954, 13.367958068847656));
circle.push(new GLatLng(52.50854221659768, 13.369932174682617));
circle.push(new GLatLng(52.50911685569954, 13.371992111206055));
circle.push(new GLatLng(52.50943029204291, 13.376498222351074));
circle.push(new GLatLng(52.50694885979093, 13.379073143005371));
circle.push(new GLatLng(52.5079153290087, 13.394222259521484));
circle.push(new GLatLng(52.502978276780325, 13.394908905029297));
circle.push(new GLatLng(52.50151533999679, 13.394007682800293));
circle.push(new GLatLng(52.501018975384234, 13.394608497619629));
circle.push(new GLatLng(52.5029521533361, 13.395252227783203));
circle.push(new GLatLng(52.507027222951635, 13.394737243652344));
circle.push(new GLatLng(52.50668764824625, 13.390445709228516));
circle.push(new GLatLng(52.51212052872203, 13.389630317687988));
circle.push(new GLatLng(52.51235559012293, 13.393535614013672));
circle.push(new GLatLng(52.51499341517189, 13.39306354522705));
circle.push(new GLatLng(52.51528069348672, 13.397269248962402));
circle.push(new GLatLng(52.5165081342206, 13.402376174926758));
circle.push(new GLatLng(52.51402710160183, 13.405852317810059));
circle.push(new GLatLng(52.51922405141273, 13.412246704101562));
circle.push(new GLatLng(52.52233148148175, 13.41653823852539));
circle.push(new GLatLng(52.52413316799366, 13.412117958068848));
circle.push(new GLatLng(52.52000745786557, 13.404779434204102));
circle.push(new GLatLng(52.51768331130324, 13.399243354797363));
circle.push(new GLatLng(52.51689986340726, 13.385810852050781));
circle.push(new GLatLng(52.51546350598189, 13.386068344116211));
circle.push(new GLatLng(52.51468001850454, 13.377528190612793));
circle.push(new GLatLng(52.51781388459441, 13.377056121826172));
circle.push(new GLatLng(52.51810114446905, 13.38036060333252));
circle.push(new GLatLng(52.522618711818936, 13.37958812713623));
circle.push(new GLatLng(52.52214869756206, 13.376412391662598));
circle.push(new GLatLng(52.52314094398409, 13.37486743927002));
circle.push(new GLatLng(52.52355872524612, 13.372807502746582));
circle.push(new GLatLng(52.523454280303135, 13.370747566223145));
circle.push(new GLatLng(52.52222703362077, 13.368000984191895));
circle.push(new GLatLng(52.521313104243944, 13.369932174682617));
circle.push(new GLatLng(52.52154811647112, 13.371949195861816));
circle.push(new GLatLng(52.519485188449174, 13.372035026550293));
circle.push(new GLatLng(52.51953741567019, 13.370704650878906));
circle.push(new GLatLng(52.51778776996722, 13.370361328125));
circle.push(new GLatLng(52.51731770402358, 13.368945121765137));
circle.push(new GLatLng(52.517709425992514, 13.361477851867676));
circle.push(new GLatLng(52.516952093701605, 13.357443809509277));
circle.push(new GLatLng(52.51713489924288, 13.354654312133789));
circle.push(new GLatLng(52.51504564773247, 13.350791931152344));
circle.push(new GLatLng(52.51520234504166, 13.34989070892334));
circle.push(new GLatLng(52.51488894986446, 13.348989486694336));
circle.push(new GLatLng(52.51444496953719, 13.348946571350098));
circle.push(new GLatLng(52.512669003368266, 13.322896957397461));
circle.push(new GLatLng(52.513974867830505, 13.317403793334961));
circle.push(new GLatLng(52.51966798345114, 13.299593925476074));
circle.push(new GLatLng(52.51945907481539, 13.295817375183105));
circle.push(new GLatLng(52.51094520285744, 13.297319412231445));
circle.push(new GLatLng(52.51115415197517, 13.301610946655273));
circle.push(new GLatLng(52.50548605514632, 13.302812576293945));
circle.push(new GLatLng(52.499869477922694, 13.307104110717773));
circle.push(new GLatLng(52.500496480263955, 13.313241004943848));
circle.push(new GLatLng(52.502429681191614, 13.325257301330566));
circle.push(new GLatLng(52.50384034173069, 13.331222534179688));
			var start = 0;
			var end;
			var section=66;
			while(start<circle.length-1){
				end=start+section+1;
				if(circle.length<end){
					end=circle.length;
				}
			map.addOverlay(new GPolyline(circle.slice(start,end),'#ff0000',5,0.6));
			start+=section;
	}
}
function describeLine2(){
	var city = [];
city.push(new GLatLng(52.50381421879876, 13.331351280212402));
city.push(new GLatLng(52.50438891971521, 13.335556983947754));
city.push(new GLatLng(52.501436967009504, 13.343067169189453));
city.push(new GLatLng(52.500836102798495, 13.34688663482666));
city.push(new GLatLng(52.50195945095233, 13.348517417907715));
city.push(new GLatLng(52.50284765940397, 13.349976539611816));
city.push(new GLatLng(52.50564278654393, 13.35237979888916));
city.push(new GLatLng(52.509560889859564, 13.35165023803711));
city.push(new GLatLng(52.509769845559056, 13.363151550292969));
city.push(new GLatLng(52.510684015063205, 13.368558883666992));
city.push(new GLatLng(52.5091429754802, 13.368086814880371));
city.push(new GLatLng(52.50851609646001, 13.369889259338379));
city.push(new GLatLng(52.50901237642165, 13.371777534484863));
city.push(new GLatLng(52.50937805280756, 13.376541137695312));
city.push(new GLatLng(52.50697498086002, 13.379158973693848));
city.push(new GLatLng(52.50741903665947, 13.385510444641113));
city.push(new GLatLng(52.506478677892794, 13.386154174804688));
city.push(new GLatLng(52.50679213305039, 13.390488624572754));
city.push(new GLatLng(52.51037058766109, 13.389887809753418));
city.push(new GLatLng(52.51063177731809, 13.393707275390625));
city.push(new GLatLng(52.515019531459934, 13.393106460571289));
city.push(new GLatLng(52.515228461205545, 13.396797180175781));
city.push(new GLatLng(52.5165081342206, 13.402419090270996));
city.push(new GLatLng(52.51400098472393, 13.405852317810059));
city.push(new GLatLng(52.51692597856219, 13.409285545349121));
city.push(new GLatLng(52.52011191100383, 13.40482234954834));
city.push(new GLatLng(52.517709425992514, 13.39932918548584));
city.push(new GLatLng(52.51692597856219, 13.385810852050781));
city.push(new GLatLng(52.51546350598189, 13.386025428771973));
city.push(new GLatLng(52.51460166898845, 13.377399444580078));
city.push(new GLatLng(52.51783999920608, 13.377056121826172));
city.push(new GLatLng(52.51812725890996, 13.380403518676758));
city.push(new GLatLng(52.522644823574645, 13.379631042480469));
city.push(new GLatLng(52.522044249266486, 13.375983238220215));
city.push(new GLatLng(52.52086918882906, 13.373665809631348));
city.push(new GLatLng(52.52081696319122, 13.371949195861816));
city.push(new GLatLng(52.519615756385335, 13.371949195861816));
city.push(new GLatLng(52.51956352925742, 13.370747566223145));
city.push(new GLatLng(52.51773554066627, 13.370447158813477));
city.push(new GLatLng(52.51731770402358, 13.368945121765137));
city.push(new GLatLng(52.51768331130324, 13.361220359802246));
city.push(new GLatLng(52.51705655410405, 13.354482650756836));
city.push(new GLatLng(52.51517622886228, 13.350491523742676));
city.push(new GLatLng(52.51460166898845, 13.348946571350098));
city.push(new GLatLng(52.51373981509122, 13.350234031677246));
city.push(new GLatLng(52.50950865077948, 13.35113525390625));
city.push(new GLatLng(52.50877729713837, 13.349418640136719));
city.push(new GLatLng(52.50705334397416, 13.347916603088379));
city.push(new GLatLng(52.505799517382684, 13.341522216796875));
city.push(new GLatLng(52.505198712799256, 13.34113597869873));
city.push(new GLatLng(52.505068102020545, 13.33791732788086));
city.push(new GLatLng(52.5054599331924, 13.333840370178223));
city.push(new GLatLng(52.506191342034576, 13.332295417785645));
city.push(new GLatLng(52.50522483490844, 13.331522941589355));
city.push(new GLatLng(52.50381421879876, 13.331351280212402));
			var start = 0;
			var end;
			var section=55;
			while(start<city.length-1){
				end=start+section+1;
				if(city.length<end){
					end=city.length;
				}
			map.addOverlay(new GPolyline(city.slice(start,end),'#000080',5,0.6));
			start+=section;
	}
}
var resultText = "";
var markers = new Array();
var htmls = new Array();
var end;
var i=1;
function createMarker(point, title, html){
	var myIcon;
	myIcon = new GIcon();
	myIcon.image = "http://www.travelplatz.com/js/iconr/iconr"+ i + ".png";
	myIcon.iconSize = new GSize(20, 34);
	myIcon.shadow = "http://www.travelplatz.com/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,{"icon":myIcon, "clickable":true, "title":title});
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
		map.removeOverlay(marker);
		markers[i] = marker;
		htmls[i] = html;
		resultText =  resultText + "<a href=javascript:changePlace("+ i +")>"+ i + " " + title +"</a><br />";
		i++;
		if(i >end){i=1}
		return marker;
}
function createMarker1(point, title, html){
	var myIcon;
	myIcon = new GIcon();
	myIcon.image = "http://www.travelplatz.com/js/icong/icong"+ i + ".png";
	myIcon.iconSize = new GSize(20, 34);
	myIcon.shadow = "http://www.travelplatz.com/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,{"icon":myIcon, "clickable":true, "title":title});
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
		map.removeOverlay(marker);
		markers[i] = marker;
		htmls[i] = html;
		resultText =  resultText + "<a href=javascript:changePlace("+ i +")>"+ i + " " + title +"</a><br />";
		i++;
		if(i >end){i=1}
		return marker;
}
function createMarker2(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 = "http://www.travelplatz.com/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,{"icon":myIcon, "clickable":true, "title":title});
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
		map.removeOverlay(marker);
		markers[i] = marker;
		htmls[i] = html;
		resultText =  resultText + "<a href=javascript:changePlace("+ i +")>"+ i + " " + title +"</a><br />";
		i++;
		if(i >end){i=1}
		return marker;
}
function createMarker3(point, title, html){
	var myIcon;
	myIcon = new GIcon();
	myIcon.image = "http://www.travelplatz.com/js/icony/icony"+ i + ".png";
	myIcon.iconSize = new GSize(20, 34);
	myIcon.shadow = "http://www.travelplatz.com/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,{"icon":myIcon, "clickable":true, "title":title});
	GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
		map.removeOverlay(marker);
		markers[i] = marker;
		htmls[i] = html;
		resultText =  resultText + "<a href=javascript:changePlace("+ i +")>"+ i + " " + title +"</a><br />";
		i++;
		if(i >end){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");
			end = place.length;
			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:200px'>";
				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("kana").length != 0){
					html += place[i].getElementsByTagName("kana")[0].firstChild.nodeValue;
					html += "</b>)<br />";
				}else{
					html += "";
				}
				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 />";
				}
				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 flag = place[i].getElementsByTagName("flag")[0].firstChild.nodeValue;
				if(flag==1){var marker = createMarker(point, title, html);}
				else if(flag==2){var marker = createMarker1(point, title, html);}
				else if(flag==3){var marker = createMarker2(point, title, html);}
				else if(flag==4){var marker = createMarker3(point, title, html);}
				else {var marker = createMarker(point, title, html);}
				map.addOverlay(marker);
				}
				document.getElementById("map_right").innerHTML = resultText;
		}
	}
request.send('');
}

onload = load;
onunload = GUnload;

