var map;
window.onload=createMap;
window.onunload=GUnload;

 function createMap(){ 
	var jNormal = new GMapType(G_NORMAL_MAP.getTileLayers(), G_NORMAL_MAP.getProjection(),"マップ"); 
	var jSatellite = new GMapType(G_SATELLITE_MAP.getTileLayers(), G_SATELLITE_MAP.getProjection(),"衛星写真"); 
 
	map = new GMap2(document.getElementById("map")); 
	map.getMapTypes().length = 0; 
	map.addMapType(jNormal); 
	map.addMapType(jSatellite); 
 
	map.addControl(new GLargeMapControl()); 
	map.addControl(new GMapTypeControl()); 
	map.setCenter(new GLatLng(35.272386,136.251969), 14);
 
	var icon = new GIcon(); 
	icon.iconSize = new GSize(32, 41); 
	icon.iconAnchor = new GPoint(12, 35); 
	icon.infoWindowAnchor = new GPoint(9, 2); 
	icon.infoShadowAnchor = new GPoint(18, 25); 
 
	function createMarker(point, text, type) { 
		if(type == "ファミリーレストラン"){ icon.image = "./img/icon_guidemap_fr.png"; } 
		else if(type == "ファーストフード"){ icon.image = "./img/icon_guidemap_ff.png"; } 
		else if(type == "中華"){ icon.image = "./img/icon_guidemap_chinese.png"; } 
		else if(type == "和食"){ icon.image = "./img/icon_guidemap_japanese.png"; } 
		else if(type == "喫茶"){ icon.image = "./img/icon_guidemap_coffee.png"; } 
		else if(type == "外国料理"){ icon.image = "./img/icon_guidemap_foreign.png"; } 
		else if(type == "寿司"){ icon.image = "./img/icon_guidemap_sushi.png"; } 
		else if(type == "居酒屋"){ icon.image = "./img/icon_guidemap_izakaya.png"; } 
		else if(type == "洋食"){ icon.image = "./img/icon_guidemap_yoshoku.png"; } 
		else if(type == "焼肉"){ icon.image = "./img/icon_guidemap_yakiniku.png"; } 
		else if(type == "菓子"){ icon.image = "./img/icon_guidemap_kashi.png"; } 
		else if(type == "軽食"){ icon.image = "./img/icon_guidemap_cafe.png"; } 
		else if(type == "鉄板焼"){ icon.image = "./img/icon_guidemap_teppan.png"; } 
		else if(type == "麺類"){ icon.image = "./img/icon_guidemap_men.png"; } 
		else { icon.image = "/shared/img/marker5.png"; } 
 
		var marker = new GMarker(point, icon); 
		var html = "<div class=\"info\">" + text + "</div>";
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		});
		return marker;
	}
	var request = GXmlHttp.create();
	request.open("GET", "./marker.xml", true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var xmlDoc = request.responseXML;
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var i = 0; i < markers.length; i++) {
				
				var point = new GPoint(parseFloat(markers[i].getAttribute("lng")),parseFloat(markers[i].getAttribute("lat")));
				var marker = createMarker(point, markers[i].firstChild.nodeValue, markers[i].getAttribute("type") );
				map.addOverlay(marker);
			}
		}
	}

	request.send(null);
}
 
function setPosition(place){
	alert(place);
	if(place=="china"){
		map.setCenter(new GLatLng(30.86451022625836,108.80859375), 5);
	}
	if(place=="japan"){
		map.setCenter(new GLatLng(35.92464453144099,136.56005859375), 6);
	}
	if(place=="southeastasia"){
		map.setCenter(new GLatLng(16.594081412718474,102.9638671875), 6);
	}
}

	
function mapLocation(nlng, nlat, nzoom){
	map.setCenter(new GLatLng(nlat, nlng), nzoom, G_NORMAL_MAP);
}
