﻿
/* On document ready, grab the lat and lon values we've put into hidden fields from the xslt, 
then zoom the map to the position of the lat/lon values */
$(document).ready(function() {
    var lat = $("#lat").val();
    var lon = $("#lon").val();
    var name = $("#name").val();
    ZoomToPosition(lat, lon);

    var point = new google.maps.LatLng(parseFloat(lat), parseFloat(lon));    

    var marker = new google.maps.Marker({
        position: point,        
        title: name,
        map: MYMAP.map
    });
});

var MYMAP = {
    map: null,
    bounds: null
}

/* Initialise the map object */
MYMAP.init = function(selector, latLng, zoom) {
    var myOptions = {
        zoom: zoom,
        center: latLng,        
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        disableDefaultUI: true,
        draggable: false
    }
    this.map = new google.maps.Map($(selector)[0], myOptions);
    this.bounds = new google.maps.LatLngBounds();
}

/* Zoom to the lat/lon position on the map */
function ZoomToPosition(lat, lon){
    var myLatLng = new google.maps.LatLng(lat, lon);
    MYMAP.init('#map', myLatLng, 15);
    MYMAP.map.panTo(myLatLng);
    MYMAP.map.setZoom(15);
}
