/*
This code is for 80th May Festival website's map by Google Maps.
Thanks for Google Maps Creators!
Written by Tomohiro Suzuki in University of Tokyo.
*/
function load() {
 if (GBrowserIsCompatible()) {
	var map;

	map = new GMap2(document.getElementById("map"));
	map.enableContinuousZoom();
	map.addControl(new GLargeMapControl());
	map.addControl(new GMapTypeControl());
	map.addControl(new GOverviewMapControl(new GSize(170,120)));
	map.setCenter(new GLatLng(35.713,139.762), 15);







	//ファイル名に乱数を付加してキャッシュを利用しない
	var xmlFile;
	xmlFile = "places.xml"; //ファイル名
	xmlFile += "?rand=" + Math.random(); //乱数を付加

	addMarkerByXML(map,xmlFile);

	map.moveCenter = function (lat, lng, zoom) {
		if((zoom > 0) && (map.getZoom != zoom)){
			map.setZoom(zoom);
		}
		map.panTo(new GLatLng(lat, lng));
	}


  }//end of if
}




function addMarkerByXML(map,xmlFile){
 var request = GXmlHttp.create();
 request.open("GET", xmlFile, true);
 request.onreadystatechange = function(){
	if(request.readyState == 4){
		var xmlDoc = request.responseXML;
		var places = xmlDoc.documentElement.getElementsByTagName("place");
		for( var i=0; i < places.length ; i++){
			var lat = parseFloat(places[i].getAttribute("lat"));
			var lng = parseFloat(places[i].getAttribute("lng"));
			var point = new GLatLng(lat,lng);
			addMarker(map,point,places[i]);
		}
	}
 }
 request.send(null);
}

function addMarker(map,point,node){
　var myicon = new GIcon();
　myicon.image= "images/" + node.getElementsByTagName("image")[0].firstChild.nodeValue;



//  alert(myicon.image);

　myicon.shadow="images/" + node.getElementsByTagName("shadow")[0].firstChild.nodeValue;
　myicon.iconSize = new GSize(node.getElementsByTagName("iconW")[0].firstChild.nodeValue , node.getElementsByTagName("iconH")[0].firstChild.nodeValue );

//  alert(myicon.iconSize);

　myicon.shadowSize = new GSize(node.getElementsByTagName("shadowW")[0].firstChild.nodeValue , node.getElementsByTagName("shadowH")[0].firstChild.nodeValue );
　myicon.iconAnchor = new GPoint(node.getElementsByTagName("anchorX")[0].firstChild.nodeValue , node.getElementsByTagName("anchorY")[0].firstChild.nodeValue );
　myicon.infoWindowAnchor = new GPoint(node.getElementsByTagName("anchorX")[0].firstChild.nodeValue , node.getElementsByTagName("anchorY")[0].firstChild.nodeValue );
　myicon.transparent = "images/" + node.getElementsByTagName("image")[0].firstChild.nodeValue;

　var marker = new GMarker(point, myicon);
  GEvent.addListener(marker,"click", function(){
	var html = '<h2 style="font-size:0.9em;margin-top:0px;">' + node.getElementsByTagName("name")[0].firstChild.nodeValue + "</h2>";
	html += '<p style="width:300px">'+ node.getElementsByTagName("desc")[0].firstChild.nodeValue + '</p>';
//	html += '<p style="font-size:0.9em;"><a href="'+ node.getElementsByTagName("url")[0].firstChild.nodeValue + '" target="_blank">' + 
//		node.getElementsByTagName("url")[0].firstChild.nodeValue + '</a></p>';

	marker.openInfoWindowHtml(html);
  });

  map.addOverlay(marker);
}

