﻿// JScript File

function createMarker(point, html) {
    var marker = new GMarker(point);
    GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });
    map.addOverlay(marker);
    return marker;
}
function resizeCenterMap(minLng, maxLng, minLat, maxLat) {
    map.setZoom(14);
    var bounds = map.getBounds();

    var north = bounds.getNorthEast();
    var south = bounds.getSouthWest();
    var width = north.lng() - south.lng();
    var height = north.lat() - south.lat();

    var needWidth = maxLng - minLng;
    var needHeight = maxLat - minLat;

    do {
        map.setZoom(map.getZoom() - 1);
        var bounds = map.getBounds();
        var north = bounds.getNorthEast();
        var south = bounds.getSouthWest();
        var width = north.lng() - south.lng();
        var height = north.lat() - south.lat();
    }
    while ((needWidth > width) || (needHeight > height))
    map.setZoom(map.getZoom() - 1);
    map.setCenter(new GLatLng(((minLat + maxLat) / 2), ((minLng + maxLng) / 2)));
}

function toggleLayer(whichLayer, bOnOff) {
    //! is ued to switch the bOnOff, works right when its switched
    if (document.getElementById) {
        // this is the way the standards work
        var style2 = document.getElementById(whichLayer).style;
        //alert(bOnOff);
        style2.display = !bOnOff ? "none" : "block";
    }
    else if (document.all) {
        // this is the way old msie versions work
        var style2 = document.all[whichLayer].style;
        style2.display = !bOnOff ? "none" : "block";
    }
    else if (document.layers) {
        // this is the way nn4 works
        var style2 = document.layers[whichLayer].style;
        style2.display = !bOnOff ? "none" : "block";
    }
}
function createPointFromAddress(sAddress, sID, sHTML) {
    if (geocoder) {
        geocoder.getLatLng(sAddress, function(point) {
            if (point) {
                var marker = new GMarker(point); map.centerAndZoom(point, 4); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(sHTML); });
                map.addOverlay(marker);
            } else { toggleLayer('map', false); }
        }
       );
    }
}


var map;
var geocoder = new GClientGeocoder();
function loadMap() {
    map = new GMap(document.getElementById("map"));
    map.centerAndZoom(new GPoint(-87.988172, 42.140525), 10);
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.setMapType(G_HYBRID_MAP);


}


