﻿//<![CDATA[
var gMapComparables;
var gMapAssessments;

function initMapGMC()
{
    if (GBrowserIsCompatible()) 
    {
        var map = document.getElementById("gMapComparables");
        if(map)
        {
            gMapComparables = new GMap2(document.getElementById("gMapComparables"));
        }
    }
}
function initMapGMA()
{
    if (GBrowserIsCompatible()) 
    {
        var map = document.getElementById("gMapAssessments");
        if(map)
        {
            gMapAssessments = new GMap2(document.getElementById("gMapAssessments"));
        }
    }
}
function initMap(mapName, gMap) {
    if (GBrowserIsCompatible()) {
        var map = document.getElementById(mapName);
        if (map) {
            return new GMap2(document.getElementById(mapName));
        }
    }
}
function centerMap(lat, lon, address, gMap) {
    centerMap(lat, lon, address, gMap, true);
}
function centerMap(lat, lon, address, gMap, fullControls) {
    if (GBrowserIsCompatible()) {
        if (gMap) {
            if(fullControls)
                gMap.setCenter(new GLatLng(lat, lon), 13);
            else
                gMap.setCenter(new GLatLng(lat, lon), 12);
        }
    }
}
function addReference(lat, lon, address, gMap)
{
    addReference(lat, lon, address, gMap, true);
}

function addReference(lat, lon, address, gMap, fullControls) {
    iconCount = 0;
    if (GBrowserIsCompatible()) {
        var point = new GLatLng(lat, lon);

        //gMap.setCenter(point, 14);            

        var latOffset = 0.01;
        var lonOffset = 0.015;
        var polygon = new GPolygon([
        new GLatLng(lat - latOffset, lon - lonOffset),
        new GLatLng(lat + latOffset, lon - lonOffset),
        new GLatLng(lat + latOffset, lon + lonOffset),
        new GLatLng(lat - latOffset, lon + lonOffset),
        new GLatLng(lat - latOffset, lon - lonOffset),
        ], "#f33f00", 1, 1, "#ff0000", 0.2);
        var Icon = new GIcon();
        Icon.image = "/img/mapicon-subj.png";
        Icon.iconSize = new GSize(23, 27);
        Icon.shadow = "/img/mapicon-shadowx.png";
        Icon.shadowSize = new GSize(29, 26);
        Icon.iconAnchor = new GPoint(10, 25);
        //Icon.infoWindowAnchor = new GPoint(5, 2);
        //Icon.transparent = "mytran.png";
        //Icon.printImage = "mymarkerie.gif";
        //Icon.mozPrintImage = "mymarkerff.gif";
        //Icon.printShadow = "myshadow.gif";
        //Icon.imageMap=[9,0,6,1,4,2,2,4,0,8,0,12,1,14,2,16,5,
        // 19,7,23,8,26,9,30,9,34,11,34,11,30,12,26,13,24,14,21,
        // 16,18,18,16,20,12,20,8,18,4,16,2,15,1,13,0];
        var marker = new GMarker(point, { clickable: false, icon: Icon, zIndexProcess: importanceOrder }); //, markerOptions);
        marker.importance = 201;
        gMap.addOverlay(marker);
        if (fullControls) {
            gMap.addControl(new GSmallZoomControl());
        }
        else {
            gMap.disableDragging();
        }
        //marker.openInfoWindowHtml(address);
    }

}








