/**
 * よかNavi - ターゲット座標指定方式 Google Map
 * 
 * @package yokanavi
 * @author Hideyuki Kagasawa <kagasawa@web-prom.net>
 * @copyright Copyright (C) 2008 Fusic Co., Ltd , All Rights Reserved.
 */

 // GoogleMap本体
 var objGmap;

 /**
	 * 読み込み完了時に実行
	 */
	 window.onload = function() {
		 // Gマップオブジェクトを生成
		 objGmap = new targetGoogleMap('map');

		 // 地図移動イベントをリスナに追加
		 GEvent.addListener(objGmap.map, "move", function() { 
			 var objPoint = objGmap.map.getCenterLatLng();

			 // ドラッグするとクロスターゲットがズレるので、一回消して書き直す
			 objGmap.map.clearOverlays();
			 objGmap.marker = new GMarker(objPoint, objGmap.icon);
			 objGmap.map.addOverlay(objGmap.marker);

			 // 十字アイコンが示す座標を表示
             //			document.getElementById('datalatlon').innerHTML=objGmap.map.getCenterLatLng() 

			 // 十字アイコンが示す座標を保管
			 $(datalatlonX).value = objPoint.x;
			 $(datalatlonY).value = objPoint.y;
		 });
		 
		 // 検索ボタンのイベントを割当
         if( $(btnGmapSearch) ){
		     $(btnGmapSearch).onclick = function() {
			     // GClientGeocoderを初期化
			     var geocoder = new GClientGeocoder();
			     // 検索対象の住所文字列を取得
			     var addr = $(searchAddr).value;
	             
			     if ( addr != '' ) {
				     if (geocoder) {
					     geocoder.getLatLng(
						     addr,
						     function(point) {
							     if (!point) {
								     alert(addr + " not found");
								     return false;
							     } else {
								     objGmap.map.setCenter(point, 15);
                                     /*
								// マーカー表示
								var marker = new GMarker(point);
								map.addOverlay(marker);
								marker.openInfoWindowHtml(addr);
*/
							     }
						     }
					     );
				     }
			     }
		     }
         }

	 }
	 
	 /**
	 * コンストラクタ
	 */
	 function targetGoogleMap (mapDivId) {

		 // 開始座標
		 var init_x = defaltX;
		 var init_y = defaltY;

		 // 座標指定がある場合は上書きする
		 if ( x != 0 ) {
			 init_x = x;
		 }
		 if ( y != 0 ) {
			 init_y = y;
		 }

		 // Gマップオブジェクトを生成
		 this.map = new GMap($(mapDivId));
		 this.map.centerAndZoom(new GPoint(init_x, init_y), 2);
		 this.map.addControl(new GLargeMapControl());
		 this.map.addControl(new GMapTypeControl());

		 // 十字アイコン作成
		 this.icon = new GIcon();
		 this.icon.image = crossIconPath;
		 this.icon.iconSize = new GSize(100, 100);
		 this.icon.iconAnchor = new GPoint(50, 50);
		 this.marker = new GMarker(this.map.getCenterLatLng(), this.icon);
		 this.map.addOverlay(this.marker);
	 }


