﻿// Check that the page has loaded
$(document).ready(function() {

    // GOOGLE MAPS
    var map = new GMap2($("#map2").get(0));
    var point_1 = new GLatLng(46.184685, 6.700909);
    map.setCenter(point_1, 2);
    map.setUIToDefault();
    var bounds = new GLatLngBounds();

    var TVIMarker = new GIcon();
    TVIMarker.image = "i/pin_marker.png";
    TVIMarker.shadow = "i/pin_shaddow.png";
    TVIMarker.iconSize = new GSize(30, 28);
    TVIMarker.shadowSize = new GSize(30, 28);
    TVIMarker.iconAnchor = new GPoint(10, 28);
    TVIMarker.infoWindowAnchor = new GPoint(10, 2);

    $('#instructorDetails .customInfoWindow').each(function() {
        if ($(this).find('.lat').val() != "") {
            point_1 = new GLatLng($(this).find('.lat').val(), $(this).find('.long').val());
            var marker_1 = new GMarker(point_1, TVIMarker);
            map.addOverlay(marker_1);
            bounds.extend(point_1);

            var point_1_text = $(this).html();
            // Display marker text on click
            GEvent.addListener(marker_1, "mouseover", function() {
                marker_1.openExtInfoWindow(map, "customInfoWindow", point_1_text, { breakOffset: 3 });
            });

        }

    });

    map.setZoom(map.getBoundsZoomLevel(bounds));
    if (map.getZoom() == 0) {
        map.setZoom(1);
    }
    map.setCenter(bounds.getCenter());

});