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(35.441932, 133.754111);
	map.setCenter(center, 9);

	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(35.473186,134.224904);
	html = '<p class="gMapCom"><a href="http://www.kyudai.co.jp/" target="_blank">久大建材（株）</a></p><p class="gMapAdd">鳥取市叶１１０-１</p><p class="gMapTel">0857（53）0920</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(35.510578,134.196856);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/koyo/" target="_blank">（株）興洋工務店</a></p><p class="gMapAdd">鳥取市岩吉１３０-３</p><p class="gMapTel">0857（28）2244</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(35.509737,134.217921);
	html = '<p class="gMapCom"><a href="http://www.yamata.co.jp/" target="_blank">（有）ヤマタホーム</a></p><p class="gMapAdd">鳥取市西品治６００</p><p class="gMapTel">0857（27）7060</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(35.515459,133.625534);
	html = '<p class="gMapCom">（有）高尾材木店</p><p class="gMapAdd">東伯郡琴浦町八幡</p><p class="gMapTel">0858（55）0610</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(35.488377,133.750506);
	html = '<p class="gMapCom">（有）坂本工務店</p><p class="gMapAdd">東伯郡北栄町由良宿８３０-１７</p><p class="gMapTel">0858（49）6280</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(35.454856,133.422775);
	html = '<p class="gMapCom">（有）橋本工務店</p><p class="gMapAdd">米子市淀江町西原１１４５-１</p><p class="gMapTel">0859（56）6160</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(35.453483,133.293866);
	html = '<p class="gMapCom">（有）はまだ工務店</p><p class="gMapAdd">米子市彦名町２５３８-３</p><p class="gMapTel">0859（29）7287</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);
				}
			}
		);
	}
}

