﻿var commerceIcon = new GIcon(G_DEFAULT_ICON);
commerceIcon.image = liveString + "/Content/images/contenu/cartes/installations/commerce.png";
commerceIcon.iconSize = new GSize(24, 24);
commerceIcon.shadowSize = new GSize(24, 24);
var currentMapId;
var defaultPoint = new GLatLng(46.7406389, -71.4513056);
$(document).ready(function() {
    $('.voir-carte').click(function() {
        getPlace(this.rel, this.title);
        $(this).unbind('click');
        $(this).click(function() { $("#map_holder" + this.title).toggle(500); return false; });
        return false;
    });
    $('#Category').val('-1');
    $('#Category').change(function() {
        if ($(this).val() == -1) {
            $('div .entreprises-liste').find('span.jour-evenement-texte').show(200);
        } else {
            $('div .entreprises-liste').find('span.jour-evenement-texte').not('.category' + $(this).val()).hide(200);
            $('div .entreprises-liste').find('span.category' + $(this).val()).show(200);
        }
    });
});

function getPlace(placeName, mapId) {
    currentMapId = mapId;
    $.getJSON(liveString + "/Maps/GetPlace/" + placeName, setupMarker);
}

function setupMarker(place) {
    if (google.maps.BrowserIsCompatible() && $("#map_canvas" + currentMapId)) {
        $("#map_holder" + currentMapId).toggle(500);
        if ($("#map_holder" + currentMapId).is(':visible')) {
            var map = new google.maps.Map2($("#map_canvas" + currentMapId)[0]);
            map.setMapType(G_HYBRID_MAP);
            map.setUIToDefault();
            map.disableScrollWheelZoom();
            map.clearOverlays();
            map.setCenter(defaultPoint, 13);
            if (place.Latitude != 0) {
                var mOption = { icon: commerceIcon };
                var marker = new GMarker(new GLatLng(Number(place.Latitude), Number(place.Longitude)), mOption);
                map.panTo(marker.getLatLng());
                map.addOverlay(marker);
                marker.openInfoWindowHtml(place.HtmlBubble);
            }
            else {
                if (place.KmlFile) {
                    var geoXml = new GGeoXml(place.KmlFile);
                    map.panTo(geoXml.getLatLng());
                    map.addOverlay(geoXml);
                }
            }
        }
    }
}
