
// Create VARIABLES. They need to be outside the load function, so all Javascript functions refer to the same stuff.
var map;
var geoxml;
var marker_boxes = document.getElementsByName("markers");
var campsite_chk_boxes = document.getElementsByName("campsite_chk");

// These are for arrays, to push into, so things can be remembered and thereby cleared or added in bulk.
var placemarkers = [];
var markers_array = [];
var campsite_polys = [];

// Define the nature of the little red icon that will be used for the markers.
var redIcon = new GIcon();
redIcon.image = "/images/mm_20_red.png";
redIcon.shadow = "/images/mm_20_shadow.png";
redIcon.iconSize = new GSize(12, 20);
redIcon.shadowSize = new GSize(22, 20);
redIcon.iconAnchor = new GPoint(6, 20);
redIcon.infoWindowAnchor = new GPoint(5, 20);





// Define the  polygons, which will later be added to the map.
// Define here, outside the map load function, 
// so that they are global variables that can be called by the HTML checkboxes.

// DEFINE CAMP SITES
// ########### North_of_Epping_2 ###############
var points = [ 
new GLatLng(51.709084,0.120040),
new GLatLng(51.709225,0.121011),
new GLatLng(51.709129,0.121150),
new GLatLng(51.708775,0.121359),
new GLatLng(51.708431,0.120871),
new GLatLng(51.708160,0.120989),
new GLatLng(51.707836,0.120447),
new GLatLng(51.709084,0.120040)
];
var North_of_Epping_2 = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6);
GEvent.addListener(North_of_Epping_2, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>North of Epping (2)</H3>Permanent site for 6 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.709084,0.120040);
var marker_North_of_Epping_2 = createCampsiteMarker(point,'<H3>North of Epping (2)</H3>Permanent site for 6 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');


// ########### North_of_Epping_1 ###############
var points = [ 
new GLatLng(51.708694,0.118173),
new GLatLng(51.708935,0.118784),
new GLatLng(51.708244,0.119331),
new GLatLng(51.707954,0.118752),
new GLatLng(51.708694,0.118173)
];
var North_of_Epping_1 = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(North_of_Epping_1, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>North of Epping (1)</H3>Permanent site for 4 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.708694,0.118173);
var marker_North_of_Epping_1 = createCampsiteMarker(point,'<H3>North of Epping (1)</H3>Permanent site for 4 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');


// ########### Lindsey_Street ###############
var points = [ 
new GLatLng(51.708485,0.109311),
new GLatLng(51.708717,0.109010),
new GLatLng(51.708763,0.109107),
new GLatLng(51.709438,0.108383),
new GLatLng(51.709332,0.108211),
new GLatLng(51.709362,0.108141),
new GLatLng(51.709312,0.107975),
new GLatLng(51.709473,0.107728),
new GLatLng(51.709576,0.107347),
new GLatLng(51.709488,0.107272),
new GLatLng(51.709438,0.107267),
new GLatLng(51.709656,0.106661),
new GLatLng(51.709621,0.106618),
new GLatLng(51.709648,0.106564),
new GLatLng(51.709396,0.106344),
new GLatLng(51.709213,0.106114),
new GLatLng(51.709133,0.106033),
new GLatLng(51.709091,0.106049),
new GLatLng(51.709007,0.106055),
new GLatLng(51.708889,0.105931),
new GLatLng(51.708862,0.106065),
new GLatLng(51.708771,0.106130),
new GLatLng(51.708298,0.106618),
new GLatLng(51.708054,0.106859),
new GLatLng(51.708221,0.107621),
new GLatLng(51.708580,0.108544),
new GLatLng(51.708294,0.109059),
new GLatLng(51.708485,0.109311)
];
var Lindsey_Street = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(Lindsey_Street, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>Lindsey Street - Epping</H3>Permanent site for 15 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.708485,0.109311);
var marker_Lindsey_Street = createCampsiteMarker(point,'<H3>Lindsey Street - Epping</H3>Permanent site for 15 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');



