var map,zm,start,sraku,sons,shotp;
var oldaddr = new Array();

function startUp() {
  map = new GMap2( document.getElementById("mymap") );
  map.setCenter( new GLatLng(35.656, 139.54), 5 );
  map.addControl(new GLargeMapControl());
  map.addControl(new GMapTypeControl());
  map.addControl(new GScaleControl());
  map.addControl(new GOverviewMapControl(new GSize(200, 150)));
  map.addControl(new ZoomBox());

  document.F3.S3.style.visibility = "hidden";



  //マウスホイールイベントを追加
  if( navigator.userAgent.match( "MSIE" ) ){
	document.getElementById( "mymap" ).attachEvent( "onmousewheel" , mouseWheelZooming );
  }
  if( navigator.userAgent.match( "Gecko" ) ){
	document.getElementById( "mymap" ).addEventListener( "DOMMouseScroll" , mouseWheelZooming , false );
  }
  if( navigator.userAgent.match( "Safari" ) ){
	document.getElementById( "mymap" ).onmousewheel = mouseWheelZooming;
  }

  function invGeo(latlng, fun) {
	GDownloadUrl( "igeo.php?lat="+encodeURIComponent(latlng.lat())
		+"&lng="+encodeURIComponent(latlng.lng()), fun );
  }

  function wikisearch(sw, address, fun) {
	GDownloadUrl( "wiki.php?sw="+sw+"&city="+encodeURIComponent(address), fun );
  }

  function imgsearch(sw, address, fun) {
	GDownloadUrl( "image.php?sw="+sw+"&start="+start+"&addr="+encodeURIComponent(address), fun );
  }

  function localsearch(sw, latlng, fun) {
	GDownloadUrl( "localsearch.php?sw="+sw+"&lat="+encodeURIComponent(latlng.lat())
		+"&lng="+encodeURIComponent(latlng.lng()), fun );
  }

  function onsensearch(sw, address, fun) {
	GDownloadUrl( "onsen.php?sw="+sw+"&start="+sons+"&pref="+encodeURIComponent(address), fun );
  }

  function setWeather(sw, latlng, fun) {
    // 座標をIDに変換
    var id = latlngToID( latlng );

    // Weather Hacksに問い合わせ
    GDownloadUrl( "tomorrow_weather.php?sw="+sw+"&city="+encodeURIComponent(id), fun);
  }

  function stationsearch(sw, latlng, fun) {
	GDownloadUrl( "station.php?sw="+sw+"&lat="+encodeURIComponent(latlng.lat())
		+"&lng="+encodeURIComponent(latlng.lng()), fun );
  }

  function restaurantsearch(sw, latlng, fun) {
	GDownloadUrl( "restaurant.php?sw="+sw+"&lat="+encodeURIComponent(latlng.lat())
		+"&lng="+encodeURIComponent(latlng.lng()), fun );
  }

  function hotpeppersearch(sw, address, fun) {
	GDownloadUrl( "hotpepper.php?sw="+sw+"&start="+shotp+"&genre="+document.F3.S3.value+"&addr="+encodeURIComponent(address), fun );
  }

  function hotelsearch(sw, address, fun) {
	GDownloadUrl( "hotel.php?sw="+sw+"&pref="+encodeURIComponent(address), fun );
  }

  function rakutensearch(sw, address, fun) {
	GDownloadUrl( "rakuten.php?sw="+sw+"&srak="+srak+"&addr="+encodeURIComponent(address), fun );
  }


  GEvent.addListener( map, "click", function(ov,latlng){ 
        if(ov)
		return;
	if(document.F2.S2.value=='mode0')
		return;
        var pm = new PositionMark(latlng);
        map.addOverlay( pm );
	zm = map.getZoom();
	start = 1;
	srak = 1;
	sons = 1;
	shotp = 1;
		invGeo( latlng, function(address) {
		var space = " ";
		var SPaddr = address.split(space);
		var Prep = SPaddr[0].replace(/県$/, '');
		Prep = Prep.replace(/東京都/, /東京/);
		Prep = Prep.replace(/府$/, '');
		var Crep = SPaddr[1].replace(/市$/, '');
		Crep = Crep.replace(/市.*区$/,'');
		Crep = Crep.replace(/町$/,'');
		Crep = Crep.replace(/村$/,'');
		Crep = Crep.replace(/.*郡/,'');
//		Crep = Crep.replace(/郡.*村$/,'');
//		Crep = Crep.replace(/郡.*町$/,'');
		var reptmp,initDatatmp;
		if(zm >= 14){
			reptmp = Crep;
			initDatatmp = SPaddr[0]+SPaddr[1]+SPaddr[3];
		}else if(zm >= 10 && zm <= 13){
			reptmp = Crep;
			initDatatmp = SPaddr[0]+SPaddr[1];
		}else {
			reptmp = Prep;
			initDatatmp = SPaddr[0];
		}
		if(document.F2.S2.value=='mode1'){
			var swlocal=0,swwiki=0,swonsen=0,swstation=0,swweather=0,swrestaurant=0,swhotel=0,swhotp=0,swrakuten=0,swimage=1;
			document.F1.S1.value = 'イベント';
		}
		if(document.F2.S2.value=='mode2'){
			var swlocal=1,swwiki=1,swonsen=0,swstation=0,swweather=0,swrestaurant=0,swhotel=0,swhotp=0,swrakuten=0,swimage=1;
			document.F1.S1.value = '観光名所';
		}
		if(document.F2.S2.value=='mode3'){
			var swlocal=0,swwiki=0,swonsen=0,swstation=0,swweather=0,swrestaurant=0,swhotel=0,swhotp=0,swrakuten=1,swimage=1;
			document.F1.S1.value = 'おみやげ';
		}
		if(document.F2.S2.value=='mode4'){
			var swlocal=0,swwiki=0,swonsen=1,swstation=1,swweather=0,swrestaurant=0,swhotel=0,swhotp=0,swrakuten=0,swimage=1;
			document.F1.S1.value = '温泉';
		}
		if(document.F2.S2.value=='mode5'){
			var swlocal=0,swwiki=0,swonsen=0,swstation=1,swweather=0,swrestaurant=0,swhotel=1,swhotp=0,swrakuten=0,swimage=0;
		}
		if(document.F2.S2.value=='mode6'){
			var swlocal=0,swwiki=0,swonsen=0,swstation=1,swweather=0,swrestaurant=1,swhotel=0,swhotp=1,swrakuten=0,swimage=0;
		}
		if(document.F2.S2.value=='mode7'){
			var swlocal=0,swwiki=0,swonsen=0,swstation=0,swweather=1,swrestaurant=0,swhotel=0,swhotp=0,swrakuten=0,swimage=0;
		}
		if(document.F2.S2.value=='mode8'){
			var swlocal=0,swwiki=0,swonsen=0,swstation=1,swweather=0,swrestaurant=0,swhotel=0,swhotp=0,swrakuten=0,swimage=0;
		}
		if(document.F2.S2.value=='mode9'){
			var swlocal=0,swwiki=0,swonsen=0,swstation=0,swweather=0,swrestaurant=0,swhotel=0,swhotp=0,swrakuten=0,swimage=0;
		}
			setWeather( swweather, latlng, function(weatherData) {
				var SPweather = weatherData.split(space);
			if(swonsen){
				for(i=0;i<oldaddr.length;i++){
					if(oldaddr[i] == SPaddr[0]+' 温泉')
						sons += 20;
				}
				oldaddr.push(SPaddr[0]+' 温泉');
			}
			wikisearch( swwiki, document.a.b.value, function(wikibody){
			onsensearch( swonsen, SPaddr[0], function(onsenName){
				var SPonsen = onsenName.split(space);
			stationsearch( swstation, latlng, function(stationData){
				var SPstation = stationData.split(space);
			restaurantsearch( swrestaurant, latlng, function(restaurantData){
				var SPrestaurant = restaurantData.split('???');
			if(swhotp){
				for(i=0;i<oldaddr.length;i++){
					if(oldaddr[i] == SPaddr[0]+SPaddr[1]+document.F3.S3.value)
						shotp += 25;
				}
				oldaddr.push(SPaddr[0]+SPaddr[1]+document.F3.S3.value);
			}
			hotpeppersearch( swhotp, SPaddr[0]+SPaddr[1], function(hotpepperData){
				var SPhotp = hotpepperData.split('???');
			hotelsearch( swhotel, SPaddr[0], function(hotelData){
				var SPhotel = hotelData.split('???');
			if(swrakuten){
				for(i=0;i<oldaddr.length;i++){
					if(oldaddr[i] == reptmp+' みやげ')
						srak += 1;
				}
				oldaddr.push(reptmp+' みやげ');
			}
			rakutensearch( swrakuten, reptmp+' みやげ', function(rakutenData){
				var SPrakuten = rakutenData.split('???');
			if(swimage){
				if(document.F1.S1.value=='<----イメージ検索オプション---->'||document.F1.S1.value=='')
					document.F1.S1.value = '観光名所';
				for(i=0;i<oldaddr.length;i++){
					if(oldaddr[i] == reptmp+document.F1.S1.value)
						start += 10;
				}
				oldaddr.push(reptmp+document.F1.S1.value);
			}
			imgsearch( swimage, reptmp+"　"+document.F1.S1.value, function(keyword){
						var SPkeyword = keyword.split(space);
			localsearch( swlocal, latlng, function(local){
						var SPlocal = local.split(space);
						
    			GEvent.addListener(map, "addoverlay",
			function() { map.removeOverlay(pm); });
						addHistory(latlng,
							   reptmp,
							   initDatatmp,
							   SPkeyword,
							   SPlocal,
							   wikibody,
							   SPweather,
							   SPonsen,
							   SPstation,
							   SPrestaurant,
							   SPhotp,
							   SPhotel,
							   SPrakuten,
							swlocal,
							swonsen,
							0,
							swstation,
							swweather,
							swrestaurant,
							swhotp,
							swhotel,
							swrakuten,
							swimage);
			});
			});
			});
			});
			});
			});
			});
			});
			});
			});

      	});
  });

}


  function wikisearch2(sw, address, fun) {
	GDownloadUrl( "wiki.php?sw="+sw+"&city="+encodeURIComponent(address), fun );
  }
  function stationsearch2(sw, latlng, fun) {
	GDownloadUrl( "station.php?sw="+sw+"&lat="+encodeURIComponent(latlng.lat())
		+"&lng="+encodeURIComponent(latlng.lng()), fun );
  }
  function imgsearch2(sw, address, fun) {
	GDownloadUrl( "image.php?sw="+sw+"&start="+start+"&addr="+encodeURIComponent(address), fun );
  }
