//
// Google Map Control
//

// CONFIGURATION

var map = null;
var geocoder = null;

//
// Google Mapの表示
//

var GmapCtl = Class.create();

GmapCtl.prototype = {

	initialize: function() {
		this.x = 139.76710;
		this.y = 35.68105;
		this.zoom = 15;

		if (!GBrowserIsCompatible()) { return false; }
		if (!document.getElementById("map")) { return false; }

		map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(this.y, this.x), this.zoom);

		geocoder = new GClientGeocoder();
	
	},

	addCtl: function() {
		map.addControl(new GOverviewMapControl());
		map.addControl(new GMapTypeControl());
	//	map.addControl(new GSmallMapControl());
		map.addControl(new GSmallZoomControl());
	//	map.addControl(new GLargeMapControl());
	},

	moveTo: function(x, y)  {
		this.x = x;
		this.y = y;
		return this;
	},

	clear: function() {
		map.clearOverlays();
	},

	setposition: function() {
		map.setCenter(new GLatLng(this.y, this.x), this.zoom);
	},

	goSearch: function(address) {

		if (!geocoder) { return false; }
		if (!address) { return false; }

		geocoder.getLatLng(
			address,			function(point){				if (!point){					alert(address + "は、Google Map上見つかりませんでした。");
					new Effect.Highlight("address");
					$("address").value = "";
				}else{					map.setCenter(point, 15);				}			}		);
	},

	getCenterPos: function(){
		var centerPoint = map.getCenter();
		this.x = centerPoint.x;
		this.y = centerPoint.y;
		return this;	
	},

	chgW2J: function( wx, wy ){
		var jposition = new Array;
		var jx1 = wx * 1.000083049 - wy * 0.000046047 - 0.010041046;
		var jy1 = wy * 1.000106961 - wx * 0.000017467 - 0.004602017;

		jposition.x = parseInt(jx1 * 3600 * 1000);
		jposition.y = parseInt(jy1 * 3600 * 1000);

		return jposition;
	},

	createMarker: function(x1, y1, tl1, tab1, tl2, tab2) {	var marker = new GMarker(new GLatLng(y1, x1));	GEvent.addListener(marker, 'click', function() {
		tabList=[
			new GInfoWindowTab(tl1, tab1),
			new GInfoWindowTab(tl2, tab2)
			]

		marker.openInfoWindowTabsHtml(tabList);  		})
	map.addOverlay(marker);
	}
}