// ########### West_of_Epping_Green ###############
var points = [ 
new GLatLng(51.723022,0.070649),
new GLatLng(51.722324,0.067624),
new GLatLng(51.722095,0.067720),
new GLatLng(51.721806,0.066379),
new GLatLng(51.721287,0.066658),
new GLatLng(51.721386,0.067291),
new GLatLng(51.721031,0.067334),
new GLatLng(51.721573,0.070413),
new GLatLng(51.722012,0.071014),
new GLatLng(51.722694,0.071089),
new GLatLng(51.722569,0.072162),
new GLatLng(51.722713,0.072227),
new GLatLng(51.722713,0.075510),
new GLatLng(51.723427,0.075349),
new GLatLng(51.723408,0.073997),
new GLatLng(51.723640,0.073879),
new GLatLng(51.723644,0.073535),
new GLatLng(51.723930,0.073171),
new GLatLng(51.724152,0.072999),
new GLatLng(51.724323,0.072935),
new GLatLng(51.724628,0.072913),
new GLatLng(51.723347,0.070757),
new GLatLng(51.723022,0.070649)
];
var West_of_Epping_Green = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(West_of_Epping_Green, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>West of Epping Green</H3>Permanent site for 15 pitches plus paddock<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.723022,0.070649);
var marker_West_of_Epping_Green = createCampsiteMarker(point,'<H3>West of Epping Green</H3>Permanent site for 15 pitches plus paddock<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');


// ########### East_of_Epping_Green ###############
var points = [ 
new GLatLng(51.727837,0.078055),
new GLatLng(51.727833,0.078154),
new GLatLng(51.727966,0.078530),
new GLatLng(51.727882,0.078616),
new GLatLng(51.727882,0.078723),
new GLatLng(51.727840,0.078835),
new GLatLng(51.727985,0.079385),
new GLatLng(51.728100,0.079377),
new GLatLng(51.728210,0.079812),
new GLatLng(51.727962,0.079981),
new GLatLng(51.727650,0.078935),
new GLatLng(51.727814,0.078723),
new GLatLng(51.727821,0.078492),
new GLatLng(51.727760,0.078125),
new GLatLng(51.727837,0.078055)
];
var East_of_Epping_Green = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(East_of_Epping_Green, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>East of Epping Green</H3>Permanent site for 2 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.727837,0.078055);
var marker_East_of_Epping_Green = createCampsiteMarker(point,'<H3>East of Epping Green</H3>Permanent site for 2 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');


// ########### Duck_Lane ###############
var points = [ 
new GLatLng(51.719215,0.132195),
new GLatLng(51.719040,0.133386),
new GLatLng(51.718876,0.133209),
new GLatLng(51.718697,0.133182),
new GLatLng(51.718613,0.133236),
new GLatLng(51.718479,0.133542),
new GLatLng(51.718487,0.133654),
new GLatLng(51.718414,0.133644),
new GLatLng(51.718399,0.133821),
new GLatLng(51.718414,0.134051),
new GLatLng(51.717777,0.133987),
new GLatLng(51.717873,0.133279),
new GLatLng(51.718163,0.133134),
new GLatLng(51.718529,0.132823),
new GLatLng(51.718739,0.132641),
new GLatLng(51.718884,0.132351),
new GLatLng(51.718925,0.132335),
new GLatLng(51.719120,0.132136),
new GLatLng(51.719215,0.132195)
];
var Duck_Lane = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(Duck_Lane, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>East of Thornwood - Duck Lane</H3>Permanent site for 8 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.719215,0.132195);
var marker_Duck_Lane = createCampsiteMarker(point,'<H3>East of Thornwood - Duck Lane</H3>Permanent site for 8 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');


// ########### Woodside_Thornwood ###############
var points = [ 
new GLatLng(51.715027,0.137474),
new GLatLng(51.714752,0.138767),
new GLatLng(51.714504,0.138659),
new GLatLng(51.714436,0.138863),
new GLatLng(51.714390,0.139346),
new GLatLng(51.713936,0.139142),
new GLatLng(51.713917,0.138885),
new GLatLng(51.714115,0.138144),
new GLatLng(51.713661,0.137753),
new GLatLng(51.714195,0.136798),
new GLatLng(51.715027,0.137474)
];
var Woodside_Thornwood = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(Woodside_Thornwood, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>Rear of Forest House, Woodside - Thornwood</H3>Permanent site for 10 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.715027,0.137474);
var marker_Woodside_Thornwood = createCampsiteMarker(point,'<H3>Rear of Forest House, Woodside - Thornwood</H3>Permanent site for 10 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');



