/**
 * @author ability
 */
var map;
var gmarker = new Array();


$(document).ready(function(){
	// Google Map 表示
	map = new GMap(document.getElementById("google_map"));
	//map.addControl(new GLargeMapControl());
	map.centerAndZoom(new GPoint(133.930206, 34.206124), 8);
	//map.enableScrollWheelZoom();
	
	disMap();
	
});

$(function(){
	
	// lightpop
	$(".besuka a").lightpop();
	
	// タブ操作
	$(".tabmenu ul li a").click(function(){
		map.clearOverlays();
		$(this).toggleClass("hover");
		disMap();
	});
	
	// ズームイン・ズームアウト
	$("p.zoomin img").click(function(){
		var size = map.getZoomLevel();
		map.zoomTo(size-1)
	});
	$("p.zoomout img").click(function(){
		var size = map.getZoomLevel();
		map.zoomTo(size+1)
	});
	
	// hoverで色変更
	$("#contents .list").hover(
		function(){
			$(this).css("background","#e2eff1");
		},
		function(){
			$(this).css("background", "#fff");
		}
	);
	$("#contents .info .list").hover(
		function(){
			$(this).css("background", "#fff");
		},
		function(){
			$(this).css("background", "#fff");
		}
	);
	
});

function disMap(){
	// googlemap表示切替
	$(".tabmenu ul li a").each(function(index){
		gmarker[index] = new Array();
		if($(this).is(".hover")){
			setPoint(index);
		}
	});
}

function setPoint(param){
	
	var point = new Array();
	
	//アイコン画像の指定
	var iconSet = new GIcon();
	//iconSet.shadow           = "http://maps.google.co.jp/mapfiles/ms/icons/msmarker.shadow.png"; //影画像パス
	iconSet.iconSize         = new GSize(43, 33); //アイコンサイズ
	//iconSet.shadowSize       = new GSize(59, 32); //影サイズ
	iconSet.iconAnchor       = new GPoint(20, 0); //アイコンの表示開始位置（0,0）は左上角から
	iconSet.infoWindowAnchor = new GPoint(15, 20); //情報ウィンドウの表示開始位置
	iconSet.infoShadowAnchor = new GPoint(15, 20); //情報ウィンドウの影の表示開始位置
	
	for(cntGenre = 0; cntGenre < 9; cntGenre++){
		if(param != cntGenre){
			continue;
		}
		iconSet.image = "./images/top/g_icn"+cntGenre+".png"; //アイコン画像パス
		for(cntSpot = 0; cntSpot < code_x[cntGenre].length; cntSpot++){
			point[cntSpot] = new GLatLng(code_x[cntGenre][cntSpot], code_y[cntGenre][cntSpot]);
		}
	}
	
	for(var i = 0; i < point.length; i++){
		var marker = createMarker(point[i], html[param][i], iconSet, param, i);
		gmarker[param][i] = marker;
		map.addOverlay(marker);
	}
}

function createMarker(point, htmlData ,iconSet, x, y){
	var marker = new GMarker(point,iconSet);
	// クリックしたマーカーに該当する情報を表示
	GEvent.addListener(marker, 'click', function(){
		myclick(x, y, "marker");
	});
	return marker;
}

function myclick(x, y, mode) {
	map.clearOverlays();
	if(mode == "click"){
		$(".tabmenu ul .li_05 a").addClass("hover");
		map.setCenter(new GLatLng(code_x[x][y], code_y[x][y]), 16);
	}
	disMap();
	setTimeout('$("div.accom_info").fadeIn()', 1*250);
	$('div.accom_info').html(html[x][y]);
	
	// アイコンの表示
	// アイコン画像（オーバー）の指定
	var iconSetOver = new GIcon();
	iconSetOver.image = "./images/top/g_icn"+x+"_over.png"; //アイコン画像（オーバー）パス
	iconSetOver.iconSize         = new GSize(43, 33); //アイコンサイズ
	iconSetOver.iconAnchor       = new GPoint(20, 0); //アイコンの表示開始位置（0,0）は左上角から
	
	markerOver = new GMarker(new GLatLng(code_x[x][y], code_y[x][y]), iconSetOver);
	
	map.removeOverlay(markerOver);
	map.addOverlay(markerOver);
}

function winClose(){
	$("div.accom_info").fadeOut();
}

