
/*** create custom county markers **********************/

var markers = [];
var mgr;
var allmarkers = [];

function setupCountyMarkers() 
{
    map = new GMap2(document.getElementById('map_canvas'));
    map.setMapType(G_PHYSICAL_MAP);
    map.setCenter(new GLatLng(maplat, maplng), mapzoom);
    map.addControl(new customControls());
    mgr = new MarkerManager(map, { trackMarkers: true });
    allmarkers.length = 0;
    var type = 1;
    for (var i in towns) {
        var layer = towns[i];
        var markers = [];
        for (var j in layer["places"]) {
            var place = layer["places"][j];
            var title = place["name"];

            if (title == 'Exmoor' || title == 'Dartmoor' || title == 'New Forest' || title == 'Cotswolds')
            {
               
                var icon = new GIcon(G_DEFAULT_ICON);
                icon.iconSize = new GSize(14, 19);
                icon.shadow = null;
                icon.iconAnchor = new GPoint(7, 7);
                icon.infoWindowAnchor = new GPoint(2, 10);
                icon.image = "/img/buttons/tree.png";
                }
             else
             {
                 var icon = new GIcon(G_DEFAULT_ICON);
                 icon.iconSize = new GSize(14, 14);
                 icon.shadow = null;
                 icon.iconAnchor = new GPoint(7, 7);
                 icon.infoWindowAnchor = new GPoint(2, 10);
                 icon.image = "/img/buttons/mapInfo-town.png";
                }
            
            var location = place["location"];
            var image = place["image"];
            var town_search_url = place["town_search_url"];
            var cottage_search_url = place["cottage_search_url"];
            var property_number = place["property_number"];
            var posn = new GLatLng(place["posn"][0], place["posn"][1]);
            var marker = createMarker(posn, title, icon, location, image, town_search_url, cottage_search_url, property_number, map);
            markers.push(marker);
            allmarkers.push(marker);
        }

        mgr.addMarkers(markers, layer["zoom"][0], layer["zoom"][1]);
    }
    mgr.refresh();
}

function createMarker(posn, title, icon, location, image, town_search_url, cottage_search_url, property_number, map) 
{
    var marker = new GMarker(posn, { title: title, icon: icon });
    GEvent.addListener(marker, 'click', function() {
        var infoHtml = '<div class="inner"><a class="image" href="' + town_search_url + '" style="background:url(' + image + ') no-repeat left top;"></a><div class="inner-inner"><p><b><a href="' + town_search_url + '">' + title + '</a></b><br/>' + location + '<br/></p><p class="search-cottages"><a href="' + cottage_search_url + '">Search cottages</a> (' + property_number + ')</p></div></div>';
        marker.openExtInfoWindow(
			map,
			"mapInfoTown",
			infoHtml,
			{ beakOffset: 5 }
		);


    });
    return marker;
}