// ########### Upland_Lane ###############
var points = [ 
new GLatLng(51.726021,0.125291),
new GLatLng(51.725445,0.125737),
new GLatLng(51.725410,0.125635),
new GLatLng(51.725304,0.125731),
new GLatLng(51.725163,0.125259),
new GLatLng(51.724789,0.125549),
new GLatLng(51.724922,0.126037),
new GLatLng(51.724342,0.126493),
new GLatLng(51.724041,0.124991),
new GLatLng(51.724174,0.124900),
new GLatLng(51.724426,0.124814),
new GLatLng(51.724594,0.124653),
new GLatLng(51.724930,0.124369),
new GLatLng(51.725155,0.125087),
new GLatLng(51.725861,0.124648),
new GLatLng(51.726021,0.125291)
];
var Upland_Lane = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(Upland_Lane, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>North of Thornwood - Upland Lane</H3>Permanent site for 8 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.726021,0.125291);
var marker_Upland_Lane = createCampsiteMarker(point,'<H3>North of Thornwood - Upland Lane</H3>Permanent site for 8 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');


// ########### Rye_Hall_Road ###############
var points = [ 
new GLatLng(51.730484,0.121568),
new GLatLng(51.730724,0.122550),
new GLatLng(51.730068,0.122765),
new GLatLng(51.730186,0.123392),
new GLatLng(51.730076,0.123441),
new GLatLng(51.730007,0.123301),
new GLatLng(51.729946,0.123269),
new GLatLng(51.729912,0.123215),
new GLatLng(51.729824,0.123237),
new GLatLng(51.729813,0.123323),
new GLatLng(51.729729,0.123403),
new GLatLng(51.729671,0.123500),
new GLatLng(51.729618,0.123543),
new GLatLng(51.729488,0.121976),
new GLatLng(51.730484,0.121568)
];
var Rye_Hall_Road = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(Rye_Hall_Road, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>North of Thornwood - Rye Hall Road</H3>Permanent site for 8 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.730484,0.121568);
var marker_Rye_Hall_Road = createCampsiteMarker(point,'<H3>North of Thornwood - Rye Hall Road</H3>Permanent site for 8 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');


// ########### Tylers_Green ###############
var points = [ 
new GLatLng(51.725899,0.173882),
new GLatLng(51.725113,0.173625),
new GLatLng(51.724361,0.173668),
new GLatLng(51.724045,0.174783),
new GLatLng(51.723743,0.176296),
new GLatLng(51.723537,0.177594),
new GLatLng(51.724583,0.178174),
new GLatLng(51.725273,0.175620),
new GLatLng(51.725899,0.173882)
];
var Tylers_Green = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(Tylers_Green, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>West of Tylers Green</H3>Permanent site for 8 pitches plus paddock<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.725899,0.173882);
var marker_Tylers_Green = createCampsiteMarker(point,'<H3>West of Tylers Green</H3>Permanent site for 8 pitches plus paddock<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');



// ########### Merlin_Way_Perm_Perm ###############
var points = [ 
new GLatLng(51.719715,0.161297),
new GLatLng(51.720043,0.162048),
new GLatLng(51.719700,0.162027),
new GLatLng(51.718754,0.162510),
new GLatLng(51.718719,0.161448),
new GLatLng(51.719021,0.161523),
new GLatLng(51.719334,0.161523),
new GLatLng(51.719715,0.161297)
];
var Merlin_Way_Perm = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(Merlin_Way_Perm, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>Merlin Way - Permanent</H3>Permanent site for 4 piches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.719715,0.161297);
var marker_Merlin_Way_Perm = createCampsiteMarker(point,'<H3>Merlin Way - Permanent</H3>Permanent site for 4 piches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');

// ########### Merlin_Way_Transit ###############
var points = [ 
new GLatLng(51.721935,0.161855),
new GLatLng(51.722496,0.161812),
new GLatLng(51.721977,0.160611),
new GLatLng(51.721752,0.160546),
new GLatLng(51.721684,0.160139),
new GLatLng(51.721500,0.160096),
new GLatLng(51.721191,0.159366),
new GLatLng(51.719730,0.161276),
new GLatLng(51.720089,0.162070),
new GLatLng(51.720699,0.162413),
new GLatLng(51.721935,0.161855)
];
var Merlin_Way_Transit = new GPolygon(points,"#990000",1,0.90,"#FF0000",0.6); 
GEvent.addListener(Merlin_Way_Transit, "click", function(point){ 
map.openInfoWindowHtml(point,'<H3>Merlin Way - Transit</H3>Emergency / Overnight Transit for 25-30 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>'); 
}); 
var point = new GLatLng(51.721935,0.161855);
var marker_Merlin_Way_Transit = createCampsiteMarker(point,'<H3>Merlin Way - Transit</H3>Emergency / Overnight Transit for 25-30 pitches<br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');




