/**
 * realisations_photo.tpl
 *
 * @author      CHEDOTAL Amaury
 */

$(function() {

    function initialize() {
        if (GBrowserIsCompatible()) {
            
            /*
             * Map
             */
            var map = new GMap2(document.getElementById('map'));
            
            /**
             * Get GPS Coordinates
             */
            var geocoder = new GClientGeocoder();
            var address = Serum.activolt_MERCHANT_ADDRESS1+" "+Serum.activolt_MERCHANT_ADDRESS2+" "+Serum.activolt_MERCHANT_ZIPCODE+" "+Serum.activolt_MERCHANT_CITY;
            
            geocoder.getLatLng(
              address,
              function(point) {
                if (point) {

                    /*
                     * Icon
                     */
                    var blueIcon        = new GIcon(G_DEFAULT_ICON);
                    blueIcon.image      = Serum.inside_googlemaps_marker;
                    blueIcon.iconSize   = new GSize(40, 50);
                    blueIcon.imageMap   = new Array(0,0,40,0,40,50,0,50);
                    blueIcon.iconAnchor = new GPoint(40, 50);
                    
                    /*
                     * Set up map control (zoom in and out, and other stuff)
                     */
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());
                    
                    /* 
                     * Set map center
                     */
                    map.setCenter(point, 15);
                    
                    /**
                     * Set up Marker
                     */ 
                    var marker = new GMarker(point, blueIcon );
                    marker.value = 1;
                    map.addOverlay(marker);
                    
                    /**
                     * Add click event on Marker
                     */
                    GEvent.addListener(marker, 'click', function() {
                        var htmlAddress = '<strong>' + Serum.activolt_MERCHANT_NAME + ' ' + Serum.activolt_MERCHANT_JURIDICSTATUS + '</strong><br/>';
                        htmlAddress += Serum.activolt_MERCHANT_ADDRESS1 + '<br />';    
                        if (Serum.activolt_MERCHANT_ADDRESS2 != '') {
                            htmlAddress += Serum.activolt_MERCHANT_ADDRESS2 + '<br />'; 
                        }
                        htmlAddress += Serum.activolt_MERCHANT_ZIPCODE + ' ' + Serum.activolt_MERCHANT_CITY; 

                        marker.openInfoWindowHtml(htmlAddress);
                    });
                    
                  }
                }
              );
        }
    }

    initialize();

});