var iconCount = 0;
function addPoint(lat, lon, address, gMap) {
    if (GBrowserIsCompatible()) 
    {
        var point = new GLatLng(lat, lon);
        var Icon = new GIcon();
          if(iconCount++ <= 15)
              Icon.image = "/img/mapicon-comp" + iconCount + ".png";
          else
              Icon.image = "/img/mapicon-compx.png";

          Icon.iconSize = new GSize(23, 27);
          Icon.shadow = "/img/mapicon-shadowx.png";
          Icon.shadowSize = new GSize(29, 26);
          Icon.iconAnchor = new GPoint(10, 25);
        var marker = new GMarker(point, {clickable:false, icon:Icon, zIndexProcess:importanceOrder});
        marker.importance = 200-iconCount;
        gMap.addOverlay(marker);
    }
}
function addGreenPoint(lat, lon, address, gMap) {
    if (GBrowserIsCompatible()) {
        var point = new GLatLng(lat, lon);
        var Icon = new GIcon();
        Icon.image = "/img/mapicon-green.png";

        Icon.iconSize = new GSize(23, 27);
        Icon.shadow = "/img/mapicon-shadowx.png";
        Icon.shadowSize = new GSize(29, 26);
        Icon.iconAnchor = new GPoint(10, 25);
        var marker = new GMarker(point, { clickable: false, icon: Icon, zIndexProcess: importanceOrder });
        marker.importance = 100;
        gMap.addOverlay(marker);
    }
}
function addGreyPoint(lat, lon, address, gMap) {
    if (GBrowserIsCompatible()) {
        var point = new GLatLng(lat, lon);
        var Icon = new GIcon();
        Icon.image = "/img/mapicon-grey-50.png";

        Icon.iconSize = new GSize(23, 27);
        Icon.shadow = "/img/mapicon-shadowx.png";
        Icon.shadowSize = new GSize(29, 26);
        Icon.iconAnchor = new GPoint(10, 25);
        var marker = new GMarker(point, { clickable: false, icon: Icon, zIndexProcess: importanceOrder });
        marker.importance = 100;
        gMap.addOverlay(marker);
    }
}
function addColorPoint(lat, lon, address, color, gMap) {
    if (GBrowserIsCompatible()) {
        var point = new GLatLng(lat, lon);
        var Icon = new GIcon();
        if (iconCount++ <= 15)
            Icon.image = "/img/mapicons/" +color+ "/mapicon-comp" + iconCount + ".png";
        else
            Icon.image = "/img/mapicons/" + color + "mapicon-compx.png";

        Icon.iconSize = new GSize(23, 27);
        Icon.shadow = "/img/mapicon-shadowx.png";
        Icon.shadowSize = new GSize(29, 26);
        Icon.iconAnchor = new GPoint(10, 25);
        var marker = new GMarker(point, { clickable: false, icon: Icon, zIndexProcess: importanceOrder });
        marker.importance = 200 - iconCount;
        gMap.addOverlay(marker);
    }
}

function inverseOrder(marker, b) {
    return -GOverlay.getZIndex(marker.getPoint().lat());
} 
function importanceOrder (marker,b) {
    return GOverlay.getZIndex(marker.getPoint().lat()) + marker.importance*1000000;
}


function drawCircle(lat, lng, radius, numPoints, map) {
    poly = [];
    //var lat = center.lat();
    //var lng = center.lng();
    var d2r = Math.PI / 180;                // degrees to radians
    var r2d = 180 / Math.PI;                // radians to degrees
    var Clat = (radius / 3963) * r2d;      //  using 3963 as earth's radius
    var Clng = Clat / Math.cos(lat * d2r);
    //alert(radius);
    //Add each point in the circle
    for (var i = 0; i < numPoints; i++) {
        var theta = Math.PI * (i / (numPoints / 2));
        Cx = lng + (Clng * Math.cos(theta));
        Cy = lat + (Clat * Math.sin(theta));
        poly.push(new GLatLng(Cy, Cx));
    }

    //Remove the old line if it exists
    //if (line) {
    //    map.removeOverlay(line);
    //}

    //Add the first point to complete the circle
    poly.push(poly[0]);

    //Create a line with teh points from poly, red, 3 pixels wide, 80% opaque
    line = new GPolygon(poly, "#ffffff", 1, 1, "#00ff00", 0.05);
    //line = new GPolyline(poly, '#FF0000', 1, 0.2);

    map.addOverlay(line);
}


//]]>
