var map = null;
var geocoder = null;
var marker2 = null;

function createMarker(point, html, icon){
	var marker = new GMarker(point, icon);
	GEvent.addListener(marker, "mouseover", function() {
		marker.openInfoWindowHtml(html);
		});
	return marker;
	}

function load() {
	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("map"));
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.enableContinuousZoom();
		map.enableDoubleClickZoom();

	// GClientGeocoderを初期化
	geocoder = new GClientGeocoder();
	
	var center = new GLatLng(38.549909, 140.327339);
	map.setCenter(center, 8);

	icon = new GIcon();
	icon.image = '../img/marker.gif';
	icon.iconSize = new GSize( 25, 33 );	// 画像の大きさ
	icon.shadow = '../img/marker_shadow.png';
	icon.shadowSize = new GSize( 45, 29 );	// 影画像の大きさ
	icon.iconAnchor = new GPoint( 12, 32 );	// 画像の「基準点」
	icon.infoWindowAnchor = new GPoint( 12, 32 );	// 情報ウィンドウの基準点	
	var html; 
	var point;


	point = new GLatLng(38.403233,140.27796);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/kikuchi-komuten/" target="_blank">（有）菊地工務店</a></p><p class="gMapAdd">寒河江市字上河原４３-１</p><p class="gMapTel">0237（86）8920</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.357902,140.27819);
	html = '<p class="gMapCom"><a href="http://www.takamoku.co.jp/" target="_blank">（株）高松木材</a></p><p class="gMapAdd">寒河江市大字島字島東８７</p><p class="gMapTel">0237（86）4175</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.246014,140.314593);
	html = '<p class="gMapCom"><a href="http://www.ichicom.co.jp/" target="_blank">（株）市村工務店</a></p><p class="gMapAdd">山形市久保田３丁目１１番１２号</p><p class="gMapTel">023（644）6878</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.961844,139.932782);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/abe-seizaisho/" target="_blank">（株）阿部製材所</a></p><p class="gMapAdd">酒田市市条横枕３６</p><p class="gMapTel">0234（64）2036</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.775381,140.295664);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/towahome/" target="_blank">（有）トーワホーム</a></p><p class="gMapAdd">新庄市桧町２６-５</p><p class="gMapTel">0233（23）1944</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.734688,140.27069);
	html = '<p class="gMapCom"><a href="http://www.yj-co.com/" target="_blank">（株）ヤマムラ</a></p><p class="gMapAdd">新庄市福田７１１-６</p><p class="gMapTel">0233-23-4313</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.576158,140.383369);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/takahashi-kenso/" target="_blank">高橋建創</a></p><p class="gMapAdd">北村山郡大石田町大字横山７５７</p><p class="gMapTel">0237（35）4251</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.760266,139.845545);
	html = '<p class="gMapCom"><a href="http://www.abeta.co.jp/index_g.htm" target="_blank">阿部多（株）</a></p><p class="gMapAdd">鶴岡市文下字沼田４４-１</p><p class="gMapTel">0235（24）3141</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.840746,139.903448);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/ku-kan/" target="_blank">風舎建築スタジオ<br>（有）空間工房</a></p><p class="gMapAdd">東田川郡庄内町余目字下梵天塚３５－９</p><p class="gMapTel">0234（42）3837</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.439859,140.385696);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/takaken/" target="_blank">高橋建設</a></p><p class="gMapAdd">東根市六田１－６－３０</p><p class="gMapTel">0237（42）3326</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.27205,140.339401);
	html = '<p class="gMapCom"><a href="http://www.shikinosumai.jp/" target="_blank">（株）四季の住まい</a></p><p class="gMapAdd">山形市銅町二丁目１３番１１号</p><p class="gMapTel">023(615)6161</p>';
	map.addOverlay(createMarker(point, html, icon));


	}
}


function showAddress(address) {
	if (geocoder) {
		geocoder.getLatLng(
		address,
			function(point) {
				if (!point) {
				alert(address + " not found");
				} else {
					if(marker2 != null){
					map.removeOverlay(marker2);
					}
				var icon = new GIcon();
				icon.image = "../img/aicon_map.gif";  //アイコン画
				icon.shadow = "../img/aicon_map.gif"; //影の画
				icon.iconSize = new GSize(36, 36);    //アイコンサイズ
				icon.shadowSize = new GSize(36, 36); //影のサイズ
				icon.iconAnchor = new GPoint(18, 36);
				icon.infoWindowAnchor = new GPoint(18, 0);
				var markeropts = new Object();
				markeropts.icon = icon;
				map.setCenter(point, 13);
				marker2 = new GMarker(point, icon);
				map.addOverlay(marker2);
				marker2.openInfoWindowHtml(address);
				}
			}
		);
	}
}

