﻿//----------------------------------------------------------------------------//
// Javascript pour la map google du WebShow ----------------------------------//
//----------------------------------------------------------------------------//

WebShowMap = function() {
    this._map = null;
    this._address = null;
    this._element = null;

}
WebShowMap$Initialize = function(element) {
    this._element = element;
    if (GBrowserIsCompatible()) {
        jQuery(window).unload(function() { GUnload(); });
    }

}

WebShowMap$SetAddress = function(address) {
    this._address = address;
    this._map = new GMap2(document.getElementById(this._element));

    var ui = this._map.getDefaultUI();
    ui.controls.smallzoomcontrol3d = false;
    ui.controls.menumaptypecontrol = false;
    this._map.setUI(ui);
    this._map.disableDragging();
    
    var me = this;
    var geocoder = new GClientGeocoder();
    geocoder.getLatLng(this._address, function(point) { me.setLocation.apply(me, [point]) });
    GEvent.addListener(this._map, "click", function() { me.openGoogleMapsWindow.apply(me) });
}
WebShowMap$SetLocation = function(point) {
    if (!point) {
        ;
    } else {
        this._map.setCenter(point, 12);
        var marker = new GMarker(point);
        this._map.addOverlay(marker);
    }
}
WebShowMap$OpenGoogleMapsWindow = function() {
    window.location.href = 'http://maps.google.com/maps?hl=fr&q=' + this._address;
}

WebShowMap.prototype = {
    initialize: WebShowMap$Initialize,
    setAddress: WebShowMap$SetAddress, 
    setLocation: WebShowMap$SetLocation,
    openGoogleMapsWindow: WebShowMap$OpenGoogleMapsWindow
}