
	var map, httpObj;
	var userLine;
	var userMarker;
	var points = [];
	var cleararr= [];
	var xmlData ;
	var pointData ;
	var mapCenter ;
	var mapZoom ;
	var targetData="";
	
	var points1 = [];
	var points2 = [];
	var points3 = [];
	var points4 = [];

	window.onload = function() {
		map = new GMap2(document.getElementById("gmap"));

		map.addControl(new GLargeMapControl()); // 移動ボタンとズームスライダを付加
		map.addControl(new GMapTypeControl());  // 地図/衛星切替ボタンを付加
		map.addControl(new GScaleControl());    // 縮尺スケールを付加		
		
		
		var msec = (new Date()).getTime();
		httpObj = GXmlHttp.create();
		httpObj.open("get", "root_nagano_st.xml?cache="+msec);
		httpObj.onreadystatechange = function() {
			if ((httpObj.readyState == 4) && (httpObj.status == 200)) addMarker();
		}
		httpObj.send(null);
	}
	
	function setRoot(aXML){
		//ラインを削除してから再描画する
		map.removeOverlay(userLine);
		map.removeOverlay(userMarker);
		targetData=aXML;
		
		var msec = (new Date()).getTime();
		httpObj = GXmlHttp.create();
		httpObj.open("get", aXML + "?cache="+msec);
		httpObj.onreadystatechange = function() {
			if ((httpObj.readyState == 4) && (httpObj.status == 200)) addMarker();
		}
		httpObj.send(null);
	
	
	}
	
	function addMarker() {
		 xmlData = httpObj.responseXML;
		 pointData = xmlData.getElementsByTagName("point");
		 mapCenter = xmlData.getElementsByTagName("center");
		 mapZoom = xmlData.getElementsByTagName("zoom");
//		
//		
//		
		var cx = mapCenter[0].getElementsByTagName("x")[0].firstChild.nodeValue;
		var cy = mapCenter[0].getElementsByTagName("y")[0].firstChild.nodeValue;
		var cz = parseInt(mapZoom[0].getElementsByTagName("rate")[0].firstChild.nodeValue);
//
//	
//
		map.setCenter(new GLatLng(cx, cy),cz);
		points.clear();
		
		

		if(targetData==""){
			setRoot1();//points=points1;
		}else if(targetData=="root_nagano_st.xml"){
			setRoot1();
		}else if(targetData=="root_denagano_st.xml"){
			setRoot2();
		}else if(targetData=="root_suzaka_ic.xml"){
			setRoot3();
		}else if(targetData=="root_nagano_ic.xml"){
			setRoot4();
		}
		
		

		//document.write(points);
		
		//addLine(points4);
		//userMarker=new GMarker(new GLatLng(mx, my))
		//map.addOverlay(userMarker);


	}
	
	 function addLine(aPoint) {
		userLine=new GPolyline(aPoint, "#ff0000",4,1);
		map.addOverlay(userLine);
		//map.addOverlay(new GPolyline(userLine))
	}

	function gp(x,y) {
		return new GLatLng(y, x);
	}
	function setRoot1(){
	//map.setCenter(new GLatLng(36.643002, 138.188685),15);
	points.push(new GLatLng(36.643002, 138.188685));
	points.push(new GLatLng(36.643863, 138.187484));
	points.push(new GLatLng(36.644328, 138.186378));
	points.push(new GLatLng(36.646893, 138.186958));
	points.push(new GLatLng(36.6479, 138.187119));
	points.push(new GLatLng(36.64858, 138.187108));
	points.push(new GLatLng(36.649648, 138.187119));
	points.push(new GLatLng(36.649639, 138.187387));
	points.push(new GLatLng(36.64982, 138.187387));	
	userLine=new GPolyline(points, "#ff0000");
	map.addOverlay(userLine);
	userMarker=new GMarker(new GLatLng(36.64982, 138.187387))
	map.addOverlay(userMarker);

	}
	function setRoot2(){
	points.push(new GLatLng(36.649172, 138.191552));
	points.push(new GLatLng(36.649389, 138.188406));
	points.push(new GLatLng(36.649493, 138.187451));
	points.push(new GLatLng(36.649983, 138.187419));
	points.push(new GLatLng(36.649983, 138.187419));
	userLine=new GPolyline(points, "#ff0000");
	map.addOverlay(userLine);
	userMarker=new GMarker(new GLatLng(36.649983, 138.187419))
	map.addOverlay(userMarker);
		//alert(points)		
	}
	function setRoot3(){
	points.push(new GLatLng(36.636675, 138.275728));
	points.push(new GLatLng(36.638638, 138.267145));
	points.push(new GLatLng(36.641737, 138.250837));
	points.push(new GLatLng(36.642425, 138.234916));
	points.push(new GLatLng(36.642735, 138.230839));
	points.push(new GLatLng(36.642632, 138.228307));
	points.push(new GLatLng(36.642598, 138.222513));
	points.push(new GLatLng(36.641806, 138.214917));
	points.push(new GLatLng(36.641806, 138.214402));
	points.push(new GLatLng(36.64518, 138.217664));
	points.push(new GLatLng(36.647349, 138.219767));
	points.push(new GLatLng(36.64759, 138.217578));
	points.push(new GLatLng(36.6479, 138.211098));
	points.push(new GLatLng(36.648313, 138.205047));
	points.push(new GLatLng(36.648623, 138.199682));
	points.push(new GLatLng(36.648899, 138.195391));
	points.push(new GLatLng(36.649148, 138.191786));
	points.push(new GLatLng(36.649364, 138.188717));
	points.push(new GLatLng(36.649467, 138.187387));
	points.push(new GLatLng(36.649872, 138.187408));
	userLine=new GPolyline(points, "#ff0000");
	map.addOverlay(userLine);
	userMarker=new GMarker(new GLatLng(36.649872, 138.187408))
	map.addOverlay(userMarker);
		//alert(points)		
	}
	function setRoot4(){
	points.push(new GLatLng(36.57749, 138.197687));
	points.push(new GLatLng(36.578627, 138.197043));
	points.push(new GLatLng(36.581143, 138.193760));
	points.push(new GLatLng(36.584279, 138.189511));
	points.push(new GLatLng(36.585485, 138.188503));
	points.push(new GLatLng(36.58738, 138.187644));
	points.push(new GLatLng(36.593531, 138.184490));
	points.push(new GLatLng(36.595219, 138.183696));
	points.push(new GLatLng(36.597217, 138.183224));
	points.push(new GLatLng(36.598682, 138.182881));
	points.push(new GLatLng(36.59944, 138.182409));
	points.push(new GLatLng(36.600628, 138.181593));
	points.push(new GLatLng(36.603574, 138.180091));
	points.push(new GLatLng(36.605004, 138.179061));
	points.push(new GLatLng(36.606054, 138.178740));
	points.push(new GLatLng(36.607656, 138.178611));
	points.push(new GLatLng(36.608793, 138.178997));
	points.push(new GLatLng(36.610447, 138.179641));
	points.push(new GLatLng(36.612841, 138.179748));
	points.push(new GLatLng(36.616509, 138.180177));
	points.push(new GLatLng(36.617939, 138.181400));
	points.push(new GLatLng(36.621263, 138.182065));
	points.push(new GLatLng(36.625809, 138.182752));
	points.push(new GLatLng(36.62853, 138.183138));
	points.push(new GLatLng(36.633575, 138.182194));
	points.push(new GLatLng(36.636038, 138.181787));
	points.push(new GLatLng(36.639533, 138.181808));
	points.push(new GLatLng(36.642787, 138.181851));
	points.push(new GLatLng(36.64679, 138.181990));
	points.push(new GLatLng(36.649983, 138.182055));
	points.push(new GLatLng(36.65013, 138.182280));
	points.push(new GLatLng(36.649846, 138.184158));
	points.push(new GLatLng(36.649605, 138.185778));
	points.push(new GLatLng(36.649519, 138.186539));
	points.push(new GLatLng(36.649476, 138.187290));
	points.push(new GLatLng(36.649476, 138.187419));
	points.push(new GLatLng(36.64982, 138.187408));
	userLine=new GPolyline(points, "#ff0000");
	map.addOverlay(userLine);
	userMarker=new GMarker(new GLatLng(36.649872, 138.187408))
	map.addOverlay(userMarker);
		//alert(points)		
	}
	


