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(13.754058580410238, 100.50644874572754), 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());
var bts1 = [];
bts1.push(new GLatLng(13.802668374013075, 100.55385947227478));
bts1.push(new GLatLng(13.798875819432254, 100.55158495903015));
bts1.push(new GLatLng(13.776952812712498, 100.54363489151001));
bts1.push(new GLatLng(13.772680504342663, 100.54208993911743));
bts1.push(new GLatLng(13.770262968424946, 100.54119944572449));
bts1.push(new GLatLng(13.762780953190148, 100.53709030151367));
bts1.push(new GLatLng(13.753245726244336, 100.53176879882812));
bts1.push(new GLatLng(13.74693558926217, 100.53074955940247));
bts1.push(new GLatLng(13.746643786906802, 100.53081393241882));
bts1.push(new GLatLng(13.7464249349017, 100.53094267845154));
bts1.push(new GLatLng(13.74623734730599, 100.53116261959076));
bts1.push(new GLatLng(13.746122710367976, 100.53139865398407));
bts1.push(new GLatLng(13.744762695140336, 100.53930044174194));
bts1.push(new GLatLng(13.743084811067439, 100.54904222488403));
bts1.push(new GLatLng(13.742334449083828, 100.55253982543945));
bts1.push(new GLatLng(13.741980110645075, 100.55335521697998));
bts1.push(new GLatLng(13.741354806210557, 100.5543315410614));
bts1.push(new GLatLng(13.730505508679657, 100.56970596313477));
bts1.push(new GLatLng(13.72426250570193, 100.57851433753967));
bts1.push(new GLatLng(13.71965570916293, 100.58505892753601));
bts1.push(new GLatLng(13.715142628485328, 100.59134602546692));
bts1.push(new GLatLng(13.710087458200986, 100.59845924377441));
bts1.push(new GLatLng(13.709607993101175, 100.59899568557739));
bts1.push(new GLatLng(13.705709697048956, 100.60103416442871));
var start = 0;
var end;
var section = 15;
while(start<bts1.length-1){
	end = start+section+1;
	if(bts1.length<end){
		end = bts1.length;
	}
map.addOverlay(new GPolyline(bts1.slice(start,end),'#008000',5,0.8));
start+=section;
}
var bts2 = [];
bts2.push(new GLatLng(13.746555203977, 100.52910804748535));
bts2.push(new GLatLng(13.744752273537241, 100.53940773010254));
bts2.push(new GLatLng(13.744694954711827, 100.53975105285645));
bts2.push(new GLatLng(13.744564684601919, 100.53994417190552));
bts2.push(new GLatLng(13.744319776599168, 100.54010510444641));
bts2.push(new GLatLng(13.74407486834037, 100.54016947746277));
bts2.push(new GLatLng(13.743861224756566, 100.54019093513489));
bts2.push(new GLatLng(13.73919749310165, 100.53940773010254));
bts2.push(new GLatLng(13.735049559923382, 100.53878545761108));
bts2.push(new GLatLng(13.730599308792751, 100.53703665733337));
bts2.push(new GLatLng(13.730192841365012, 100.53676843643188));
bts2.push(new GLatLng(13.729432015824637, 100.5362319946289));
bts2.push(new GLatLng(13.729181880861239, 100.53591012954712));
bts2.push(new GLatLng(13.728514852987871, 100.53411841392517));
bts2.push(new GLatLng(13.726586714873987, 100.52863597869873));
bts2.push(new GLatLng(13.72644080107429, 100.52834630012512));
bts2.push(new GLatLng(13.726232352631568, 100.52818536758423));
bts2.push(new GLatLng(13.725961369379107, 100.52815318107605));
bts2.push(new GLatLng(13.725617428646315, 100.52816390991211));
bts2.push(new GLatLng(13.723783069554935, 100.52940845489502));
bts2.push(new GLatLng(13.722532361951204, 100.53003072738647));
bts2.push(new GLatLng(13.722209261403293, 100.53003072738647));
bts2.push(new GLatLng(13.721813202060199, 100.52986979484558));
bts2.push(new GLatLng(13.721490100522015, 100.5294942855835));
bts2.push(new GLatLng(13.721365028839427, 100.52860379219055));
bts2.push(new GLatLng(13.719280490982126, 100.52145838737488));
bts2.push(new GLatLng(13.718133987268468, 100.51745653152466));
bts2.push(new GLatLng(13.7180922961188, 100.51696300506592));
bts2.push(new GLatLng(13.718811467412552, 100.51410913467407));
var start = 0;
var end;
var section = 15;
while(start<bts2.length-1){
	end = start+section+1;
	if(bts2.length<end){
		end = bts2.length;
	}
map.addOverlay(new GPolyline(bts2.slice(start,end),'#008080',5,0.8));
start+=section;
}
var mrt = [];
mrt.push(new GLatLng(13.801574374212484, 100.53897857666016));
mrt.push(new GLatLng(13.797719286398753, 100.54884910583496));
mrt.push(new GLatLng(13.802824659279956, 100.55345177650452));
mrt.push(new GLatLng(13.81301423260829, 100.5612301826477));
mrt.push(new GLatLng(13.806471285773025, 100.57303190231323));
mrt.push(new GLatLng(13.799115460695083, 100.57464122772217));
mrt.push(new GLatLng(13.78971717107698, 100.57419061660767));
mrt.push(new GLatLng(13.77852625294429, 100.57354688644409));
mrt.push(new GLatLng(13.76608432369087, 100.57011365890503));
mrt.push(new GLatLng(13.757393337185569, 100.56515693664551));
mrt.push(new GLatLng(13.749139727450858, 100.56337594985962));
mrt.push(new GLatLng(13.737509147249881, 100.56140184402466));
mrt.push(new GLatLng(13.722688700766273, 100.56015729904175));
mrt.push(new GLatLng(13.722417713420617, 100.55395603179932));
mrt.push(new GLatLng(13.725961369379107, 100.54563045501709));
mrt.push(new GLatLng(13.729338215244624, 100.53730487823486));
mrt.push(new GLatLng(13.732464881025347, 100.53000926971436));
mrt.push(new GLatLng(13.738009399140669, 100.51713466644287));
var start = 0;
var end;
var section = 15;
while(start<mrt.length-1){
	end = start+section+1;
	if(mrt.length<end){
		end = mrt.length;
	}
map.addOverlay(new GPolyline(mrt.slice(start,end),'#ff0000',5,0.8));
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 createMarker4(point, title, html){
	var myIcon;
	myIcon = new GIcon();
	myIcon.image = "http://www.travelplatz.com/js/iconw/iconw"+ 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 createMarker5(point, title, html){
	var myIcon;
	myIcon = new GIcon();
	myIcon.image = "http://www.travelplatz.com/thailand/js/bts.jpg";
	myIcon.iconSize = new GSize(20, 20);
	myIcon.iconAnchor = new GLatLng(10, 20);
	myIcon.infoWindowAnchor = new GPoint(20, 0);
	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 createMarker6(point, title, html){
	var myIcon;
	myIcon = new GIcon();
	myIcon.image = "http://www.travelplatz.com/thailand/js/bts1.jpg";
	myIcon.iconSize = new GSize(20, 20);
	myIcon.iconAnchor = new GLatLng(10, 20);
	myIcon.infoWindowAnchor = new GPoint(20, 0);
	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 createMarker7(point, title, html){
	var myIcon;
	myIcon = new GIcon();
	myIcon.image = "http://www.travelplatz.com/thailand/js/metro.jpg";
	myIcon.iconSize = new GSize(20, 20);
	myIcon.iconAnchor = new GLatLng(10, 20);
	myIcon.infoWindowAnchor = new GPoint(20, 0);
	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("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 if(flag==5){var marker = createMarker4(point, title, html);}
				else if(flag==6){var marker = createMarker5(point, title, html);}
				else if(flag==7){var marker = createMarker6(point, title, html);}
				else if(flag==8){var marker = createMarker7(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;

