/**
 * 観光案内一覧
 */
var map;
var html;
var gmarker;

// 初期表示
$('document').ready(function(){
	// googlemapを表示
	map = new GMap( document.getElementById( "googlemap" ) );
	map.addControl( new GSmallMapControl() );
	map.centerAndZoom( new GPoint(138.792422, 34.912516), 5 );
	
	// 観光案内一覧を取得
	$.ajax({
		type: "POST",
		url: "./getMapList.php",
		success: function( mapData ){
			if( mapData == "\n" )
			{
				// 取得情報が無ければ終了
				return;
			}
			// 座標とhtmlの分割
			mapData = mapData.split( "\n" );
			
			// 1つ分に分割
			mapPoint = mapData[0].split( "\t" );
			mapHtml = mapData[1].split( "\t" );
			
			// マップhtmlを配列に追加
			html = mapHtml;
			gmarker = new Array( mapPoint.length );
			
			// 座標の登録
			for( nCnt = 0; nCnt < mapPoint.length; nCnt++)
			{
				// 座標の分割
				point = mapPoint[ nCnt ].split( ":" );
				gmarker[ nCnt ] = createMarker( point[0], point[1], nCnt );
				map.addOverlay( gmarker[ nCnt ] );
			}
			
		},
		error: function(){
			alert("マップ情報を取得できませんでした。");
		}
	});
});

function createMarker( point01, point02, value )
{
	var icon = new GIcon();
	icon.image = "../stay/images/list/mapicn_"+(value+1)+".png";
	icon.shadow = "../stay/images/list/shadow.png"; //影画像パス
	icon.iconSize = new GSize( 32, 39 );
	icon.iconAnchor = new GPoint( 52, 39 );
	icon.iconAnchor       = new GPoint(16, 39); //アイコンの表示開始位置（0,0）は左上角から
	icon.infoWindowAnchor = new GPoint(25, 5); //情報ウィンドウの表示開始位置
	icon.infoShadowAnchor = new GPoint(25, 5); //情報ウィンドウの影の表示開始位置
	var marker = new GMarker( new GPoint( point01, point02 ), icon );
	GEvent.addListener( marker, 'click', function(){
		map.centerAndZoom( new GPoint( point01, point02 ), 1 );
		marker.openInfoWindowHtml( html[ value ] );
	} );
	return marker;
}

function myclick( point_x, point_y ,value )
{
	map.centerAndZoom( new GPoint( point_x, point_y ), 1 );
	gmarker[ value ].openInfoWindowHtml( html[ value ] );
}

