﻿//<![CDATA[
var map = null;
var done = false;
var geocoder = null;
var centerset = false;
var mapEntries = new Array(100);
var mapEntriesCount = 0;
var initialDelay = 200; // time (in milliseconds) before we start adding markers to the map
var cycle = 180; // time (in milliseconds) between the display of each marker on the map
var bounds = new GLatLngBounds();
window.onload = GLoad;
window.onunload = GUnload;
function GLoad() {
    if (GBrowserIsCompatible()) {
        map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        geocoder = new GClientGeocoder();
        geocoder.getLatLng('Montreal, Canada', function(point) { map.setCenter(point, 9); });
        var respointer = new GIcon();
        respointer.image = "http://www.reseau411.ca/images/gmap/sign_red_big.png";
        respointer.shadow = "http://www.reseau411.ca/images/gmap/sign_shadow_big.png";
        respointer.iconSize = new GSize(28, 28);
        respointer.shadowSize = new GSize(44, 28);
        respointer.iconAnchor = new GPoint(16, 28);
        respointer.infoWindowAnchor = new GPoint(5, 1);
        markerOptions = { icon: respointer };
    }
}
function showAddressOnMap(cl, address, nom, tel, website, logo, lang) {
    try {
        if (!geocoder) {
            geocoder = new GClientGeocoder();
        };
        geocoder.getLatLng(address,function(point) {
            if (!point) {
                // adresse not found
            } else {
                bounds.extend(point);
                // var marker = new GMarker(point);
                var marker = new GMarker(point, markerOptions);
                map.addOverlay(marker);
                if (website) {
                    website = "<a href='" + "http://" + website + "' target='_blank'>" + website + "</a>"
                }
                if (logo) {
                    logo = "<img src='" + logo + "' align='left'>"
                }
                if (nom) {
                    nom = "<span class='bubble_nom'> " + nom + "</span>"
                }
                if (tel) {
                    tel = "<span class='bubble_tel'>" + tel + "</span>"
                }
                if (address) {
                    address = "<span class='bubble_address'>" + address + "</span>"
                }
                lien1 = ""
                lien2 = ""
                if (cl) {
                    lien1 = "<a href='/" + lang + "/" + cl + "' target='_blank'>"
                    lien2 = "</a>"
                }
                marker.bindInfoWindowHtml(logo + "<strong>" + lien1 + nom + lien2 + "</strong><br>" + address + "<br>" + tel + "<br>" + website);
            }
        });
    }
    catch (e) {
    }
}
function mapEntry(s) {
    mapEntries[mapEntriesCount] = s;
    mapEntriesCount++;
}
function showMap() {
    try {
        var i = 0;
        for (i = 0; i < mapEntriesCount; i++) {
            setTimeout(mapEntries[i], initialDelay + (i * cycle));
        }
        if (mapEntriesCount > 0) {
            if (mapEntriesCount < 3) { initialDelay = initialDelay * 5; }
            setTimeout("map.setZoom(map.getBoundsZoomLevel(bounds)-1)", initialDelay + (mapEntriesCount * (cycle * 2)));
            setTimeout("map.setCenter(bounds.getCenter(), 15)", initialDelay + (mapEntriesCount * (cycle * 2)))
        }
        setTimeout('document.getElementById("map").style.visibility =\'visible\'', initialDelay + (mapEntriesCount * (cycle * 2)));
    }
    catch (e) {
    }
}

function doMap() {
    if (!done) {
        document.getElementById("map").style.visibility = 'hidden';
        setTimeout("GUnload(); GLoad(); showMap();", 500);
        done = true;
        setTimeout("document.getElementById('map').style.visibility = 'visible';", 2000);
    }
}

//]]>