/*****************************************
 * JavaScript: gmaps_load.js  1.0
 * 
 * last updated on 2008.01.22
 * (c) 2008 Junji Kuroki (http://www.resumenext.com/)
 * 
 * use: Google Maps API Key
 * --------------------------------------------------------
 * Please bury API Key under the following places. 
 * <head>
 * 		<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=APIKEY" type="text/javascript"></script>
 * </head>
 * 
 * Script to display GoogleMap.
 * <body>
 *		<script type="text/javascript">
 *			simplegmaps_load("gmaps", "LON", "LAT", 15);
 *		</script>
 * 
 *****************************************/
function simplegmaps_load(_id, _y, _x, _z) {
	if (GBrowserIsCompatible()) {
		var _desc = document.getElementById(_id).innerHTML;
		var map = new GMap2(document.getElementById(_id));

		//map.addControl(new GSmallMapControl());
		map.addControl(new GLargeMapControl());
		map.addControl(new GMapTypeControl());
		//map.addControl(new GScaleControl() );
		//map.addControl(new GOverviewMapControl());
		map.enableDoubleClickZoom();
		map.enableContinuousZoom(); 
		map.setCenter(new GLatLng(_y, _x), _z);

		//desc
		var point = new GMarker(new GLatLng(_y, _x));
		if(_desc){
			GEvent.addListener(point, "click", function() {
				point.openInfoWindowHtml(_desc);
			});
		}
		map.addOverlay(point);


	}
}


function gmaps_box_open(doc) {
	doc.innerHTML = '';
	document.getElementById("gmaps_box").style.display = "";
	simplegmaps_load_admin('gmaps_admin', '35.68150944335228', '139.76486921310425', 6);
}


function simplegmaps_load_admin(_id, _y, _x, _z) {
	if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById(_id));

		//map.addControl(new GSmallMapControl());
		map.addControl(new GLargeMapControl());
		//map.addControl(new GMapTypeControl());
		//map.addControl(new GScaleControl() );
		map.addControl(new GOverviewMapControl());
		map.enableDoubleClickZoom();
		map.enableContinuousZoom(); 
		map.setCenter(new GLatLng(_y, _x), _z);

		//icon
		var icon = new GIcon();
		icon.image = "http://www.google.com/mapfiles/marker.png";
		icon.shadow = "http://www.google.com/mapfiles/shadow50.png";
		icon.iconSize = new GSize(20, 34);
		icon.iconAnchor = new GPoint(10, 34);
		var marker = new GMarker(new GLatLng(_y, _x), icon);
		map.addOverlay(marker);

		GEvent.addListener(map, "move", function() { 
			map.clearOverlays()
			marker = new GMarker(map.getCenter(), icon);
			map.addOverlay(marker);
		});

		//tag
		GEvent.addListener(map, "moveend", function() {
			var center = map.getCenter();
			var z = map.getZoom();
			document.getElementById("maps_tag").value = "[gmaps:" + center.y + "/" + center.x + "/" + z + "/460/300](comment)[/gmaps]";
		});

	}
}
