﻿//Sightings User Control functions
var geocoder = null;
var defaultZoom = 6;
var currentLat = 54.622978 //google.loader.ClientLocation.latitude;
var currentLng = -2.592773 //google.loader.ClientLocation.longitude;
var map;
// //Sightings User Control functions
        

function sightingsMapload() {
    if (GBrowserIsCompatible()) {

        sightingsMap = new GMap2(document.getElementById("sightingsMap"));
        var sightinglocation = new GLatLng(sightingLat, sightingLng);
        sightingsMap.setCenter(sightinglocation, largeMapZoom);
        sightingsMap.addControl(new GSmallMapControl());
        sightingsMap.disableDoubleClickZoom();

        GEvent.addListener(sightingsMap, "dblclick", function(overlay, latlng) {
            if (latlng) {
                sightingsMap.setCenter(sightinglocation, largeMapZoom);
            }
        });

        sightingsMapSmall = new GMap2(document.getElementById("sightingsMapSmall"));
        var locationSmall = new GLatLng(sightingLat, sightingLng);
        sightingsMapSmall.setCenter(locationSmall, smallMapZoom);
        sightingsMapSmall.disableDoubleClickZoom();
        sightingsMapSmall.disableDragging();

        var marker = createMarker(sightinglocation, birdImage, false);
        sightingsMap.addOverlay(marker);

        var markerSmall = createMarker(locationSmall, birdImage, false);
        sightingsMapSmall.addOverlay(markerSmall);

    }
}

function createMarker(latLng, iconImage, draggable) {
    if (iconImage != '') {
        var icon = new GIcon();
        icon.image = iconImage;
        icon.iconSize = new GSize(41, 52);
        icon.iconAnchor = new GPoint(27, 52);
        icon.infoWindowAnchor = new GPoint(14, 14);
        markerOptions = { icon: icon, draggable: draggable };
        var marker = new GMarker(latLng, markerOptions);

    }
    else {
        markerOptions = { draggable: draggable };
        var marker = new GMarker(latLng, markerOptions);
    }
    return marker;
}

function CommentFocus(inputId) {
    $(function() {
        $("#" + inputId).focus();
    });
}

//Sightings User Control functions
function loadSightings() {
    if (document.getElementById("map") != null) {
        map = new GMap2(document.getElementById("map"));

        var location = new GLatLng(currentLat, currentLng);
        map.setCenter(location, defaultZoom);
        map.addControl(new GSmallZoomControl3D());
        map.disableDoubleClickZoom();
    }
}

function addBirdMarker(lat, lng, customImage, sightingId, setCenter) {
    //alert("Lat: " + lat + " Lng: " + lng + " Image: " + customImage);
    map.clearOverlays();
    var latLng = new GLatLng(lat, lng);
    var marker = createMarker(latLng, customImage, false);
    map.addOverlay(marker);
    if (setCenter) {
        map.setCenter(latLng, defaultZoom);
    }

    GEvent.addListener(marker, 'click', function() {
        window.location.href = "/Sightings/SightingDetails.aspx?sightingId=" + sightingId;
    });
}
// //Sightings User Control functions

window.onload = sightingsMapload
window.unload = GUnload;   
