var TenpoInfo = function(i, n, s, y, x, a, p, c) {
	this.id = String(i);
	this.name = String(n);
	this.lat = Number(y);
	this.lng = Number(x);
	this.address = String(a);
	this.spell = String(s);
	this.parking = p;
	this.closed = c;
}

var tenpoList = new Array();
tenpoList.push(null);
tenpoList.push(new TenpoInfo("8men001", "藍華",			"あいか",			35.662875, 139.333299, "八王子市元横山町2-22-3", false, false));
tenpoList.push(new TenpoInfo("8men002", "青葉",			"あおば",			35.658273, 139.328544, "八王子市南新町 15-1", false, false));
tenpoList.push(new TenpoInfo("8men003", "いち",			"いち",				35.65287,  139.338269, "八王子市下柚木 531-28", false, false));
tenpoList.push(new TenpoInfo("8men004", "一閑人",		"いっかんじん",		35.680682, 139.285387, "八王子市上壱分方町 233", false, false));
tenpoList.push(new TenpoInfo("8men005", "一麺",			"いちめん",			35.657675, 139.335477, "八王子市三崎町 5-13", false, false));

tenpoList.push(new TenpoInfo("8men006", "一陽来福",		"いちようらいふく",	35.680642, 139.3074,   "八王子市楢原町 472-1", false, false));
tenpoList.push(new TenpoInfo("8men007", "いっぱしや",	"いっぱしや",		35.679634, 139.36647,  "八王子市石川町 1207", false, false));
tenpoList.push(new TenpoInfo("8men008", "壱発ラーメン",	"いっぱつらーめん",	35.65214,  139.32672,  "八王子市台町 1-17-8", false, false));
tenpoList.push(new TenpoInfo("8men009", "江川亭",		"えがわてい",		35.685187, 139.370839, "八王子市小宮町 1111-1", false, false));
tenpoList.push(new TenpoInfo("8men010", "えびす丸",		"えびすまる",		35.639147, 139.339854, "八王子市片倉町 2348", false, false));

tenpoList.push(new TenpoInfo("8men011", "おがわ屋",		"おがわや",			35.666312, 139.349974, "八王子市大和田町 5-27-11", false, false));
tenpoList.push(new TenpoInfo("8men012", "楓",			"かえで",			35.663681, 139.353005, "八王子市大和田町 5-10-1", false, false));
tenpoList.push(new TenpoInfo("8men013", "吾衛門",		"ごえもん",			35.65741,  139.311069, "八王子市千人町3-3-3", false, false));
tenpoList.push(new TenpoInfo("8men014", "二郎（法政）",	"じろうほうせい",	35.629407, 139.310246, "八王子市寺田町233-2", false, false));
tenpoList.push(new TenpoInfo("8men015", "二郎（野猿）",	"じろうやえん",		35.629782, 139.379798, "八王子市下柚木321-1", false, false));

tenpoList.push(new TenpoInfo("8men016", "竹の家",		"たけのいえ",		35.658212, 139.336714, "八王子市中町4-2", false, false));
tenpoList.push(new TenpoInfo("8men017", "多摩利屋",		"たまりや",			35.639001, 139.341206, "八王子市片倉町722-1", false, false));
tenpoList.push(new TenpoInfo("8men018", "樽座",			"たるざ",			35.655779, 139.348985, "八王子市明神町2-1-9", false, false));
tenpoList.push(new TenpoInfo("8men019", "タンタン",		"たんたん",			35.651898, 139.340171, "八王子市子安町1-30-6", false, false));
tenpoList.push(new TenpoInfo("8men020", "でうら",		"でうら",			35.65214,  139.328691, "八王子市台町 1-6-12", false, false));

