
/* <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> */

// google map script---------------------------------------------------------------------------------

var aroundDefZoom = 12; //デフォルトズーム率
var aroundDefLat = 33.63891841350721; //デフォルト緯度
var aroundDefLng = 130.38745880126953; //デフォルト経度

function aroundLoadXML() {
	
	q = "?time=" + (new Date()).getTime();
	
	httpObj = aroundCreateXMLHttpRequest(aroundDisplayData);
	if (httpObj) {
		httpObj.open("GET","data.xml" + q);
		httpObj.send(null);
	}
	
}



function aroundCreateXMLHttpRequest(cbFunc) {
	var XMLhttpObject = null;
	try{
		XMLhttpObject = new XMLHttpRequest();
	}catch(e){
		try{
			XMLhttpObject = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				XMLhttpObject = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}
	if (XMLhttpObject) XMLhttpObject.onreadystatechange = cbFunc;
	return XMLhttpObject;
}



var aroundGmapObj;

var aroundArdAry = new Array();
var aroundLat = new Array();
var aroundLng = new Array();
var aroundTitle = new Array();
var aroundURL = new Array();
var aroundSummary = new Array();


function aroundDisplayData() {
	if ((httpObj.readyState == 4) && (httpObj.status == 200)) {
		xmlData = httpObj.responseXML;
		aroundArdAry = new Array();
		aroundLat = new Array();
		aroundLng = new Array();
		aroundTitle = new Array();
		aroundURL = new Array();
		aroundSummary = new Array();
		
		aroundArdAry = xmlData.getElementsByTagName("around");
		
		for(i=0; i < aroundArdAry.length; i++) {
			aroundLat[i] = aroundArdAry[i].getElementsByTagName("lat")[0].childNodes[0].nodeValue;
			aroundLng[i] = aroundArdAry[i].getElementsByTagName("lng")[0].childNodes[0].nodeValue;
			aroundTitle[i] = aroundArdAry[i].getElementsByTagName("title")[0].childNodes[0].nodeValue;
			aroundURL[i] = aroundArdAry[i].getElementsByTagName("url")[0].childNodes[0].nodeValue;
			aroundSummary[i] = aroundArdAry[i].getElementsByTagName("summary")[0].childNodes[0].nodeValue;
		}
		
		aroundGglMap();
	}
}





// google map 起動関数
function aroundGglMap() {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("around-map"));
		aroundGmapObj = map;
		
		map.addControl(new GLargeMapControl());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		
		var center = new GLatLng(aroundDefLat, aroundDefLng);
		map.setCenter(center, aroundDefZoom);
		
		/*map.enableContinuousZoom();
		map.enableDoubleClickZoom();*/
		
		for(i=0; i<aroundLat.length; i++) {
				points = new GLatLng(aroundLat[i], aroundLng[i]);
				map.addOverlay(aroundCreateMarker(points,aroundTitle[i],aroundURL[i],aroundSummary[i]));
		}
		
		txtLnks = $("around-txt").getElementsByClassName("gglmap");
		txtLnkLen = txtLnks.length;
		for(i=0; i<txtLnkLen; i++){
			txtLnks[i].onclick = function(){
				lnk = this.getAttribute("href");
				for(z=0; z<aroundLat.length; z++){
					if(lnk == aroundURL[z]){
						html = '<div class="fontM"><span class="fontL fontB">' + aroundTitle[z] + '</span><br /><a href="' + aroundURL[z] +  '" target="_blank">' + aroundURL[z] + '</a><br />' + aroundSummary[z] + '</div>';
						aroundGmapObj.openInfoWindowHtml(new GLatLng(aroundLat[z], aroundLng[z]),html);
						return false;
					}
				}
			}
		}
		
		/*var mapElem = document.getElementById("around-map");
		if (mapElem.addEventListener) //Mozilla
			mapElem.addEventListener('DOMMouseScroll', aroundZoomByWheel, false);
		mapElem.onmousewheel = aroundZoomByWheel;*/
		
		stayLoadXML();
		
	}
}







// マーカーポイント作成＆バルーンウィンドウ作成
function aroundCreateMarker(point,ttl,lnk,smry){
	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function(){
		html = '<div class="fontM"><span class="fontL fontB">' + ttl + '</span><br /><a href="' + lnk +  '" target="_blank">' + lnk + '</a><br />' + smry + '</div>';
		aroundGmapObj.openInfoWindowHtml(point,html);
	});
	/*if(ttl=="かしいかえん"){
		html = '<div class="fontM"><span class="fontL fontB">' + ttl + '</span><br /><a href="' + lnk +  '" target="_blank">' + lnk + '</a><br />' + smry + '</div>';
		aroundGmapObj.openInfoWindowHtml(point,html);
	}*/
	return marker;
}





// マウスホイールでの拡大縮小関数
function aroundZoomByWheel(event) {
	if (!event) event = window.event;
		var zoom = aroundGmapObj.getZoom();
		var delta = 0;
		if (event.wheelDelta) //IE
			delta = event.wheelDelta;
		else if (event.detail) //Mozilla
			delta = -event.detail;
		if (delta) {
			delta = delta < 0 ? -1 : +1;
			zoom += delta;
		if (zoom >= 0) {
				aroundGmapObj.setZoom(zoom);
			if (event.preventDefault) { //Firefox
				event.preventDefault();
				event.stopPropagation();
			} else { //IE
				event.returnValue = false;
				event.cancelBubble = true;
			}
		}
	}
}





function aroundMapLarge() {
	$("around-map").style.width = "644px";
	$("around-map").style.float = "none";
	$("around-map").style.margin = "0px 0px 10px 0px";
	$("around-txt").style.width = "644px";
	$("around-txt").style.float = "none";
	$("around-print").style.margin = "0px 0px 10px 0px";
	$("around-print").innerHTML = '<a href="javascript:aroundMapSmall();">地図を元に戻す</a>';
	window.resizeBy(-1,-1);
	window.resizeBy(1,1);
	$("footer1").style.bottom = "12px";
	$("footer2").style.bottom = "0px";
	aroundGmapObj.checkResize();
	var center = new GLatLng(aroundDefLat, aroundDefLng);
	aroundGmapObj.setCenter(center);
}

function aroundMapSmall() {
	$("around-map").style.width = "338px";
	$("around-map").style.float = "right";
	$("around-map").style.margin = "0px";
	$("around-txt").style.width = "290px";
	$("around-txt").style.float = "left";
	$("around-print").style.margin = "0px";
	$("around-print").innerHTML = '<a href="javascript:aroundMapLarge();">地図を拡大する</a>';
	window.resizeBy(-1,-1);
	window.resizeBy(1,1);
	$("footer1").style.bottom = "12px";
	$("footer2").style.bottom = "0px";
	location.href = "#around-map";
	aroundGmapObj.checkResize();
	var center = new GLatLng(aroundDefLat, aroundDefLng);
	aroundGmapObj.setCenter(center);
}










/*addEvent(window, 'load', aroundLoadXML);*/
aroundLoadXML();





