//<![CDATA[

	var map;
	var res;
	var rows;
	var cols;
	var pnt=new GPoint;

	function AddMarker(x, y, html){
		var marker=new GMarker(new GPoint(x, y));
		GEvent.addListener(marker, "click", function(){
			marker.openInfoWindowHtml(html);
		});
		map.addOverlay(marker);
	}

	function PopupHtml(a, b, c, d){
		var imgs=b.split(' ');
		var htm, i;
		var tw;
		
		tw=POPUPWIDTH;
		htm="<table width="+tw+" cellspacing=0 cellpadding=2><tr><td align=left valign=top>"+
			"<div style=\"font-size:14px;margin-bottom:4px;\"><b>"+a+"</b></div>";
		if(b!=""){
			htm=htm+"<table cellspacing=0 cellpadding=0 align=right><tr><td align=center>";
			for(i=0; i<imgs.length; i++){
				htm=htm+"<img src="+imgs[i]+" hspace=1 vspace=1><br>";
			}
			htm=htm+"</td></tr></table>";
		}
		htm=htm+"<div style=\"font-size:12px;\">"+c+"</div>";
		if(d!=""){
			htm=htm+"<div style=\"font-size:12px;margin-top:4px;\">"+d+"</div>";;
		}
		htm=htm+"</div></td></tr></table>";
		return htm;
	}

	function CreateMap(){
		// 地図の作成
		map=new GMap(document.getElementById("map"));
		//map.addControl(new GSmallMapControl());
		
	  	// 初期位置へ
	  	map.centerAndZoom(new GPoint(STARTX, STARTY), STARTZOOM);
		document.getElementById("zoom"+map.getZoomLevel()).style.backgroundColor=SELECTCOLOR;
		MapType(0);
	  	
		GEvent.addListener(map, "moveend", function(){
			window.status=map.getCenterLatLng().toString();
			Zoom(999);
		});
		
		// マーカーの作成
		var request=GXmlHttp.create();
		request.open("GET", "data.txt", true);
		request.onreadystatechange=function(){
			if(request.readyState==4){
				res=request.responseText;
				var html="";
				rows=res.split('\n');
				var g=Math.floor((rows.length+1)/3);
				var i, j;

				html=html+"<table><tr><td align=left valign=top><font size=-1>";
				for(i=0; i<rows.length; i++){
					var cols=rows[i].split(',');
					if(cols.length==6){
						AddMarker(cols[0], cols[1], PopupHtml(cols[2], cols[3], cols[4], cols[5]));
						html=html+'　　・<a href="javascript:InfoWin('+i+');">'+cols[2]+'</a><br>';
					}
					if(cols.length==1){
						if(cols[0].length<=1){
							html=html+"</font></td><td align=left valign=top><font size=-1>";
						}
						else{
							html=html+'　<b>'+cols[0]+'</b><br>';
						}
					}
				}
				html=html+"</font></td></tr></table>";
				
				for(i=0; i<rows.length; i++){
					var cols=rows[i].split(',');
					if(cols.length==6){
						var imgs=cols[3].split(' ');
						for(j=0; j<imgs.length; j++){
							html=html+"<img src="+imgs[j]+" width=1 height=1 onload=\"this.width=0;this.height=0;\">";
						}
					}
				}
				
				document.getElementById("list").innerHTML=html;
			}
		}
		request.send(null);
	}

	function onLoad(){
		if(GBrowserIsCompatible()){
			document.getElementById("map").innerHTML="";
			CreateMap();
		}
	}

	// 情報ウィンドウ
	function InfoWin(a){
		cols=rows[a].split(',');
		pnt.x=cols[0]; pnt.y=cols[1];
		map.openInfoWindowHtml(pnt, PopupHtml(cols[2], cols[3], cols[4], cols[5]), new GSize(0, -32));
	}

	// ズーム
	function Zoom(a){
		var d;
		if(a!=999){
			map.zoomTo(a);
		}
		a=map.getZoomLevel();
		for(var i=-2; i<=6; i++){
			if(i==a){
				document.getElementById("zoom"+i).style.backgroundColor=SELECTCOLOR;
			}
			else{
				document.getElementById("zoom"+i).style.backgroundColor=BACKCOLOR;
			}
		}
	}
	
	function ZoomPlus(a){
		a=map.getZoomLevel()+a;
		if(a>=-2 && a<=6){
			Zoom(a);
		}
	}
	
	// 移動
	function MapMove(a){
		var pnt=map.getCenterLatLng();
		var bnd=map.getBoundsLatLng();
		if(a==1||a==2||a==3){ pnt.y=bnd.minY;}
		if(a==7||a==8||a==9){ pnt.y=bnd.maxY;}
		if(a==1||a==4||a==7){ pnt.x=bnd.minX;}
		if(a==3||a==6||a==9){ pnt.x=bnd.maxX;}
		map.recenterOrPanToLatLng(pnt);
	}
	
	// MapType
	function MapType(a){
		var d;
		map.setMapType((a)?G_SATELLITE_MAP:G_NORMAL_MAP);
		document.getElementById("type0").style.backgroundColor=(map.getCurrentMapType()==G_NORMAL_MAP)?SELECTCOLOR:BACKCOLOR;
		document.getElementById("type1").style.backgroundColor=(map.getCurrentMapType()==G_SATELLITE_MAP)?SELECTCOLOR:BACKCOLOR;
		ZoomPlus(0);
	}

	// 
	function MapGoto(a,b,c){
		Zoom(c);
		map.recenterOrPanToLatLng(new GPoint(a,b));
	}
	
//]]>

