/**
 * 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, 8);
            
                        jQuery.each(Serum.listephotogooglemap, function(i, val){
                            //console.log(val);
                            var marker = new GMarker(new GLatLng(val['GPS_x'],val['GPS_y']), blueIcon );
                            marker.value = 1;
                            map.addOverlay(marker);
                            
                            
                            GEvent.addListener(marker, 'click', function() {
                                var galleryDetailPopupContent = "<h2 class=\"in-line\">" + val['construction_site'] + "</h2>";
                                galleryDetailPopupContent += "<span class=\"place\">" + val['place'] + "</span><br />";
                                galleryDetailPopupContent += "<a href='" + Serum.tabphoto[i].original +"' target='_blank' title='" + val['name'] + "'><img src='" + Serum.tabphoto[i].zoom +"' /></a>";

                                marker.openInfoWindowHtml(galleryDetailPopupContent);
                                
                                map.setCenter(marker.getLatLng());
                            });
                           
                        });
                        
                    }
                }
            );
        }
    }
initialize();
});
