﻿    //<![CDATA[
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());

var points = [];

var icon = new GIcon();
icon.image="icon.png";
icon.iconSize = new GSize(60,60);
icon.iconAnchor = new GPoint(30,48);
icon.infoWindowAnchor = new GPoint(30,0);
var icon2 = new GIcon();
icon2.image="icon2.png";
icon2.iconSize = new GSize(60,60);
icon2.iconAnchor = new GPoint(30,48);
icon2.infoWindowAnchor = new GPoint(30,0);


function addMarker(point, html, chokueiFlg) {
	var myicon;
	if (chokueiFlg == 1){
		myicon = icon2;
	}
	else{
		myicon = icon;
	}
	var marker = new GMarker(point, myicon);
	if ( html != ""){
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html)
		});
	}
	map.addOverlay(marker);
	
	return marker;
}

var request = GXmlHttp.create();
request.open("GET", "list/points.xml", true);
request.onreadystatechange = function() {
	if (request.readyState == 4){
		var xmlDoc = request.responseXML;
		var places = xmlDoc.documentElement.getElementsByTagName("place");
		

		var lineNodes = [];
		var centerFlg = 0;
		var chokueiFlg = 0;
		for (var i=0; i < places.length; i++){
			if (places[i].getAttribute("latlng") != ""){
				var latlng = places[i].getAttribute("latlng").split(",");
				var latitude = parseFloat(latlng[0]);
				var longitude = parseFloat(latlng[1]);
				points[i] = new GLatLng(latitude, longitude);
				
				var html = "<div style='width:240px'>";
				
				var title = places[i].getElementsByTagName("title")[0].firstChild.nodeValue;
//				if (places[i].getElementsByTagName("title").length != 0){
				if (title != ""){
					html += "<b>";
					
					if (places[i].getElementsByTagName("link").length != 0){
						var link = places[i].getElementsByTagName("link")[0].firstChild.nodeValue;
//						html += "<a href='" + link + "' target='_blank'>" + title + "</a>";
						html += title;
					}
					else html+= title;
					html += "</b><br>";
				}
				
				if (places[i].getElementsByTagName("address").length != 0){
					html += "<font size='-1'>";
					html += places[i].getElementsByTagName("address")[0].firstChild.nodeValue;
					html += "</font><br>";
				}
				if (places[i].getElementsByTagName("telfax").length != 0){
					html += "<font size='-1'>";
					html += places[i].getElementsByTagName("telfax")[0].firstChild.nodeValue;
					html += "</font><br>";
				}
				
/*				if (places[i].getElementsByTagName("chokuei").length != 0){
					var chokueiLabel = places[i].getElementsByTagName("chokuei")[0].firstChild.nodeValue;
					if (chokueiLabel == "direct"){
						chokueiFlg = 1;
					}
				}*/
				var chokueiLabel = places[i].getElementsByTagName("chokuei")[0].firstChild.nodeValue;
				if (chokueiLabel == "direct"){
					chokueiFlg = 1;
					}

				html += "</div>";
				if (centerFlg == 0){
					map.setCenter(new GLatLng(36.70365959719456,138.6474609375), 5);
					centerFlg = 1;
				}
//				html = chokueiLabel + html;
				addMarker( points[i], html, chokueiFlg);
//				lineNodes.push(points[i]);
			}
		}
		
//		var polyline = new GPolyline(lineNodes);
//		map.addOverlay(polyline);
	}
}
request.send(null);


function setCenter(index) {
    /* 地図のズームレベル（倍率）を設定 */
    map.setZoom(14);
    map.panTo(points[index]);
}
    //]]>