//ジオコーディング移動
function moveTo(place, sw) {
  var gls = new GlocalSearch();
  gls.setSearchCompleteCallback( null, moveToThePlace );
  gls.setCenterPoint(map); // 現在地図で表示されている付近を重点的に検索
  gls.execute(place);

  function moveToThePlace() {
    if( !gls.results || gls.results.length==0 )
      alert( place + " は見つかりませんでした" );
    else {
      var p = gls.results[0];
//      document.a.b.value = gls.results[0].city;
	map.setZoom(16);
      map.setCenter( new GLatLng(p.lat, p.lng) );
    if(sw)
	document.a.b.value = sw;
/*    if(document.F2.S2.value=='mode2'||sw != 0 ){
	var pm = new PositionMark(new GLatLng(p.lat, p.lng));
        map.addOverlay( pm );
	wikisearch2( 1, document.a.b.value, function(wikibody){
	stationsearch2( 1, new GLatLng(p.lat, p.lng), function(stationData){
	var space = " ";
	var SPstation = stationData.split(space);
	start=1;
	for(i=0;i<oldaddr.length;i++){
		if(oldaddr[i] == document.a.b.value)
			start += 10;
	}
	oldaddr.push(document.a.b.value);
	imgsearch2( 1, document.a.b.value, function(keyword){
		var SPkeyword = keyword.split(space);
	GEvent.addListener(map, "addoverlay",
	function() { map.removeOverlay(pm); });
		addHistory(
							new GLatLng(p.lat, p.lng),
							   0,
							   document.a.b.value,
							   SPkeyword,
							   0,
							wikibody,
							   0,
							   0,
							   SPstation,
							   0,
							   0,
							   0,
							   0,
							0,
							0,
							1,
							1,
							0,
							0,
							0,
							0,
							0,
							1);
	});
	});
	});
	} */
    }
  }
}


//マーカークリア
function clrMarker() {
	map.clearOverlays();
	points = [];
	prevPos = [];
	newItems = [];
	counter = 1;
	mks = [];
	oldaddr = [];
	totaldis = 0;
	totaldisbox = [];
	totaldisbox.push(totaldis);
	parent.image.document.getElementById("history").innerHTML = "";
	parent.image.document.getElementById("distance").innerHTML = totaldis +"m";
}