//FUNCTIONS: created outside the load function so that they are "global," and therefore available to any other function.

// This function will add a user-created marker to the already drawn map. They call this "geocoding." It inherits its "map" from
// the one that will be created by the loading function.
function showAddress(address) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
var placemarker = new GMarker(point);
placemarker.infoWindowAnchor = new GPoint(5, 0);
map.addOverlay(placemarker);
placemarker.openInfoWindowHtml('<br>' + address + '<br><br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');
GEvent.addListener(placemarker, "click", function() {
placemarker.openInfoWindowHtml('<br>' + address + '<br><br>Zoom: <a href="javascript:myzoom(+2)">In</a> - <a href="javascript:myzoom(-2)">Out</a>');
});
placemarkers.push(placemarker);
map.setCenter(point);
}
}
);
}

// Once the array has been created, I hope this can be used to "clear" the markers.
function clearplacemarkers(placemarkers){
map.closeInfoWindow();
for (var i=0;i<placemarkers.length;i++) {
map.removeOverlay(placemarkers[i]);
}
}



// This function defines the markers, adding them to the array "markers_array."
function createCampsiteMarker(point,html) {
var icon = new GIcon(redIcon);
var marker = new GMarker(point, icon);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
markers_array.push(marker);
return marker;
}


// Once the array has been created, this can be used to show the markers as a group. It also checks all the individual checkboxes as slaves of the master radio button. I'd like to get it to zoom to show all.
function showmarkers(){
map.closeInfoWindow();
for (var i=0;i<markers_array.length;i++) {
  markers_array[i].checked = true; 
  map.addOverlay(markers_array[i]);
}
for(var i = 0; i < marker_boxes.length; i++) {
  marker_boxes[i].checked = true;
} 
}


// Once the array has been created, this can be used to hide the markers as a group. It also unchecks all the individual checkboxes as slaves of the master radio button.
function hidemarkers(){
map.closeInfoWindow();
for (var i=0;i<markers_array.length;i++) {
  map.removeOverlay(markers_array[i]);
}
for(var i = 0; i < marker_boxes.length; i++) {
marker_boxes[i].checked = false;
}
}





function show_all_fountains(rionimap, markers_array) {
// Create new bounds object
var bounds = new GLatLngBounds();
// Loop through the points, extending the bounds as necessary
for (var i=0; i<markers_array.length; i++) {
bounds.extend(markers_array[i].getPoint());
}
// Find the centre of the new bounds
var lat = bounds.getSouthWest().lat() + ((bounds.getNorthEast().lat()
- bounds.getSouthWest().lat()) / 2);
var lon = bounds.getSouthWest().lng() + ((bounds.getNorthEast().lng()
- bounds.getSouthWest().lng()) / 2);
// Get the bounds zoom level
var zoom = map.getBoundsZoomLevel(bounds);
// Change the map to the new bounds values
map.setCenter(new GLatLng(lat, lon), zoom);
}


// Add clicking HTML links for markers to sidebar
function mysidebarclick(i) {
map.addOverlay(markers_array[i]);
GEvent.trigger(markers_array[i], "click");
marker_boxes[i].checked = true;
document.getElementById("markers_off").checked = false;
}




// This function is supposed to: 1) show or hide the rioni polygons according to whether the check box for Rioni is checked; 2) check or uncheck the individual boxes accordingly
function showCampsites(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
for (var i=0;i<campsite_polys.length;i++) {
map.removeOverlay(campsite_polys[i]);
}
for(var i = 0; i < campsite_chk_boxes.length; i++) {
campsite_chk_boxes[i].checked = false;
} 
} else {
for (var i=0;i<campsite_polys.length;i++) {
map.addOverlay(campsite_polys[i]);
}
for(var i = 0; i < campsite_chk_boxes.length; i++) {
campsite_chk_boxes[i].checked = true;
} 
}
}


// HTML checkboxes for the individual markers, to be placed in a sidebar

