function getZoomLebelFromWidth(width)
{
	if (width <= 0.004827976226806641) {
		return 17;
	} else if (0.004827976226806641 < width && width <= 0.009655952453613281) {
		return 16;
	} else if (0.009655952453613281 < width && width <=0.019311904907226562) {
		return 15;
	} else if (0.019311904907226562 < width && width <=0.038623809814453125) {
		return 14;
	} else if (0.038623809814453125 < width && width <=0.07724761962890625) {
		return 13;
	} else if (0.07724761962890625 < width && width <=0.1544952392578125) {
		return 12;
	} else if (0.1544952392578125 < width && width <=0.308990478515625) {
		return 11;
	} else if (0.308990478515625 < width && width <=0.61798095703125) {
		return 10;
	} else if (0.61798095703125 < width && width <=1.2359619140625) {
		return 9;
	} else if (1.2359619140625 < width && width <=2.471923828125) {
		return 8;
	} else if (2.471923828125 < width && width <=4.94384765625) {
		return 7;
	} else if (4.94384765625 < width && width <=9.8876953125) {
		return 6;
	} else if (9.8876953125 < width && width <=19.775390625) {
		return 5;
	} else if (19.775390625 < width && width <=39.55078125) {
		return 4;
	} else if (39.55078125 < width && width <=79.1015625) {
		return 3;
	} else if (79.1015625 < width && width <=158.203125) {
		return 2;
	} else if (158.203125 < width && width <=316.40625) {
		return 1;
	} else if (316.40625 < width) {
		return 0;
	}
}

function zoomMap(x, y, width)
{
	var newCenter = new GLatLng(y, x);
	var newZoomLebel = getZoomLebelFromWidth(width);
	map.setCenter(newCenter, newZoomLebel);
   	window.scrollTo(0,0);
}

function zoomToPref(viewname)
{
	if (viewname == "") return;
	
	var view = getPrefViewFromName(viewname);
	zoomMap(view[0], view[1], view[2]);
}

function plotSymbol(x, y, id, iconno)
{
	var targetPoint = new GPoint(x, y);
	var marker = new GMarker(targetPoint, getIcon(iconno));
    GEvent.addListener(marker, "click", function() {
   		var targetBlock = document.getElementById(id.toString(10));
      	marker.openInfoWindowHtml(targetBlock.innerHTML);
    });
	map.addOverlay(marker);
}

function clearSymbols()
{
	map.clearOverlays();
}

function getIcon(iconno)
{
	var markerURL = ROOT_URL + "map/mapsymbols/symbol20_34_" + iconno + ".png";
	var icon = new GIcon();
	icon.image = markerURL;
	icon.shadow = ROOT_URL + "map/mapsymbols/shadow20_34.png";
	icon.iconSize = new GSize(20, 34);
	icon.shadowSize = new GSize(37, 34);
	icon.iconAnchor = new GPoint(9, 34);
	icon.infoWindowAnchor = new GPoint(9, 2);
	icon.infoShadowAnchor = new GPoint(18, 25);
	
	return icon;
}

function geocode(address)
{
	var geocoder = new GClientGeocoder();
	geocoder.getLatLng(
		address,
		function(point) {
			if (!point) {
				alert("指定された住所はみつかりませんでした。");
		    } else {
		    	map.setCenter(point, 15);
		    }
		}
	);
}