//アンドゥ
function undoMarker(){
	map.closeInfoWindow();
	map.removeOverlay(mks[counter-2]);

	if(counter>1)
		counter--;

	if(counter<=1){
		parent.image.document.getElementById("history").innerHTML = "";
		points.pop();
		prevPos.pop();
		oldaddr.pop();
		totaldis = 0;
		totaldisbox = [];
		totaldisbox.push(totaldis);
		    if(totaldis >= 1000)
		    	parent.image.document.getElementById("distance").innerHTML = shortForm10(totaldis/1000) +"km";
		    if(totaldis < 1000)
    			parent.image.document.getElementById("distance").innerHTML = totaldis +"m";
		return;
		}

	points.pop();
	prevPos.pop();
	oldaddr.pop();
	mks.pop();
	
	totaldisbox.pop();
	totaldis = totaldisbox.pop();
	totaldisbox.push(totaldis);
	if(totaldis >= 1000)
		parent.image.document.getElementById("distance").innerHTML = shortForm10(totaldis/1000) +"km";
	if(totaldis < 1000)
		parent.image.document.getElementById("distance").innerHTML = totaldis +"m";


	GEvent.trigger(mks[counter-2],'click');

	var tmp = prevPos.pop();
	map.setCenter(tmp);
	prevPos.push(tmp);

	if(line != null)
		map.removeOverlay(line);
	line = new GPolyline(points, "#0000FF", 10);
	map.addOverlay(line);

	parent.image.document.getElementById("history").removeChild(parent.image.document.getElementById("history").lastChild);
	parent.image.document.getElementById("history").removeChild(parent.image.document.getElementById("history").lastChild);

}


function shopCenter(lat, lng, shopName, flag) {
	map.closeInfoWindow();
	var latlng = new GLatLng(lat, lng);
	map.setCenter( latlng );

    	var icon = new GIcon();
	if(flag == 1){
    		icon.image      = "markers/food.png";
	}else if(flag == 2){
 	   	icon.image      = "markers/hotel.png";
	}else if(flag == 3){
 	   	icon.image      = "markers/house.png";
	}
  	icon.iconSize   = new GSize(21, 31);
  	icon.shadow     = "http://www.google.com/mapfiles/shadow50.png";
  	icon.shadowSize = new GSize(52, 29);
  	icon.iconAnchor = new GPoint(20, 29);
   	icon.infoWindowAnchor = new GPoint(10, 0);

	var mk = new GMarker(latlng,icon);
        map.addOverlay(mk);
	
	shopName = shopName.split(',');

	var shoptmp;
	var shop = document.createElement("div");
	if(flag == 1){
		shoptmp = "<b><font size=2><a href=\""+shopName[1]+"\" target=\"_blank\">"+shopName[0]+"</font></b></a><br>";
		shoptmp += "<font size=1>価格（夜）："+shopName[2]+"</font><br>";
		shoptmp += "<font size=1>価格（昼）："+shopName[3]+"</font><br>";
		shoptmp += "<font size=1>カテゴリ："+shopName[4]+"</font><br>";
//		shoptmp += "<form><input type='button' value='消去' onClick='map.removeOverlay(mk);'></form>";
	}
	else if(flag == 2){
	shoptmp = "<b><font size=2><a href=\""+shopName[1]+"\" target=\"_blank\">"+shopName[0]+"</font></b></a><br>";
	shoptmp += "<font size=2><a href=\""+shopName[3]+"\" target=\"_blank\">"+shopName[2]+"</font></a><br>";
	shoptmp += "<font size=1>コメント："+shopName[4]+"</font><br>";
	shoptmp += "<font size=1>価格："+shopName[5]+"</font><br>";
	}
	else if(flag == 3){
	shoptmp = "<b><font size=2>"+shopName[0]+"</font></b>";
	}
	shop.innerHTML = shoptmp;

	GEvent.addListener(mk, "click",
        	function() {
			mk.openInfoWindowHtml(shop,{maxWidth:250});
		}
	);
	GEvent.trigger(mk,'click');
}

function shopTo(place, shopName) {
//  var p;
	map.closeInfoWindow();
  var gls = new GlocalSearch();
  gls.setSearchCompleteCallback( null, moveToThePlace );
  gls.setCenterPoint(map); // 現在地図で表示されている付近を重点的に検索
  gls.execute(place);

  function moveToThePlace() {
    if( !gls.results || gls.results.length==0 )
      alert( place + " は見つかりませんでした" );
    else {
      var p = gls.results[0];
  	map.closeInfoWindow();
	var latlng = new GLatLng(p.lat, p.lng);
        map.setCenter( latlng );



    	var icon = new GIcon();
    	icon.image      = "markers/food.png";
  	icon.iconSize   = new GSize(21, 31);
  	icon.shadow     = "http://www.google.com/mapfiles/shadow50.png";
  	icon.shadowSize = new GSize(52, 29);
  	icon.iconAnchor = new GPoint(20, 29);
   	icon.infoWindowAnchor = new GPoint(10, 0);

	var mk = new GMarker(latlng,icon);
        map.addOverlay(mk);
	
	shopName = shopName.split(',');

	var shoptmp;
	var shop = document.createElement("div");
				shoptmp = "<img src="+shopName[4]+"><br><font size=1>写真提供：ホットペッパー.jp</font><br>";
				shoptmp += "<b><font size=2><a href=\""+shopName[1]+"\" target=\"_blank\">"+shopName[0]+"</font></b></a><br>";
				shoptmp += "<font size=1>"+shopName[2]+"</font><br>";
				shoptmp += "<font size=1>予算："+shopName[3]+"</font><br>";
				shoptmp += "<font size=1>ジャンル："+shopName[5]+"</font><br>";
				shoptmp += "<font size=1>アクセス："+shopName[6]+"</font><br>";

	shop.innerHTML = shoptmp;

	GEvent.addListener(mk, "click",
        	function() {
			mk.openInfoWindowHtml(shop,{maxWidth:250});
		}
	);
	GEvent.trigger(mk,'click');
    }
  }

}

function localmove(lat, lng, Name){
	map.closeInfoWindow();
	var pm = new PositionMark(new GLatLng(lat, lng));
        map.addOverlay( pm );
	wikisearch2( 1, Name, function(wikibody){
	stationsearch2( 1, new GLatLng(lat, lng), function(stationData){
	var space = " ";
	var SPstation = stationData.split(space);
	start=1;
	for(i=0;i<oldaddr.length;i++){
		if(oldaddr[i] == Name)
			start += 10;
	}
	oldaddr.push(Name);
	imgsearch2( 1, Name, function(keyword){
		var SPkeyword = keyword.split(space);
	GEvent.addListener(map, "addoverlay",
	function() { map.removeOverlay(pm); });
		addHistory(
							new GLatLng(lat, lng),
							   0,
							   Name,
							   SPkeyword,
							   0,
							wikibody,
							   0,
							   0,
							   SPstation,
							   0,
							   0,
							   0,
							   0,
							0,
							0,
							1,
							1,
							0,
							0,
							0,
							0,
							0,
							1);
	});
	});
	});
}


var points = [];
var line   = null;
var prevPos = [];     // 前回addHistoryされた位置
var counter = 1; // 何回目のaddHistoryか？
var mks = [];
var newItems = [];
var totaldis = 0;
var totaldisbox = [];
    totaldisbox.push(totaldis);

