/* Javascript for SLTc-meeting website
 *  - route tracer, Powered by Google maps.
 * meeting.js (c) 2008 SLTc / ISAKA Yoji, Corydoras softwares.
 *
 * Notes:
 *	Require to include Google maps before load it. ex:
 *	<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjqEneKF_rpxyATeoPzspeRQIDBn8Kti0zhn2o8h6gzJAfmL0qhRDzDLYZp7oxNXyz-XbjnflmyPw5A" type="text/javascript"></script>
 *
 *[sltc.jp]
 * ABQIAAAAjqEneKF_rpxyATeoPzspeRQIDBn8Kti0zhn2o8h6gzJAfmL0qhRDzDLYZp7oxNXyz-XbjnflmyPw5A
 * http://maps.google.com/maps/api_signup?url=http%3A%2F%2Fsltc.jp%2F
 * [wiki.sltc.jp]
 * ABQIAAAAjqEneKF_rpxyATeoPzspeRRs35uQudkdyUIb8NkVZeirAmRl3BQqivLX12F6h22F2bvfsE-jBk321g
 * http://maps.google.com/maps/api_signup?url=http%3A%2F%2Fwiki.sltc.jp%2F
 *
 * History:
 *  2008.12.17
 *	divide from meeting.html.
 *  2008..
 *	1st release.
 */

// 共通変数 ----------------------------------------------------------
var	nl =  35.599600;	// 中心緯度（北緯）
var	el = 139.610000;	// 中心経度（東経）
var	zo = 17;	// 縮尺
var	oMap;
var	oStView, oSVOverlay;
var	oLastOverlay = new Array();

var	_mSXCarEnabled = true;

// 座標等の定義 ------------------------------------------------------
var	aMapStart = new Array(5);
var	aMapPoints = new Array(5);
// var	aMapMarkers = new Array(5);
// var	aMapMessages = new Array(5);
// 武蔵溝ノ口駅→高津区役所
aMapStart[0] = "南武線改札口";
aMapPoints[0] = [
	'35.599160', '139.611000',
	'35.598970', '139.610750',
	'35.598960', '139.610260',
	'35.599150', '139.609960',
	'35.598940', '139.609640',
	'35.599180', '139.609170',
	'35.599040', '139.609110',
	'35.599570', '139.608250',
	'35.599450', '139.608150'
];

// 溝の口駅→高津区役所
aMapStart[1] = "東急南口改札口";
aMapPoints[1] = [
	'35.599440', '139.609880',
	'35.599380', '139.609830',
	'35.599460', '139.609170',
	'35.599130', '139.608990',
	'35.599570', '139.608250',
	'35.599450', '139.608150'
];

// 高津区役所前バス停→高津区役所
aMapStart[2] = "高津区役所前バス停";
aMapPoints[2] = [
	'35.600186', '139.607263',
	'35.599918', '139.607989',
	'35.599780', '139.607893',
	'35.599570', '139.608250',
	'35.599450', '139.608150'
];

// 溝口駅南口バス停→高津区役所
aMapStart[3] = "「溝口駅南口」降車バス停";
aMapPoints[3] = [
	'35.598419', '139.610234',
	'35.599570', '139.608250',
	'35.599450', '139.608150'
];

// 北口降車バス停→高津区役所
aMapStart[4] = "「溝口駅(前)」降車バス停";
aMapPoints[4] = [
	'35.599130', '139.611480',
	'35.599100', '139.611350',
	'35.599287', '139.611130'
].concat(aMapPoints[0]);


// Load Gmap ---------------------------------------------------------
function gmapLoad() {
  if (GBrowserIsCompatible()) {
	oMap = new GMap2(document.getElementById("map"));
	oMap.setCenter(new GLatLng(nl, el), zo);
	oMap.addControl(new GLargeMapControl());
	oMap.addControl(new GMapTypeControl());
	oMap.addControl(new GScaleControl());
  }
}

// 与えられた座標に沿って線を引く ------------------------------------
function gmapDrawline(r, c, t) {
	var	i;
	// Google Maps に対応？
	if(!GBrowserIsCompatible())
		return;
	// 前回描いた線などがある場合は削除する
//	if(typeof oLastOverlay != 'undefined')
//		oMap.removeOverlay(oLastOverlay);
	for(i=oLastOverlay.length; i>0; i--) {
		oMap.removeOverlay(oLastOverlay[i-1]);
		delete oLastOverlay[i-1];
	}
	// 引数の既定値
	if(!c)	// 規定の色
		c = "#000000";
	if(!t)	// 規定の太さ
		t = 1;

	// 描画点の構造体を生成
	var	spt = new Array();
	for(i=0; i*2 < aMapPoints[r].length; i++) {
		spt.push(new GLatLng(aMapPoints[r][i*2], aMapPoints[r][i*2+1]));
	}
	// 線の構築
	oLastOverlay[0] = new GPolyline(spt, c, t);
	// 線の描画
	oMap.addOverlay(oLastOverlay[0]);
	// 距離表示を追加
	var	f = Math.round(oLastOverlay[0].getLength() / 50) * 50;
	var	m = Math.round(oLastOverlay[0].getLength() / 70);
	var	s = aMapStart[r] + "から建物入口まで<br />およそ " + f + " メートル、徒歩約 " + m + " 分です。";
	var	c = aMapPoints[r].length - 1;
	oMap.openInfoWindowHtml(new GLatLng(aMapPoints[r][c-1], aMapPoints[r][c]), s);

	// 印刷用 style の変更（配列+1は自転車欄用）
	for(i=0; i<aMapPoints.length+1; i++) {
		if(i == r) {
			self.document.getElementById("guidetitle_" + i).className = "";
			self.document.getElementById("guidedesc_" + i).className = "";
		} else {
			self.document.getElementById("guidetitle_" + i).className = "noprint";
			self.document.getElementById("guidedesc_" + i).className = "noprint";
		}
	}
}

// Error if no flash (for using StreetView) --------------------------
function fhNoFlash(err) {
  if (err == FLASH_UNAVAILABLE)
	alert("Street View をご利用の際は Flash 対応の Web ブラウザが必要です。");
}

// StreetView --------------------------------------------------------
function gmapStView(check, target) {
  if(document.getElementById(check).checked) {
	document.getElementById(target).style.display = 'block';
	oStView = new GStreetviewPanorama(document.getElementById(target));
	GEvent.addListener(oStView, "error", fhNoFlash); 
	GEvent.addListener(oMap, "click", function(overlay,latlng) {
		oStView.setLocationAndPOV(latlng);
	});
	oMap.setCenter(new GLatLng(nl, el), zo);
	oSVOverlay = new GStreetviewOverlay();
	oMap.addOverlay(oSVOverlay);
  } else {
	oMap.removeOverlay(oSVOverlay);
	document.getElementById(target).style.display = 'none';
  }
}

