//<![CDATA[

var map;
var myPoint;
var webroot;

var icon = new GIcon();
icon.image = "/img/pin.gif";
icon.iconSize = new GSize(19, 22);
icon.iconAnchor = new GPoint(9.5, 11);
icon.infoWindowAnchor = new GPoint(9.5, 11);

function createMarker(point, html) {
	var marker = new GMarker(point, icon);
//	var marker = new GMarker(point);
	GEvent.addListener(marker, "click", function() {
		marker.openInfoWindowHtml(html);
	});
	return marker;
}

function renderInfo(req){
	var obj = eval('(' + req.responseText + ')');

	var inHtml = '';

	//マップ上のピン初期化
	map.clearOverlays();
	for(var i = 0;i<obj.status.count;i++){
		var res = obj[i];
		var info = res.special_infos;
		var num = i + 1;

		var str;
		// 吹き出しHTML組み立て
		var html = '';
		html += '<ul>';
		html += '<li style="width:250px; word-wrap:break-word;">';
		html += '<dl style="float:left; width:185px;">';
		html += '<dt style="font-size: 12px;font-weight: bold;">' + num + '. <a href="' + info.url + '">' + info.info_title + '</a></dt>';
		html += '<dd style="font-size: 10px;">所在地：' + info.prefectures + info.address + info.building + '</dd>';
		html += '</dl>';
		html += '<div style="float:right;margin-top:10px;"><a href="' + info.url + '"><img src="' + info.pict + '" alt="" width="60" height="55"></a></div>';
		html += '</li>';
		html += '</ul>';
		var point = new GLatLng(info.address_latitude, info.address_longitude);
		map.addOverlay(createMarker(point, html));
	}

	if (obj.defaultpos && obj.defaultpos.lat && obj.defaultpos.lng) {
		var lat = obj.defaultpos.lat;
		var lng = obj.defaultpos.lng;
		map.setCenter(new GLatLng(lat, lng), 15);
	}
}

function getInfo(id){
	var center = map.getCenter();
		if (myPoint == center) {
			return;
		}
		myPoint = center;
	var zoom = map.getZoom();
	var url = webroot + "special/getInfos/" + id + '?cache=' + (new Date()).getTime();
	new Ajax.Request(url, {method: 'get', onComplete: renderInfo});
}

function searchRooms(action) {
	document.specialForm.action = action;
	document.specialForm.submit();
}

//]]>