function addHistory(latlng,
		reptmp,
		initData,
		SPkeyword,
		SPlocal,
		wikiData,
		SPweather,
		SPonsen,
		SPstation,
		SPrestaurant,
		SPhotp,
		SPhotel,
		SPrakuten,
		swlocal,
		swonsen,
		swwiki,
		swstation,
		swweather,
		swrestaurant,
		swhotp,
		swhotel,
		swrakuten,
		swimage) {

	//ライン描画
	points.push(latlng);
	if(line != null)
		map.removeOverlay(line);
	line = new GPolyline(points, "#0000FF", 10);
	map.addOverlay(line);

  var posLink = createPositionLink();
  var distStr = calcDistanceString();
  var newItem = addListItem( posLink, distStr );

  addMarker();
  GEvent.trigger(mks[counter-2],'click');


  // サブルーチン：緯度経度の文字列と、クリックイベント処理を準備
  var mkscount = counter-2;
  function createPositionLink() {
	var posLink = document.createElement("a");
	posLink.innerHTML =　initData+"<br>";
	if(swimage){
		if(swwiki)
			posLink.innerHTML +=　"<font size=2>画像検索keyword："+initData+"</font><br>";
		else
			posLink.innerHTML +=　"<font size=2>画像検索keyword："+reptmp+"+"+document.F1.S1.value+"</font><br>";
		posLink.innerHTML +=　"<font size=2>画像："+((SPkeyword.length-1)/2)+"件 </font>";
	}
	if(swrakuten){
		posLink.innerHTML +=　"<font size=2>楽天："+((SPrakuten.length-1)/6)+"件 </font>";
	}
	if(swonsen){
		posLink.innerHTML +=　"<font size=2>温泉："+((SPonsen.length-1)/2)+"件 </font>";
	}
	if(swhotp){
		posLink.innerHTML +=　"<font size=2>HotPepper："+((SPhotp.length-1)/8)+"件 </font>";
	}
	if(swrestaurant){
		posLink.innerHTML +=　"<font size=2>食べログ："+((SPrestaurant.length-1)/8)+"件 </font>";
	}
	if(swhotel){
		posLink.innerHTML +=　"<font size=2>ホテル："+((SPhotel.length-1)/9)+"件 </font>";
	}
	if(swimage||swonsen||swrestaurant||swhotel||swrakuten)
		posLink.innerHTML +=　"<br>";
	if(swimage){
	if(SPkeyword.length < 5)
		for(i=0;i<SPkeyword.length-1;i+=2){
		posLink.innerHTML += "<img src=\""+SPkeyword[i]+".jpg\" height=60>";
		}
	else{
		for(i=0;i<6;i+=2){
		posLink.innerHTML += "<img src=\""+SPkeyword[i]+".jpg\" height=60>";
		}
    	}
	}
	if(swimage)
		posLink.innerHTML += "<br>";
	posLink.innerHTML += "(" + shortForm(latlng.lat()) + "," + shortForm(latlng.lng()) + ")";
	posLink.href = "#";
	posLink.onclick = function() { map.panTo(latlng);GEvent.trigger(mks[mkscount],'click'); }
	return posLink;
  }


  // サブルーチン：距離を文字列表記
  function calcDistanceString() {
    var str;
    var tmp = prevPos.pop();
    if( tmp == undefined )
      str = "?";
    else if( shortForm( latlng.distanceFrom(tmp) ) >= 1000 ){
      str = shortForm10( latlng.distanceFrom(tmp)/1000 ) + "km";
    totaldis += shortForm( latlng.distanceFrom(tmp) );
    totaldis = shortForm( totaldis );
    totaldisbox.push(totaldis);}
    else{
      str = shortForm( latlng.distanceFrom(tmp) ) + "m";
    totaldis += shortForm( latlng.distanceFrom(tmp) );
    totaldis = shortForm( totaldis );
    totaldisbox.push(totaldis);}
    if(totaldis >= 1000)
    	parent.image.document.getElementById("distance").innerHTML = shortForm10(totaldis/1000) +"km";
    else
    	parent.image.document.getElementById("distance").innerHTML = totaldis +"m";
    prevPos.push(tmp);
    prevPos.push(latlng);
    return str;
  }

  // サブルーチン：リスト項目を追加
  function addListItem( pl, ds ) {
    var newLi = document.createElement("li");
    var distText = document.createTextNode(" - " + ds);
    var br = document.createElement("br");
    newLi.appendChild(pl);
    newLi.appendChild(distText);

    var historyList = parent.image.document.getElementById("history");
    historyList.appendChild(newLi);
    historyList.appendChild(br);
    newItems.push(newLi);
    newItems.push(br);
    return newLi;
  }


  // サブルーチン：マーカー追加
  function addMarker() {
    var icon = new GIcon();
    if(document.F2.S2.value=='mode5')
	icon.image      = "hotelmarkers/marker"+counter+".png";
    else if(document.F2.S2.value=='mode6')
	icon.image      = "foodmarkers/marker"+counter+".png";
    else{
	icon.image      = "markers/marker"+counter+".png";
    }
    icon.iconSize   = new GSize(20, 34);
    icon.shadow     = "http://www.google.com/mapfiles/shadow50.png";
    icon.shadowSize = new GSize(37, 34);
    icon.iconAnchor = new GPoint(10, 34);
    icon.infoWindowAnchor = new GPoint(10, 0);




     var mk = new GMarker(latlng, icon);
     map.addOverlay(mk);
     mks[counter-1] = mk;

     counter ++;


     // イベント追加
	GEvent.addListener(mk, "click",
		function() {
			
			parent.anmcnt = counter-1;

			var tablist = [];
			if(swlocal)
				tablist.push(new GInfoWindowTab( "ランドマーク", local ));
			if(swwiki)
				tablist.push(new GInfoWindowTab( "データ", wiki ));
			if(swweather)
				tablist.push(new GInfoWindowTab( "天気", weather ));
			if(swonsen)
				tablist.push(new GInfoWindowTab( "温泉", onsen ));
			if(swrakuten)
				tablist.push(new GInfoWindowTab( "楽天商品", rakuten ));
			if(swimage)
				tablist.push(new GInfoWindowTab( "画像検索", image ));
			if(swhotp)
				tablist.push(new GInfoWindowTab( "Hotpepper", hotp ));
			if(swrestaurant)
				tablist.push(new GInfoWindowTab( "食べログ", restaurant ));
			if(swhotel)
				tablist.push(new GInfoWindowTab( "ホテル情報", hotel ));
			if(swstation)
				tablist.push(new GInfoWindowTab( "最寄り駅", station ));
			if(document.F2.S2.value=='mode9')
				tablist.push(new GInfoWindowTab( "距離", view ));
			mk.openInfoWindowTabs( tablist, {"maxWidth" : 380});
		}
	);


     
     GEvent.addListener(mk, "mouseover",
        function() { newItem.style.backgroundColor="#ccccff"; });
     GEvent.addListener(mk, "mouseout",
        function() { newItem.style.backgroundColor="transparent"; });


  // "表示" タブの内容
  // データをそのままHTMLとして利用


  var local = document.createElement("div");
	var localtmp = "<div class='scroll'>";
	if(SPlocal[1]!=undefined){
 		for(i=0;i<SPlocal.length;i+=3){

			if(SPlocal[i+2]!=undefined){
				localtmp += "<font size=2><a href=\"JavaScript:localmove('"+SPlocal[i+1]+"','"+SPlocal[i+2]+"','"+SPlocal[i]+"')\">"+SPlocal[i]+"</font></a><br>";
			}
		}
	}
	else {localtmp = "<font size=2>見つかりませんでした</font><br><br>";}
	localtmp += "<!-- Begin Yahoo! JAPAN Web Services Attribution Snippet --><a href=\"http://developer.yahoo.co.jp/about\"><img src=\"http://i.yimg.jp/images/yjdn/yjdn_attbtn1_125_17.gif\" title=\"Webサービス by Yahoo! JAPAN\" alt=\"Web Services by Yahoo! JAPAN\" width=\"125\" height=\"17\" border=\"0\" style=\"margin:15px 15px 15px 15px\"></a><!-- End Yahoo! JAPAN Web Services Attribution Snippet --></div>";
	local.innerHTML += localtmp;


　　var　wiki = document.createElement("div");
	wiki.innerHTML = "<div class='scroll'><b>　"+initData+"</b><br><font size=2><br>"+wikiData+"</font></div>";

    var calorie = Math.floor((totaldis/4800)*220);
    var view = document.createElement("div");
	var viewtmp =  "<center>";
	viewtmp += "<b><"+initData+"></b><br>";
	viewtmp += "<font size=2><br>マーカー間の距離：" + distStr + "<br>";
    if(totaldis >= 1000)
	viewtmp += "総移動距離：" + shortForm10(totaldis/1000) + "km<br><br>";
    else
	viewtmp += "総移動距離：" + totaldis + "m<br><br>";
	viewtmp += "徒歩で約"+Math.floor(totaldis/80)+"分かかり、約" + calorie + "kcal消費します。<br>";
	viewtmp += "おにぎりに換算すると約" + shortForm10(calorie/150) + "個分です。<br>";
	viewtmp += "自転車で約"+Math.floor(totaldis/170)+"分、クルマで約"+Math.floor(totaldis/333)+"分です。";
	viewtmp += "</font></center>";
	view.innerHTML += viewtmp;

  var weather = document.createElement("div");
	var weathertmp =  "<div class='scroll'><center>";
	weathertmp += "<b><"+initData+"></b><br><br>";
 	weathertmp += "<b>明日の"+SPweather[0]+"の天気</b><br><br><img src=\""+SPweather[2]+"\"><br><font size=2>"+SPweather[1]+"</font><br>"
			+ "<font color=\"blue\">"+SPweather[3]+"</font>/<font color=\"red\">"+SPweather[4]+"</font><br><br>";
	weathertmp += "</div>";
	weather.innerHTML += weathertmp;


  var image = document.createElement("div");
	var imagetmp =  "<div class='scroll'><center>";
	if(swwiki)
		imagetmp += "<b>"+initData+"<br><br>";
	else
		imagetmp += "<b>"+reptmp+"の"+document.F1.S1.value+"<br><br>";
	if(SPkeyword[1]){
		for(i=0;i<SPkeyword.length-1;i+=2){
			imagetmp += "<a href=\""+SPkeyword[i+1]+"\" target=\"_blank\"><img src=\""+SPkeyword[i]+".jpg\" height=80></a>　";
		}
	}
	else{
		imagetmp += "<font size=2>見つかりませんでした</font>";
	}
	imagetmp += "</center>";
	imagetmp += "<!-- Begin Yahoo! JAPAN Web Services Attribution Snippet --><a href=\"http://developer.yahoo.co.jp/about\"><img src=\"http://i.yimg.jp/images/yjdn/yjdn_attbtn1_125_17.gif\" title=\"Webサービス by Yahoo! JAPAN\" alt=\"Web Services by Yahoo! JAPAN\" width=\"125\" height=\"17\" border=\"0\" style=\"margin:15px 15px 15px 15px\"></a><!-- End Yahoo! JAPAN Web Services Attribution Snippet --></div>";
	image.innerHTML += imagetmp;

  var onsen = document.createElement("div");
	var onsentmp =  "<div class='scroll'><font size=2>";
 	for(i=0;i<SPonsen.length-1;i=i+2){
	onsentmp += SPonsen[i]+"<br><a href=\"JavaScript:moveTo('"+SPonsen[i+1]+"','"+SPonsen[i]+"')\">"+SPonsen[i+1]+"</a><br>";
	}
		
  	onsentmp += "<br><br><a href=\"http://jws.jalan.net/\" target=\"_blank\">じゃらん Web サービス</a></div></font>";
	onsen.innerHTML = onsentmp;

  var station = document.createElement("div");  
 	var stationtmp = "<font size=2><div class='scroll'><center><img src='http://map.simpleapi.net/stationmap?x="+latlng.lng()+"&y="+latlng.lat()+"'></center><br>";
	for(i=0;i<SPstation.length-5;i+=5){
	stationtmp += "<b>"+SPstation[i]+"</b>（"+SPstation[i+1]+")から "+SPstation[i+2]+SPstation[i+3]+"("+SPstation[i+4]+")<br>";
	}
	stationtmp += "</font></div>";
	station.innerHTML = stationtmp;


  var hotp = document.createElement("div");
	var hotptmp = "<div class='scroll'>";
	if(SPhotp[1]!=undefined){
 		for(i=0;i<SPhotp.length;i+=8){
			var hotpName = new Array();

			hotpName[0] = SPhotp[i];
			hotpName[1] = SPhotp[i+1];
			hotpName[2] = SPhotp[i+2];
			hotpName[3] = SPhotp[i+3];
			hotpName[4] = SPhotp[i+4];
			hotpName[5] = SPhotp[i+5];
			hotpName[6] = SPhotp[i+6];
		

			if(SPhotp[i+2]!=undefined){
				hotptmp += "<img src="+SPhotp[i+4]+"><br><font size=1>写真提供：ホットペッパー.jp</font><br>";
				hotptmp += "<b><font size=2><a href=\""+SPhotp[i+1]+"\" target=\"_blank\">"+SPhotp[i]+"</font></b></a><br>";
				hotptmp += "<font size=1>"+SPhotp[i+2]+"</font><br>";
				hotptmp += "<font size=1>予算："+SPhotp[i+3]+"</font><br>";
				hotptmp += "<font size=1>ジャンル："+SPhotp[i+5]+"</font><br>";
				hotptmp += "<font size=1>アクセス："+SPhotp[i+6]+"</font><br>";
				hotptmp += "<font size=1>住所：<a href=\"JavaScript:shopTo('"+SPhotp[i+7].replace(/　.*/,'')+"','"+hotpName+"')\">"+SPhotp[i+7]+"</a></font><br><br>";
			}
		}
	}
	else {hotptmp = "<font size=2>見つかりませんでした</font><br><br>";}
	hotptmp += "Powered by <a href=\"http://www.hotpepper.jp/\" target=\"_blank\">ホットペッパー.jp</a></div>";
	hotp.innerHTML += hotptmp;


  var restaurant = document.createElement("div");
	var resttmp = "<div class='scroll'>";
	if(SPrestaurant[1]!=undefined){
 		for(i=0;i<SPrestaurant.length;i+=8){
			var restName = new Array();
			if(SPrestaurant[i+2]){
				SPrestaurant[i+2] = SPrestaurant[i+2].replace(/,/, '');
				SPrestaurant[i+2] = SPrestaurant[i+2].replace(/,/, '');
				SPrestaurant[i+3] = SPrestaurant[i+3].replace(/,/, '');
				SPrestaurant[i+3] = SPrestaurant[i+3].replace(/,/, '');
			}
			restName[0] = SPrestaurant[i];
			restName[1] = SPrestaurant[i+1];
			restName[2] = SPrestaurant[i+2];
			restName[3] = SPrestaurant[i+3];
			restName[4] = SPrestaurant[i+4];
		

			if(SPrestaurant[i+2]!=undefined){
				resttmp += "<b><font size=2><a href=\""+SPrestaurant[i+1]+"\" target=\"_blank\">"+SPrestaurant[i]+"</font></b></a><br>";
				resttmp += "<font size=1>価格（夜）："+SPrestaurant[i+2]+"</font><br>";
				resttmp += "<font size=1>価格（昼）："+SPrestaurant[i+3]+"</font><br>";
				resttmp += "<font size=1>カテゴリ："+SPrestaurant[i+4]+"</font><br>";
				resttmp += "<font size=1>住所：<a href=\"JavaScript:shopCenter("+SPrestaurant[i+6]+","+SPrestaurant[i+7]+",'"+restName+"',1)\">"+SPrestaurant[i+5]+"</a></font><br><br>";
			}
		}
	}
	else {resttmp = "<font size=2>見つかりませんでした</font><br><br>";}
	resttmp += "<a href=\"http://apiblog.kakaku.com/\" target=\"_blank\"><img src=\"http://img.tabelog.com/images/banner/tabelog_api_135x17.gif \" alt=\"食べログ.com WEB サービス\" title=\"食べログ.com WEB サービス\" border=\"0\" /></a></div>";
	restaurant.innerHTML += resttmp;


  var hotel = document.createElement("div");
	var hoteltmp = "<div class='scroll'>";
	if(SPhotel[1]!=undefined){
 		for(i=0;i<SPhotel.length;i+=9){
			var hotelName = new Array();
			hotelName[0] = SPhotel[i];
			hotelName[1] = SPhotel[i+1];
			hotelName[2] = SPhotel[i+2];
			hotelName[3] = SPhotel[i+3];
			hotelName[4] = SPhotel[i+4];
			hotelName[5] = SPhotel[i+5];

			if(SPhotel[i+2]!=undefined){
				hoteltmp += "<b><font size=2><a href=\""+SPhotel[i+1]+"\" target=\"_blank\">"+SPhotel[i]+"</font></b></a><br>";
				hoteltmp += "<font size=2><a href=\""+SPhotel[i+3]+"\" target=\"_blank\">"+SPhotel[i+2]+"</font></a><br>";
				hoteltmp += "<font size=1>"+SPhotel[i+4]+"</font><br>";
				hoteltmp += "<font size=2>宿泊料：\\"+SPhotel[i+5]+"</font><br>";
				hoteltmp += "<font size=2>住所：<a href=\"JavaScript:shopCenter("+SPhotel[i+7]+","+SPhotel[i+8]+",'"+hotelName+"',2)\">"+SPhotel[i+6]+"</a></font><br><br>";
			}
		}

	}
	else {hoteltmp = "<font size=2>見つかりませんでした</font><br><br>";}
	hoteltmp += "<a href=\"http://yoyaq.com/\" target=\"_blank\"><img src=http://yoyaq.com/images/api/135_17.gif width=135 height=17 alt=\"高級ホテルが最大70％の直前予約サイト yoyaQ.com\"></a></div>";
	hotel.innerHTML += hoteltmp;


  var rakuten = document.createElement("div");
	var rakutentmp = "<div class='scroll'>";
	if(SPrakuten[1]!=undefined){
 		for(i=0;i<SPrakuten.length;i+=6){
			if(SPrakuten[i+2]!=undefined){
				rakutentmp += "<img src='"+SPrakuten[i+3]+"'><br>";
				rakutentmp += "<b><font size=2><a href=\""+SPrakuten[i+1]+"\" target=\"_blank\">"+SPrakuten[i]+"</font></b></a><br>";
				rakutentmp += "<font size=2>価格：\\"+SPrakuten[i+2]+"</font><br>";
				rakutentmp += "<font size=2><a href=\""+SPrakuten[i+5]+"\" target=\"_blank\">"+SPrakuten[i+4]+"</font></a><br><br>";
			}
		}

	}
	else {rakutentmp = "<font size=2>見つかりませんでした</font><br><br>";}
	rakuten.innerHTML += rakutentmp;
  }



}


