﻿var _width = 638;
var _height = 238;

function createMarker(point, number, name, place) {
    if (!GBrowserIsCompatible()) return;
    var ilnyIcon = new GIcon();
    var folder = '/Images/markers/';
    ilnyIcon.image = folder + number + '_image.png';
    ilnyIcon.printImage = folder + number + '_printImage.gif';
    ilnyIcon.mozPrintImage = folder + number + '_mozPrintImage.gif';
    ilnyIcon.iconSize = new GSize(21, 28);
    ilnyIcon.shadow = folder + 'shadow.png';
    ilnyIcon.transparent = folder + 'transparent.png';
    ilnyIcon.shadowSize = new GSize(21, 28);
    ilnyIcon.printShadow = folder + 'printShadow.gif';
    ilnyIcon.iconAnchor = new GPoint(8, 8);
    ilnyIcon.infoWindowAnchor = new GPoint(8, 1);
    ilnyIcon.imageMap = [13, 0, 14, 1, 15, 2, 16, 3, 17, 4, 17, 5, 17, 6, 17, 7, 17, 8, 17, 9, 17, 10, 17, 11, 17, 12, 17, 13, 16, 14, 15, 15, 14, 16, 13, 17, 11, 18, 11, 19, 17, 20, 18, 21, 19, 22, 19, 23, 19, 24, 19, 25, 18, 26, 0, 26, 0, 25, 0, 24, 0, 23, 0, 22, 0, 21, 2, 20, 5, 19, 6, 18, 4, 17, 3, 16, 2, 15, 1, 14, 0, 13, 0, 12, 0, 11, 0, 10, 0, 9, 0, 8, 0, 7, 0, 6, 0, 5, 0, 4, 1, 3, 2, 2, 3, 1, 4, 0];

    markerOptions = { icon: ilnyIcon };

    var marker = new GMarker(point, markerOptions);
    GEvent.addListener(marker, "click", function() {
        var myHtml = "<strong>" + name + "</strong><br/>" + place;
        window.gmap.openInfoWindowHtml(point, myHtml);
    });
    return marker;
}

function createMainMarker(point) {
    if (!GBrowserIsCompatible()) return;
    var mainIcon = new GIcon();
    var folder = '/Images/markers/';
    mainIcon.image = folder + 'gray_image.png';
    mainIcon.printImage = folder + 'gray_printImage.gif';
    mainIcon.mozPrintImage = folder + 'gray_mozPrintImage.gif';
    mainIcon.iconSize = new GSize(21, 28);
    mainIcon.shadow = folder + 'shadow.png';
    mainIcon.transparent = folder + 'transparent.png';
    mainIcon.shadowSize = new GSize(21, 28);
    mainIcon.printShadow = folder + 'printShadow.gif';
    mainIcon.iconAnchor = new GPoint(8, 8);
    mainIcon.infoWindowAnchor = new GPoint(8, 1);
    mainIcon.imageMap = [13, 0, 14, 1, 15, 2, 16, 3, 17, 4, 17, 5, 17, 6, 17, 7, 17, 8, 17, 9, 17, 10, 17, 11, 17, 12, 17, 13, 16, 14, 15, 15, 14, 16, 13, 17, 11, 18, 11, 19, 17, 20, 18, 21, 19, 22, 19, 23, 19, 24, 19, 25, 18, 26, 0, 26, 0, 25, 0, 24, 0, 23, 0, 22, 0, 21, 2, 20, 5, 19, 6, 18, 4, 17, 3, 16, 2, 15, 1, 14, 0, 13, 0, 12, 0, 11, 0, 10, 0, 9, 0, 8, 0, 7, 0, 6, 0, 5, 0, 4, 1, 3, 2, 2, 3, 1, 4, 0]; 
    markerOptions = { icon: mainIcon };
    var marker = new GMarker(point, markerOptions);
    return marker;
}

// Creates a marker at the given point
// but that message is not within the marker's instance data
function showAddress(addressHTML, latValue, longValue) {
    if (!GBrowserIsCompatible()) return;
    if (window.geocoder) {
        var point = new GLatLng(latValue, longValue);
        var marker = new GMarker(point);
        window.gmap.addOverlay(marker);
        //  marker.openInfoWindowHtml(address);
        GEvent.addListener(marker, "mouseover", function() {
            marker.openInfoWindowHtml(addressHTML);
        });
    }
}

function setMapProperties() {

    // define the crosshair tile layer and its required functions
    var crossLayer = new GTileLayer(new GCopyrightCollection(""), 0, 15);
    crossLayer.getTileUrl =  function(tile, zoom) {
        return "./include/tile_crosshairs.png";
    }
    crossLayer.isPng = function() {return true;}
    // Create a new map type incorporating the tile layer
    var layerTerCross = [ G_PHYSICAL_MAP.getTileLayers()[0], crossLayer ];
    var mtTerCross = new GMapType(layerTerCross, G_PHYSICAL_MAP.getProjection(), "Ter+");
}

function mapload(width, height, latitude, longitude, zoomLevel, mapValues) {
    if (!GBrowserIsCompatible()) return;

    _width = width;
    _height = height;

    if (window.gmap == null) {
        setMapProperties();
        getGoogleMap();
    }
    
    window.gmap.setCenter(new GLatLng(latitude, longitude), zoomLevel); //5 is zoom level (state), 9 - radius 30 Mi, 11 -  5 Mi

    mainPoint = new GLatLng(latitude, longitude);
    var mainMarker = createMainMarker(mainPoint);
    window.gmap.addOverlay(mainMarker); 
}

function getGoogleMap() {
   
    if (window.gmap == null) {
        window.gmap = new GMap2(document.getElementById("map2"), {
            size: new GSize(_width, _height)
        });
        //window.gmap.addMapType(G_PHYSICAL_MAP);
        //window.gmap.addMapType(mtTerCross);
        window.gmap.addControl(new GScaleControl());
        var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10, 40));
        window.gmap.addControl(new GSmallMapControl(), topLeft);
        //map.addControl(new GLargeMapControl()  );

        //var mapControl = new GHierarchicalMapTypeControl();

        // Set up map type menu relationships
        //mapControl.clearRelationships();
        //mapControl.addRelationship(G_SATELLITE_MAP, G_HYBRID_MAP, "Labels", false);
        //mapControl.addRelationship(G_PHYSICAL_MAP, mtTerCross, "Crosshairs");
        //window.gmap.addControl(mapControl);
    }
}
