//
// easy_googlemaps.js
// Copyright(c) by H.Fujimoto
//
EasyGoogleMaps = function(data) {
    this.init(data);
};

EasyGoogleMaps.prototype = {
    data : null,
    map : null,
    infoHTML : null,

    init : function(data) {
        this.data = data;
        if (this.data.infoHTML) {
            this.infoHTML = '<div style="width : 10em; font-size : small">' + this.data.infoHTML + '</div>';
        }
    },

    draw : function() {
        if (GBrowserIsCompatible()) {
            this.map = new GMap2(document.getElementById(this.data.id));
            this.center = new GLatLng(this.data.lat, this.data.lon);
            if (this.data.LargeMapControl) {
                this.map.addControl(new GLargeMapControl());
            }
            if (this.data.MapTypeControl) {
                this.map.addControl(new GMapTypeControl());
            }
            if (this.data.SmallZoomControl) {
                this.map.addControl(new GSmallZoomControl());
            }
            if (this.data.OverviewMapControl) {
                this.map.addControl(new GOverviewMapControl());
            }
            this.map.setCenter(this.center, this.data.zoom);
            if (this.data.MapType) {
                if (this.data.MapType == 1) {
                    this.map.setMapType(G_MAP_TYPE);
                }
                else if (this.data.MapType == 2) {
                    this.map.setMapType(G_SATELLITE_TYPE);
                }
                else if (this.data.MapType == 3) {
                    this.map.setMapType(G_HYBRID_TYPE);
                }
            }
            if (this.data.centerInfoHTML) {
                this.map.openInfoWindowHtml(this.map.getCenter(), this.infoHTML);
            }
            if (this.data.Marker) {
                this.marker = new GMarker(this.center);
                this.map.addOverlay(this.marker);
                if (this.data.infoWindow && this.data.infoHTML) {
                    this.marker.title = this.infoHTML;
                    if (this.data.infoWindowOnShow) {
                        this.marker.openInfoWindowHtml(this.infoHTML);
                    }
                    GEvent.addListener(this.marker, 'click', function() {
                        this.openInfoWindowHtml(this.title);
                    });
                }
            }
        }
        else {
            document.getElementById(this.data.id).innerHTML = '<p>Your browser is not compatible for Google Maps.</p>';
        }
    }
};

function gMapBeforeUnload(func) {
    window.attachEvent ?
	window.attachEvent('onbeforeunload',func) : 
	window.addEventListener('beforeunload',func,false);
}
function gMapOnLoad(func) {
    window.attachEvent ?
	window.attachEvent('onload',func) : 
	window.addEventListener('load',func,false);
}