function PositionMark(latlng) {
  this.pos_ = latlng;
}

PositionMark.prototype = new GControl();

PositionMark.prototype.initialize = function(map) {
  this.box_ = document.createElement("div");
  this.box_.style.position        = "absolute";
  this.box_.style.width           = "8em";
  this.box_.style.backgroundColor = "white";
  this.box_.style.color           = "black";
  this.box_.style.fontSize        = "smaller";
  this.box_.style.border          = "1px solid black"; 
  this.box_.style.padding         = "1px 6px";
    this.box_.innerHTML =  "<img src='markers/miniload.gif'> Now Loading...";
  map.getPane(G_MAP_MAP_PANE).appendChild(this.box_);
  this.map_ = map;
}

PositionMark.prototype.redraw = function(force) {
  if(!force) return;

  var c1 = this.map_.fromLatLngToDivPixel(this.pos_);
  this.box_.style.left = c1.x + "px";
  this.box_.style.top  = c1.y + "px";

}

PositionMark.prototype.copy = function() {
  return new PositionMark(this.pos_);          // 自分をコピー
}

PositionMark.prototype.remove = function() {
  this.box_.parentNode.removeChild(this.box_); // 自分をDOMで親から削除
}



function ZoomBox() {}
ZoomBox.prototype = new GControl();
ZoomBox.prototype.initialize = function(map) {
  var container = document.createElement("div");

  var box = document.createElement("div");
  box.style.backgroundColor = "white";
  box.style.color           = "black";
  box.style.fontSize        = "smaller";
  box.style.border          = "1px solid black"; 
  box.style.padding         = "1px 6px";
  container.appendChild(box);

  box.innerHTML = 5;
  GEvent.addListener( map, "zoomend", function(){
	var zm1 = map.getZoom();
	box.innerHTML = zm1;
  } );

  map.getContainer().appendChild(container);
  return container;
}
ZoomBox.prototype.getDefaultPosition = function() {
  return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(25, 284));
}



