﻿function init_map() {
    if (GBrowserIsCompatible()) {
        pics = data.properties;
        map = new GMap2(document.getElementById('map_canvas'));
        var latlng = new GLatLng(maplat, maplng);
        map.setMapType(G_PHYSICAL_MAP);
        map.setCenter(latlng, mapzoom);
        map.addControl(new customControls());
        var icon = new GIcon(G_DEFAULT_ICON);
        icon.iconSize = new GSize(23, 31);
        icon.iconAnchor = new GPoint(12, 32);
        icon.infoWindowAnchor = new GPoint(7, 34);
        icon.image = "/img/buttons/map-arrow.png";
        icon.shadow = null;
        var type = 1;
        function createMarker(point) {
            var marker = new GMarker(point, { icon: icon });
            var fn = markerClickFn(pics[0], latlng, marker);
            GEvent.addListener(marker, "click", fn);
            return marker;
        }
        var marker = createMarker(latlng);
        map.addOverlay(marker);
    }
}

function markerClickFn(pic, latlng, marker) {
    return function() {
        var title = pic.servicecode;
        var nights = pic.nights;

        marker.openExtInfoWindow(
			map,
			"mapInfo",
			"<div>Loading...</div>",
			{ ajaxUrl: "/propinfocontent.aspx?duration=" + nights + "&prop=" + title,
			    beakOffset: 5
			}
		);
    };
}