// 地点クラス
var Place = function(name, cY, cX, mY, mX, infoHtml) {
	this.name = name;
	this.center = new GLatLng(cY, cX);
	this.marker = new GMarker(new GLatLng(mY, mX));
	this.infoHtml = infoHtml;
}

// GoogleMap汎用クラス
var CmGMap = function(mapid, width, height, popwidth, zoom) {
	this.mapid = mapid;
	this.width = width;
	this.height = height;
	this.popwidth = popwidth;
	this.zoom = zoom;

	this.map = null;
	this.places = new Object;

	// 初期化
	this.init = function(center)
	{
		if (GBrowserIsCompatible())
		{
			// 地図のサイズ設定
			//   ※サイズを明示的に指定しないと、NN7.1にて、表示が乱れる場合がある
			var opts = {size : new GSize(this.width, this.height)};
			this.map = new GMap2(document.getElementById(this.mapid), opts);
			document.getElementById(mapid).style.height = this.height + "px";
			document.getElementById(mapid).style.width = this.width + "px";

			// 地図オブジェクトの初期化
			this.map.enableContinuousZoom();
			this.map.enableScrollWheelZoom();
			this.map.addControl(new GLargeMapControl());
			this.map.addControl(new GMapTypeControl());

			// 地図上のアイテムの初期化
			this.map.setCenter(center, this.zoom);  // Overlayの前にやらないとエラーになる

		}
	}

	// 地点追加
	this.addPlace = function(place)
	{
		this.places[place.name] = place;

		// マーカーを追加
		this.map.addOverlay(place.marker);

		var obj = this;	// イベントリスナーに登録する無名関数内ではthisの参照先が変わるため、参照用変数を経由する

		// イベントリスナー登録
		GEvent.addListener(
				place.marker,
				'click',
				function(){ obj.openPop(place.name); }
		);

	}

	// ポップアップ表示
	this.openPop = function(name)
	{
		if (this.places[name] == null)
		{
			return;
		}
		var option = this.map.getInfoWindow();
		option.maxWidth = this.popwidth;

		var marker = this.places[name].marker;

		this.map.setCenter(this.places[name].center, this.zoom);
		marker.openInfoWindowHtml(this.places[name].infoHtml, option );

	}

}