onload   = startUp;
onunload = GUnload;
onresize = function() { map.checkResize(); }



//////////////////////////////////////////////////////////////////////////////////////


var db =
[{"name":"稚内","id":1,"lat":45.416995,"lng":"141.676999"},{"name":"旭川","id":2,"lat":43.763492,"lng":"142.357803"},{"name":"留萌","id":3,"lat":43.942848,"lng":"141.651433"},{"name":"札幌","id":4,"lat":43.068612,"lng":"141.350768"},{"name":"岩見沢","id":5,"lat":43.204201,"lng":"141.759359"},{"name":"倶知安","id":6,"lat":42.90164,"lng":"140.745471"},{"name":"網走","id":7,"lat":44.019873,"lng":"144.254156"},{"name":"北見","id":8,"lat":43.805504,"lng":"143.898167"},{"name":"紋別","id":9,"lat":44.348797,"lng":"143.348128"},{"name":"根室","id":10,"lat":43.326923,"lng":"145.582707"},{"name":"釧路","id":11,"lat":42.990584,"lng":"144.381983"},{"name":"帯広","id":12,"lat":42.917997,"lng":"143.201950"},{"name":"室蘭","id":13,"lat":42.317864,"lng":"140.975710"},{"name":"浦河","id":14,"lat":42.168366,"lng":"142.769976"},{"name":"函館","id":15,"lat":41.773709,"lng":"140.726413"},{"name":"江差","id":16,"lat":41.856727,"lng":"140.127933"},{"name":"青森","id":17,"lat":40.828668,"lng":"140.734738"},{"name":"むつ","id":18,"lat":41.286514,"lng":"141.166074"},{"name":"八戸","id":19,"lat":40.5092,"lng":"141.431499"},{"name":"秋田","id":20,"lat":39.716748,"lng":"140.129931"},{"name":"横手","id":21,"lat":39.310146,"lng":"140.560400"},{"name":"盛岡","id":22,"lat":39.701547,"lng":"141.136599"},{"name":"宮古","id":23,"lat":39.640287,"lng":"141.946454"},{"name":"大船渡","id":24,"lat":39.063529,"lng":"141.720807"},{"name":"仙台","id":25,"lat":38.260027,"lng":"140.882158"},{"name":"白石","id":26,"lat":43.05184,"lng":"141.408122"},{"name":"山形","id":27,"lat":38.248098,"lng":"140.327253"},{"name":"米沢","id":28,"lat":37.909478,"lng":"140.128209"},{"name":"酒田","id":29,"lat":38.922194,"lng":"139.845987"},{"name":"新庄","id":30,"lat":38.76256,"lng":"140.306064"},{"name":"福島","id":31,"lat":37.754123,"lng":"140.459680"},{"name":"小名浜","id":32,"lat":36.948151,"lng":"140.895903"},{"name":"若松","id":33,"lat":33.901179,"lng":"130.806307"},{"name":"水戸","id":54,"lat":36.370911,"lng":"140.476760"},{"name":"土浦","id":55,"lat":36.078644,"lng":"140.206238"},{"name":"宇都宮","id":56,"lat":36.559246,"lng":"139.898389"},{"name":"大田原","id":57,"lat":36.859584,"lng":"140.024810"},{"name":"前橋","id":58,"lat":36.383399,"lng":"139.072833"},{"name":"みなかみ","id":59,"lat":36.778614,"lng":"138.968800"},{"name":"さいたま","id":60,"lat":35.899208,"lng":"139.647519"},{"name":"熊谷","id":61,"lat":36.139627,"lng":"139.389528"},{"name":"秩父","id":62,"lat":35.99883,"lng":"139.086044"},{"name":"東京","id":63,"lat":35.681391,"lng":"139.766103"},{"name":"八丈島","id":65,"lat":33.107554,"lng":"139.795716"},{"name":"父島","id":66,"lat":27.091399,"lng":"142.198555"},{"name":"千葉","id":67,"lat":35.613425,"lng":"140.112837"},{"name":"銚子","id":68,"lat":35.729449,"lng":"140.827557"},{"name":"館山","id":69,"lat":34.9959,"lng":"139.861888"},{"name":"横浜","id":70,"lat":35.465941,"lng":"139.622847"},{"name":"小田原","id":71,"lat":35.256271,"lng":"139.155043"},{"name":"甲府","id":75,"lat":35.667054,"lng":"138.569015"},{"name":"河口湖","id":76,"lat":35.498231,"lng":"138.768852"},{"name":"富山","id":44,"lat":36.701384,"lng":"137.213091"},{"name":"伏木","id":45,"lat":36.792306,"lng":"137.058530"},{"name":"金沢","id":46,"lat":36.578117,"lng":"136.648166"},{"name":"輪島","id":47,"lat":37.388381,"lng":"136.932103"},{"name":"福井","id":48,"lat":36.061479,"lng":"136.223261"},{"name":"敦賀","id":49,"lat":35.644767,"lng":"136.076488"},{"name":"新潟","id":50,"lat":37.912299,"lng":"139.060869"},{"name":"長岡","id":51,"lat":37.447787,"lng":"138.853927"},{"name":"高田","id":52,"lat":34.515916,"lng":"135.745033"},{"name":"相川","id":53,"lat":34.757942,"lng":"135.533853"},{"name":"長野","id":72,"lat":36.643307,"lng":"138.189101"},{"name":"松本","id":73,"lat":36.230393,"lng":"137.964450"},{"name":"飯田","id":74,"lat":35.519544,"lng":"137.821244"},{"name":"静岡","id":34,"lat":34.971629,"lng":"138.388579"},{"name":"網代","id":35,"lat":35.043545,"lng":"139.081245"},{"name":"三島","id":36,"lat":35.126336,"lng":"138.910061"},{"name":"浜松","id":37,"lat":34.703866,"lng":"137.734759"},{"name":"名古屋","id":38,"lat":35.170694,"lng":"136.881637"},{"name":"豊橋","id":39,"lat":34.762734,"lng":"137.382128"},{"name":"岐阜","id":40,"lat":35.409967,"lng":"136.756324"},{"name":"高山","id":41,"lat":36.140574,"lng":"137.251301"},{"name":"津","id":42,"lat":34.734418,"lng":"136.510581"},{"name":"尾鷲","id":43,"lat":34.074304,"lng":"136.190168"},{"name":"大津","id":77,"lat":35.002997,"lng":"135.864651"},{"name":"彦根","id":78,"lat":35.272584,"lng":"136.263453"},{"name":"京都","id":79,"lat":34.985705,"lng":"135.758228"},{"name":"舞鶴","id":80,"lat":35.460344,"lng":"135.354936"},{"name":"大阪","id":81,"lat":34.702398,"lng":"135.495188"},{"name":"神戸","id":82,"lat":34.679453,"lng":"135.178221"},{"name":"豊岡","id":83,"lat":35.544161,"lng":"134.813485"},{"name":"奈良","id":84,"lat":34.680482,"lng":"135.818935"},{"name":"風屋","id":85,"lat":34.047472,"lng":"135.784115"},{"name":"和歌山","id":86,"lat":34.232436,"lng":"135.191454"},{"name":"潮岬","id":87,"lat":33.449129,"lng":"135.764552"},{"name":"岡山","id":88,"lat":34.666572,"lng":"133.918552"},{"name":"津山","id":89,"lat":35.054511,"lng":"134.003477"},{"name":"広島","id":90,"lat":34.397446,"lng":"132.475593"},{"name":"庄原","id":91,"lat":34.894945,"lng":"133.068744"},{"name":"松江","id":92,"lat":35.463947,"lng":"133.063871"},{"name":"浜田","id":93,"lat":34.902683,"lng":"132.088588"},{"name":"西郷","id":94,"lat":37.136373,"lng":"140.154844"},{"name":"鳥取","id":95,"lat":35.493953,"lng":"134.225901"},{"name":"米子","id":96,"lat":35.42327,"lng":"133.336570"},{"name":"下関","id":97,"lat":33.950306,"lng":"130.923038"},{"name":"山口","id":98,"lat":34.076294,"lng":"131.518159"},{"name":"柳井","id":99,"lat":33.965728,"lng":"132.105988"},{"name":"萩","id":100,"lat":34.393845,"lng":"131.401210"},{"name":"徳島","id":101,"lat":34.074572,"lng":"134.551391"},{"name":"日和佐","id":102,"lat":33.728954,"lng":"134.530603"},{"name":"高松","id":103,"lat":34.350754,"lng":"134.046821"},{"name":"新居浜","id":105,"lat":33.948124,"lng":"133.294761"},{"name":"宇和島","id":106,"lat":33.225774,"lng":"132.567460"},{"name":"高知","id":107,"lat":33.566758,"lng":"133.543522"},{"name":"室戸","id":108,"lat":33.315803,"lng":"134.144201"},{"name":"福岡","id":110,"lat":33.611051,"lng":"130.596075"},{"name":"八幡","id":111,"lat":34.86637,"lng":"135.706547"},{"name":"飯塚","id":112,"lat":33.628487,"lng":"130.689545"},{"name":"久留米","id":113,"lat":33.319778,"lng":"130.501408"},{"name":"大分","id":114,"lat":33.232794,"lng":"131.606595"},{"name":"中津","id":115,"lat":34.710241,"lng":"135.494127"},{"name":"日田","id":116,"lat":33.317014,"lng":"130.938786"},{"name":"佐伯","id":117,"lat":32.972521,"lng":"131.901857"},{"name":"長崎","id":118,"lat":32.753085,"lng":"129.870515"},{"name":"佐世保","id":119,"lat":33.163828,"lng":"129.726415"},{"name":"福江","id":121,"lat":35.146359,"lng":"136.912920"},{"name":"佐賀","id":122,"lat":33.264212,"lng":"130.297608"},{"name":"伊万里","id":123,"lat":33.271862,"lng":"129.876344"},{"name":"熊本","id":124,"lat":32.789207,"lng":"130.688499"},{"name":"阿蘇乙姫","id":125,"lat":32.939378,"lng":"131.041466"},{"name":"牛深","id":126,"lat":32.216576,"lng":"130.033125"},{"name":"人吉","id":127,"lat":32.216142,"lng":"130.753797"},{"name":"宮崎","id":128,"lat":31.917028,"lng":"131.433897"},{"name":"延岡","id":129,"lat":32.589944,"lng":"131.672442"},{"name":"都城","id":130,"lat":31.73657,"lng":"131.073992"},{"name":"高千穂","id":131,"lat":32.714701,"lng":"131.306448"},{"name":"鹿児島","id":132,"lat":31.602098,"lng":"130.564112"},{"name":"鹿屋","id":133,"lat":31.385255,"lng":"130.849934"},{"name":"名瀬","id":135,"lat":28.381751,"lng":"129.498848"},{"name":"那覇","id":136,"lat":26.213173,"lng":"127.689800"},{"name":"名護","id":137,"lat":26.596899,"lng":"127.991048"},{"name":"久米島","id":138,"lat":26.345762,"lng":"126.772677"},{"name":"宮古島","id":140,"lat":24.793269,"lng":"125.292911"}]

function latlngToID( pt ) {
  var mi = 0;
  var md = 40000000;
  for(var i=0; i!=db.length; ++i) {
    var dist = pt.distanceFrom( new GLatLng(db[i].lat, db[i].lng) );
    if( dist < md ) {
       md = dist;
       mi = i;
    }
  }
  return db[mi].id;
}


  // ユーティリティ：小数点以下3桁で切り捨て
  function shortForm(x) {
    return Math.floor(x*1000)/1000;
  }
  // ユーティリティ：小数点以下1桁で切り捨て
  function shortForm10(x) {
    return Math.floor(x*10)/10;
  }

//□マウスホールによるズーム処理
function mouseWheelZooming( event ){
//マウスホイールの上／下の取得と、スクロールのキャンセル
if( navigator.userAgent.match( "MSIE" ) ){ var delta = event.wheelDelta; event.returnValue = false; } //IE
if( navigator.userAgent.match( "Gecko" ) ){ var delta = event.detail * -1; event.preventDefault(); } //Gecko
if( navigator.userAgent.match( "Safari" ) ){ var delta = event.wheelDelta; event.returnValue = false; } //Safari

//ズーム処理
map.setZoom( map.getZoom() + ( delta < 0 ? -1 : 1 ) );
}
