
// GoogleMapに関するJavascript
//  プロトタイプにメソッドを追加する。
//  コンストラクタを Prototype に実装する。

function GoogleMapManager() {
    this.initialize.apply(this, arguments);
}
GoogleMapManager.prototype.initialize = function(targetElement, lttd, lgtd, zoom) {
    this.element = targetElement;
    this.lttd    = lttd;
    this.lgtd    = lgtd;
    this.zoom    = zoom;

	if(! this.lttd)
		this.lttd = 33.595175;

	if(! this.lgtd)
		this.lgtd = 130.404968;

	if(! this.zoom)
		this.zoom = 13;

};

GoogleMapManager.prototype.show = function() {
	this.map = new GMap2(document.getElementById(this.element));
	this.map.addControl(new GSmallMapControl());
	this.map.setCenter(new GLatLng(this.lttd,this.lgtd), this.zoom, G_NORMAL_MAP);
};

GoogleMapManager.prototype.setMarker = function(lttd, lgtd, html, src, iconWidth, iconHeight, zindex) {
	var marker;
	var markerOptions;

	if(src) {
		if (navigator.userAgent.indexOf("Trident/4.0") != -1) {
			markerOptions = {icon:getGmapIcon(src, iconWidth, iconHeight)};
		}
		else {
			markerOptions = {zIndexProcess: function(){return zindex;}, icon:getGmapIcon(src, iconWidth, iconHeight)};
		}
	}
	else {
		if (navigator.userAgent.indexOf("Trident/4.0") == -1)
			markerOptions = {zIndexProcess: function(){return zindex;}};
	}
	marker = new GMarker(new GLatLng(lttd, lgtd), markerOptions);

	this.map.addOverlay(marker, zindex);

	if(html) {
		GEvent.addListener(marker, 'click', function() {
			marker.openInfoWindowHtml(html);
		});
	}
};


	// マーカーのアイコンを準備
	function getGmapIcon(src, iconWidth, iconHeight) {
		width  = 20;
		height = 20;

		if(iconWidth)
			width = iconWidth;

		if(iconHeight)
			height = iconHeight;


		var icon              = new GIcon();
		icon.image            = src;
		icon.iconSize         = new GSize (width, height);
		icon.iconAnchor       = new GPoint(10, 10);
		icon.infoWindowAnchor = new GPoint(Math.round(width / 2), Math.round(height / 2));
		return(icon);
	}