function showmarker_North_of_Epping_2(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_North_of_Epping_2);
} else {
map.addOverlay(marker_North_of_Epping_2);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_North_of_Epping_1(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_North_of_Epping_1);
} else {
map.addOverlay(marker_North_of_Epping_1);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_Lindsey_Street(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_Lindsey_Street);
} else {
map.addOverlay(marker_Lindsey_Street);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_West_of_Epping_Green(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_West_of_Epping_Green);
} else {
map.addOverlay(marker_West_of_Epping_Green);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_East_of_Epping_Green(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_East_of_Epping_Green);
} else {
map.addOverlay(marker_East_of_Epping_Green);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_Duck_Lane(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_Duck_Lane);
} else {
map.addOverlay(marker_Duck_Lane);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_Woodside_Thornwood(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_Woodside_Thornwood);
} else {
map.addOverlay(marker_Woodside_Thornwood);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_Upland_Lane(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_Upland_Lane);
} else {
map.addOverlay(marker_Upland_Lane);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_Rye_Hall_Road(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_Rye_Hall_Road);
} else {
map.addOverlay(marker_Rye_Hall_Road);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_Tylers_Green(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_Tylers_Green);
} else {
map.addOverlay(marker_Tylers_Green);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_Merlin_Way_Perm(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_Merlin_Way_Perm);
} else {
map.addOverlay(marker_Merlin_Way_Perm);
}
document.getElementById("markers_off").checked = false;
}

function showmarker_Merlin_Way_Transit(elementID){
map.closeInfoWindow();
if (document.getElementById(elementID).checked==false) {
map.removeOverlay(marker_Merlin_Way_Transit);
} else {
map.addOverlay(marker_Merlin_Way_Transit);
}
document.getElementById("markers_off").checked = false;
}


//Checkboxes for the individual rioni

function showNorth_of_Epping_2(chkNorth_of_Epping_2){
map.closeInfoWindow();
if (document.getElementById(chkNorth_of_Epping_2).checked==false) {
map.removeOverlay(North_of_Epping_2);
} else {
map.addOverlay(North_of_Epping_2);
}
}

function showNorth_of_Epping_1(chkNorth_of_Epping_1){
map.closeInfoWindow();
if (document.getElementById(chkNorth_of_Epping_1).checked==false) {
map.removeOverlay(North_of_Epping_1);
} else {
map.addOverlay(North_of_Epping_1);
}
}

function showLindsey_Street(chkLindsey_Street){
map.closeInfoWindow();
if (document.getElementById(chkLindsey_Street).checked==false) {
map.removeOverlay(Lindsey_Street);
} else {
map.addOverlay(Lindsey_Street);
}
}

function showWest_of_Epping_Green(chkWest_of_Epping_Green){
map.closeInfoWindow();
if (document.getElementById(chkWest_of_Epping_Green).checked==false) {
map.removeOverlay(West_of_Epping_Green);
} else {
map.addOverlay(West_of_Epping_Green);
}
}

function showEast_of_Epping_Green(chkEast_of_Epping_Green){
map.closeInfoWindow();
if (document.getElementById(chkEast_of_Epping_Green).checked==false) {
map.removeOverlay(East_of_Epping_Green);
} else {
map.addOverlay(East_of_Epping_Green);
}
}

function showDuck_Lane(chkDuck_Lane){
map.closeInfoWindow();
if (document.getElementById(chkDuck_Lane).checked==false) {
map.removeOverlay(Duck_Lane);
} else {
map.addOverlay(Duck_Lane);
}
}

function showWoodside_Thornwood(chkWoodside_Thornwood){
map.closeInfoWindow();
if (document.getElementById(chkWoodside_Thornwood).checked==false) {
map.removeOverlay(Woodside_Thornwood);
} else {
map.addOverlay(Woodside_Thornwood);
}
}

function showUpland_Lane(chkUpland_Lane){
map.closeInfoWindow();
if (document.getElementById(chkUpland_Lane).checked==false) {
map.removeOverlay(Upland_Lane);
} else {
map.addOverlay(Upland_Lane);
}
}

function showRye_Hall_Road(Pigna){
map.closeInfoWindow();
if (document.getElementById(Pigna).checked==false) {
map.removeOverlay(Rye_Hall_Road);
} else {
map.addOverlay(Rye_Hall_Road);
}
}

