var map;

$(window).ready(function() {
	var obj = document.getElementById("map");

	if (obj != null && GBrowserIsCompatible()) {
		map = new GMap2(obj);
		map.setCenter(new GLatLng(38.67431, 135.69082), 4);

		// GClientGeocoderを初期化
		map.addControl(new GSmallMapControl());
		map.addControl(new GMapTypeControl());
		map.enableScrollWheelZoom();
	}
});

var structMarkerItems = new Array(); // GoogleMapに追加されたmarkerリスト

function StructMarker() {
	var marker = null; // マーカー
	var point = null; // 座標
	var html = null; // 店舗情報HTML
}

function addMarker(shopInfoUrl, shopId, shopName, address, tel, openTime,
		closes, x, y, isShow) {
		var point = new GLatLng(y, x);	
		var marker = new GMarker(point);
		map.addOverlay(marker);

		var myHtml = "RinRin" + shopName + "<br/>住所：" + address
				+ "<br/>tel:" + tel + "<br/>営業時間:" + openTime
				+ "<br/>定休日:" + closes + "<br/><a href='" + shopInfoUrl
				+ "'>店舗詳細へ</a>";
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(myHtml);
		});

		if(isShow) { // 追加後すぐ表示
			map.setCenter(point, 12);
			marker.openInfoWindowHtml(myHtml);
		}
		
		structMarkerItems[shopId] = new StructMarker();
		structMarkerItems[shopId].marker = marker;
		structMarkerItems[shopId].point = point;
		structMarkerItems[shopId].html = myHtml;
}

function showMarker(shopId) {
	var structMarker = structMarkerItems[shopId];
	if (structMarker == null) {
		alert("登録された住所が不正です。");
	} else {
		map.setZoom(12);
		structMarker.marker.openInfoWindowHtml(structMarker.html);
	}
}

function changeContent(ele, url, shopId, blogTermId, nowPage, isBlogTerm) {
	$.ajax({
		type : "POST",
		url : url,
		dataType : 'html',
		data : "&shopId=" + shopId + "&blogTermId=" + blogTermId + "&nowPage="
				+ nowPage,
		success : function(html) {
			$("#l_contentList").html(html);

			if (isBlogTerm) {
				$(".c_blogTerm").each(function() {
					$(this).removeClass("current");
				});

				$(ele).addClass("current");
			}
		}
	});
	return false;
}
