var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var myLatLng;

function initialize() {
	directionsDisplay = new google.maps.DirectionsRenderer();
    myLatLng = new google.maps.LatLng(gmap_location[0],gmap_location[1]);
    var myOptions = {
      zoom:14,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      center: myLatLng,
      scrollwheel: false
    }
    map = new google.maps.Map(document.getElementById("gmap"), myOptions);
    
    var image = gmap_image;
    var beachMarker = new google.maps.Marker({
        position: myLatLng,
        map: map,
        icon: image
    });
    
    directionsDisplay.setMap(map);
    directionsDisplay.setPanel(document.getElementById("gdirections"));
}
  
function calcRoute() {
    var start = $('#routefrom').val().replace(/(\d{4})\W+([A-Za-z]{2})/, "$1$2");
    var end = gmap_location_name;
    var request = {
        origin:start, 
        destination:end,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
    directionsService.route(request, function(response, status) {
      if (status == google.maps.DirectionsStatus.OK) {
        directionsDisplay.setDirections(response);
      }
    });
}

$(document).ready(function() {
	initialize();
	$('#calcroute').click(function() {
		calcRoute();
	});
});
/*
document.observe('dom:loaded', function() {new GoogleMap();});
var GoogleMap = Class.create({
    initialize: function(el)
    {
        // Google map
        if ($('gmap'))
            this.loadMap();
    },
    // load Google map
    loadMap: function()
    {
        if (GBrowserIsCompatible()) {
            document.observe('unload', GUnload, false);
            // coordinates
            var coords = $('gmap').title.split(',');
            var point = new GLatLng(parseFloat(coords[0]), parseFloat(coords[1]));
            // display map
            var map = new GMap2($('gmap'));
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.enableScrollWheelZoom(); 
            map.setCenter(point, 14);
            // add marker
            var myIcon = new GIcon();
            myIcon.image = image_gmap;
            myIcon.iconSize = new GSize(16,16);
            myIcon.iconAnchor = new GPoint(16,16);
            map.addOverlay(new GMarker(point, myIcon));
            // add directions
            var directions = new GDirections(map, $('gdirections'));
            $('routeform').observe('submit', function(e)
            {
                var elm = Event.element(e);
                directions.load('from: ' 
                    + elm.routefrom.value.replace(/(\d{4})\W+([A-Za-z]{2})/, "$1$2")
                    + ' to: ' + elm.routeto.value, {locale: 'nl_NL'});
                Event.stop(e);
            });
        }
    }
});

*/