function showTylers_Green(chkTylers_Green){
map.closeInfoWindow();
if (document.getElementById(chkTylers_Green).checked==false) {
map.removeOverlay(Tylers_Green);
} else {
map.addOverlay(Tylers_Green);
}
}

function showMerlin_Way_Perm(chkMerlin_Way_Perm){
map.closeInfoWindow();
if (document.getElementById(chkMerlin_Way_Perm).checked==false) {
map.removeOverlay(Merlin_Way_Perm);
} else {
map.addOverlay(Merlin_Way_Perm);
}
}

function showMerlin_Way_Transit(chkMerlin_Way_Transit){
map.closeInfoWindow();
if (document.getElementById(chkMerlin_Way_Transit).checked==false) {
map.removeOverlay(Merlin_Way_Transit);
} else {
map.addOverlay(Merlin_Way_Transit);
}
}



// attempting to "reload" whole shebang
function returntocender() {
map.setCenter(new GLatLng(51.709084,0.120040), 14);
}

//Attempting to add zooming function to info windows
 function myzoom(a) {
      map.setZoom(map.getZoom() + a);
    }




// Create the map and all its associated stuff

function load(map_init) {
	map_init_array = map_init.split(",");
	if(map_init_array[0]==''){
		map_init_array[0]=51.719715;
	}
	if(map_init_array[1]==''){
		map_init_array[1]=0.150297;
	}
	if(map_init_array[2]==''){
		map_init_array[2]=14;
	}                     
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("rionimap"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.addMapType(G_PHYSICAL_MAP);
map.setCenter(new GLatLng(map_init_array[0],map_init_array[1]), Number(map_init_array[2]),G_HYBRID_MAP);
map.getPane(G_MAP_FLOAT_SHADOW_PANE).style.visibility="hidden";
geocoder = new GClientGeocoder();

//Add the red markers
map.addOverlay(marker_North_of_Epping_2);
markers_array.push(marker_North_of_Epping_2);

map.addOverlay(marker_North_of_Epping_1);
markers_array.push(marker_North_of_Epping_1);

map.addOverlay(marker_Lindsey_Street);
markers_array.push(marker_Lindsey_Street);

map.addOverlay(marker_West_of_Epping_Green);
markers_array.push(marker_West_of_Epping_Green);

map.addOverlay(marker_East_of_Epping_Green);
markers_array.push(marker_East_of_Epping_Green);

map.addOverlay(marker_Duck_Lane);
markers_array.push(marker_Duck_Lane);

map.addOverlay(marker_Woodside_Thornwood);
markers_array.push(marker_Woodside_Thornwood);

map.addOverlay(marker_Upland_Lane);
markers_array.push(marker_Upland_Lane);

map.addOverlay(marker_Rye_Hall_Road);
markers_array.push(marker_Rye_Hall_Road);

map.addOverlay(marker_Tylers_Green);
markers_array.push(marker_Tylers_Green);

map.addOverlay(marker_Merlin_Way_Perm);
markers_array.push(marker_Merlin_Way_Perm);

map.addOverlay(marker_Merlin_Way_Transit);
markers_array.push(marker_Merlin_Way_Transit);



//add the  polygons

map.addOverlay(North_of_Epping_2);
campsite_polys.push(North_of_Epping_2);

map.addOverlay(North_of_Epping_1);
campsite_polys.push(North_of_Epping_1);

map.addOverlay(Lindsey_Street); 
campsite_polys.push(Lindsey_Street);

map.addOverlay(West_of_Epping_Green);
campsite_polys.push(West_of_Epping_Green);

map.addOverlay(East_of_Epping_Green);
campsite_polys.push(East_of_Epping_Green);

map.addOverlay(Duck_Lane);
campsite_polys.push(Duck_Lane);

map.addOverlay(Woodside_Thornwood);
campsite_polys.push(Woodside_Thornwood);

map.addOverlay(Upland_Lane);
campsite_polys.push(Upland_Lane);

map.addOverlay(Rye_Hall_Road);
campsite_polys.push(Rye_Hall_Road);

map.addOverlay(Tylers_Green);
campsite_polys.push(Tylers_Green);

map.addOverlay(Merlin_Way_Perm);
campsite_polys.push(Merlin_Way_Perm);

map.addOverlay(Merlin_Way_Transit);
campsite_polys.push(Merlin_Way_Transit);



}
}
// Those two close braces end the map creating "onload" function. Do not delete them!
//]]>