tenpoList.push(new TenpoInfo("8men021", "でんでん",		"でんでん",			35.651619, 139.344363, "八王子市子安町 1-37-6", false, false));
tenpoList.push(new TenpoInfo("8men022", "トモエ",		"ともえ",			35.648936, 139.307461, "八王子市散田町5-18-13", false, false));
tenpoList.push(new TenpoInfo("8men023", "初富士",		"はつふじ",			35.669715, 139.318163, "八王子市中野上町 4-17-4", false, false));
tenpoList.push(new TenpoInfo("8men024", "弘富",			"ひろとみ",			35.655047, 139.344082, "八王子市明神町 3-11", false, false));
tenpoList.push(new TenpoInfo("8men025", "敏々亭",		"びんびんてい",		35.656523, 139.315851, "八王子市台町 4-40-8", false, false));

tenpoList.push(new TenpoInfo("8men026", "星の家",		"ほしのいえ",		35.668061, 139.329107, "八王子市中野上町 1-5-12", false, false));
tenpoList.push(new TenpoInfo("8men027", "宮城",			"みやぎ",			35.65287,  139.338269, "八王子市子安町 4-26-6", false, false));
tenpoList.push(new TenpoInfo("8men028", "みんみん",		"みんみん",			35.680479, 139.307038, "八王子市楢原町 437-1", false, false));
tenpoList.push(new TenpoInfo("8men029", "麺くい亭",		"めんくいてい",		35.621782, 139.39043,  "八王子市松木30-13 リバーサイドジュネス2-103", false, false));
tenpoList.push(new TenpoInfo("8men030", "麺龍",			"めんりゅう",		35.669051, 139.353225, "八王子市大谷町 48-9", false, false));

tenpoList.push(new TenpoInfo("8men031", "分田上",		"わけたがみ",		35.629812, 139.379693, "八王子市下柚木 321-1", false, false));

//tenpoList.push(new TenpoInfo("店舗ID", "店名",		"ふりがな",		緯度, 経度, 住所, 駐車場, 閉店しているか));

var map;
var putGMap = function(id) {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));

		var n;
		for (n = 1; n<tenpoList.length; n++) {
			if(Number(tenpoList[n].id) == Number(id)) break;
		}
		
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(tenpoList[n].lat, tenpoList[n].lng), 16);
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
		
		var arrowIcon = new GIcon();
		arrowIcon.image = "http://www.google.com/intl/ja_ALL/mapfiles/arrow.png";
		arrowIcon.iconSize = new GSize(39, 34);
		arrowIcon.iconAnchor = new GPoint(11, 34);
		
		map.addOverlay(new GMarker(new GLatLng(tenpoList[n].lat, tenpoList[n].lng), arrowIcon));
	}
}

var showGMap = function(id) {
	if(!map) putGMap(id);
	document.getElementById("map").style.visibility = "visible";	
}

var hiddenGMap = function() {
	document.getElementById("map").style.visibility = "hidden";
}

var createMarker = function (tenpo, html) {
	var marker = new GMarker(new GLatLng(tenpo.lat, tenpo.lng));
	var clickAction = function () { marker.openInfoWindowHtml(html); }
	GEvent.addListener(marker, "click", clickAction);
	
	tenpo.marker = marker;
	tenpo.clickAction = clickAction;
		
	return marker;
}

var putRahmenMap = function () {
	if (GBrowserIsCompatible() && tenpoList) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		map.setCenter(new GLatLng(35.655546, 139.339012), 13);
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();
		
		var markerList = Array();
		for (var i=1; i<tenpoList.length; i++) {
			var html = '<div style="width: 240px; height: 120px;"><h4><a href="shop_shousai.html?store_id=' + tenpoList[i].id + '">' + tenpoList[i].name + '</a></h4>'
				+ '<a href="shop_shousai.html?store_id=' + tenpoList[i].id + '">'
				+ '<img class="map_img" alt="' + tenpoList[i].name + '" src="include/img.php?type=store&store_id=' + tenpoList[i].id + '&number=1" width="100"></img></a>';

			if (tenpoList[i].address) {
				html += tenpoList[i].address;
			}

			if (tenpoList[i].closed)
				html += '</div><p style="color: #ff3333; font-weight: bold;">閉店</p>';
			else
				html += '</div>';
			
			var marker = createMarker(tenpoList[i], html);
			map.addOverlay(marker);
		}		
	}
}

