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(39.303186, 141.144791);
	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.914519,141.33421);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/nagasawa-mokuzai/" target="_blank">永沢木材（株）</a></p><p class="gMapAdd">一関市千厩町千厩字摩王１２-１</p><p class="gMapTel">0191（52）5111</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(39.338014,141.526078);
	html = '<p class="gMapCom"><a href="http://tateisi.jp/" target="_blank">（株）立石工務店</a></p><p class="gMapAdd">遠野市早瀬町２-７-３１</p><p class="gMapTel">0198（63）1731</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(39.11957,141.120274);
	html = '<p class="gMapCom"><a href="http://matumoto-3.ftw.jp/" target="_blank">（株）マツモト</a></p><p class="gMapAdd">奥州市胆沢区小山字北笹森１２８-７</p><p class="gMapTel">0197（47）2225</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(39.447402,141.112505);
	html = '<p class="gMapCom">（株）坂田建材</p><p class="gMapAdd">花巻市卸町１６</p><p class="gMapTel">0198（26）4300</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(39.730971,141.094697);
	html = '<p class="gMapCom"><a href="http://www.daikyo-home.jp/" target="_blank">（株）大共ホーム</a></p><p class="gMapAdd">岩手郡滝沢村鵜飼下高柳１１-１</p><p class="gMapTel">019（687）1541</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(39.627249,141.961183);
	html = '<p class="gMapCom"><a href="http://www.nanyo.ecweb.jp/" target="_blank">南洋建材（株）</a></p><p class="gMapAdd">宮古市磯鶏沖15-10</p><p class="gMapTel">0193（62）1470</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.990484,141.116269);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/hiraizumi-seizaisho/" target="_blank">（有）平泉製材所</a></p><p class="gMapAdd">西磐井郡平泉町平泉字鈴沢３１</p><p class="gMapTel">0191（46）2700</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.94039, 141.300465);
	html = '<p class="gMapCom"><a href="http://www.simizu-k.com/" target="_blank">（有）清水建築</a></p><p class="gMapAdd">一関市千厩町磐清水字峯山３４</p><p class="gMapTel">0191（53）2766</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.840543,141.307938);
	html = '<p class="gMapCom"><a href="http://www.e-house.co.jp/idai/" target="_blank">伊大建築</p><p class="gMapAdd">東磐井郡藤沢町黄海字八景下116</p><p class="gMapTel">0191（63）3826</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.949022,141.413146);
	html = '<p class="gMapCom"><a href="http://www9.ocn.ne.jp/~takara/">（有）タカラ住建</a></p><p class="gMapAdd">一関市千厩町奥玉字萱刈場63-4</p><p class="gMapTel">0191（56）2202</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(38.807535,141.262631);
	html = '<p class="gMapCom"><a href="http://www.tohoku-h.co.jp/" target="_blank">東北ホーム（株）</a></p><p class="gMapAdd">東磐井郡藤沢町黄海山谷41</p><p class="gMapTel">0191（63）3583</p>';
	map.addOverlay(createMarker(point, html, icon));

	point = new GLatLng(39.748365,141.150289);
	html = '<p class="gMapCom">（株）工藤技建</p><p class="gMapAdd">盛岡市上田字岩脇１番地１０</p><p class="gMapTel">019（662）8230</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);
				}
			}
		);
	}
}

