function addMarkers(){
mySelect = document.getElementById('selection');
Antrim = [];Nashua = [];Merrimack = [];Greenfield = [];Manchester = [];Wilton = [];Hillsborough = [];Bedford = [];Milford = [];Amherst = [];Litchfield = [];Windsor = [];Peterborough = [];mySelect.options[mySelect.options.length] = new Option("Amherst schools",'all=Amherst');
mySelect.options[mySelect.options.length] = new Option("Antrim schools",'all=Antrim');
mySelect.options[mySelect.options.length] = new Option("Bedford schools",'all=Bedford');
mySelect.options[mySelect.options.length] = new Option("Greenfield schools",'all=Greenfield');
mySelect.options[mySelect.options.length] = new Option("Hillsborough schools",'all=Hillsborough');
mySelect.options[mySelect.options.length] = new Option("Litchfield schools",'all=Litchfield');
mySelect.options[mySelect.options.length] = new Option("Manchester schools",'all=Manchester');
mySelect.options[mySelect.options.length] = new Option("Merrimack schools",'all=Merrimack');
mySelect.options[mySelect.options.length] = new Option("Milford schools",'all=Milford');
mySelect.options[mySelect.options.length] = new Option("Nashua schools",'all=Nashua');
mySelect.options[mySelect.options.length] = new Option("Peterborough schools",'all=Peterborough');
mySelect.options[mySelect.options.length] = new Option("Wilton schools",'all=Wilton');
mySelect.options[mySelect.options.length] = new Option("Windsor schools",'all=Windsor');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Antrim[Antrim.length] = createMarker(new GPoint(-71.95910000,43.05440000),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Antrim Girls' Shelter",'Antrim=' + Antrim.length);
Nashua[Nashua.length] = createMarker(new GPoint(-71.47607500,42.73766300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Bishop Guertin High School",'Nashua=' + Nashua.length);
Merrimack[Merrimack.length] = createMarker(new GPoint(-71.49841900,42.86230800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Brentwood School",'Merrimack=' + Merrimack.length);
Nashua[Nashua.length] = createMarker(new GPoint(-71.47816000,42.78260900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Christian Bible Church Academy",'Nashua=' + Nashua.length);
Greenfield[Greenfield.length] = createMarker(new GPoint(-71.87923400,42.97841000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Crotched Mtn Rehab Center",'Greenfield=' + Greenfield.length);
Manchester[Manchester.length] = createMarker(new GPoint(-71.45984400,43.03459600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Derryfield School",'Manchester=' + Manchester.length);
Wilton[Wilton.length] = createMarker(new GPoint(-71.75504400,42.81842700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("High Mowing School",'Wilton=' + Wilton.length);
Hillsborough[Hillsborough.length] = createMarker(new GPoint(-71.95135100,43.11676500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hillsboro Christian School",'Hillsborough=' + Hillsborough.length);
Bedford[Bedford.length] = createMarker(new GPoint(-71.47949000,42.93954800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Kellogg Elementary School",'Bedford=' + Bedford.length);
Antrim[Antrim.length] = createMarker(new GPoint(-71.97854900,43.08347100),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Maharishi Academy of Total Knowledge",'Antrim=' + Antrim.length);
Milford[Milford.length] = createMarker(new GPoint(-71.67308400,42.84014500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Milford Christian Academy",'Milford=' + Milford.length);
Manchester[Manchester.length] = createMarker(new GPoint(-71.45791700,42.96087400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mount Zion Christian Schools",'Manchester=' + Manchester.length);
Nashua[Nashua.length] = createMarker(new GPoint(-71.46665600,42.77696300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Nashua Catholic Regional Jr High School",'Nashua=' + Nashua.length);
Nashua[Nashua.length] = createMarker(new GPoint(-71.47069300,42.76318900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Nashua Christian Academy",'Nashua=' + Nashua.length);
Manchester[Manchester.length] = createMarker(new GPoint(-71.45814500,42.99373700),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Nfi - Midway Shelter",'Manchester=' + Manchester.length);
Manchester[Manchester.length] = createMarker(new GPoint(-71.42746600,42.97419400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Robert B Jolicoeur School",'Manchester=' + Manchester.length);
Amherst[Amherst.length] = createMarker(new GPoint(-71.62408900,42.86453000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Rsec Academy",'Amherst=' + Amherst.length);
Manchester[Manchester.length] = createMarker(new GPoint(-71.45960800,42.99455000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Joseph Regional Jr High School",'Manchester=' + Manchester.length);
Nashua[Nashua.length] = createMarker(new GPoint(-71.50830000,42.85460000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("South Merrimack Christian Academy",'Nashua=' + Nashua.length);
Amherst[Amherst.length] = createMarker(new GPoint(-71.59503800,42.81295700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Summit School",'Amherst=' + Amherst.length);
Litchfield[Litchfield.length] = createMarker(new GPoint(-71.43146200,42.80368400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Tabernacle Christian School",'Litchfield=' + Litchfield.length);
Manchester[Manchester.length] = createMarker(new GPoint(-71.43336200,42.99749500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Trinity High School",'Manchester=' + Manchester.length);
Windsor[Windsor.length] = createMarker(new GPoint(-72.01480000,43.11500000),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Wediko Childrens Services",'Windsor=' + Windsor.length);
Peterborough[Peterborough.length] = createMarker(new GPoint(-71.96562900,42.92202000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Well School",'Peterborough=' + Peterborough.length);
} // End addStateMarkers JavaScript Function
// Takes an array of markers and centers/zooms map based on marker range
function centerByArray(myArray, recenter, newMaxMin)
{
if (newMaxMin == true)
reMaxMin(myArray);
for (var i = 0; i < myArray.length; i++)
{
var markLng = myArray[i].getPoint().x;
var markLat = myArray[i].getPoint().y;
if (markLat > maxLat) maxLat = markLat;
if (markLng > maxLng) maxLng = markLng;
if (markLat < minLat) minLat = markLat;
if (markLng < minLng) minLng = markLng;
}
if (recenter)
reCenterMap();
}
// Reinit max/mins
function reMaxMin(myArray)
{
maxLng = myArray[0].getPoint().x;
maxLat = myArray[0].getPoint().y;
minLng = myArray[0].getPoint().x;
minLat = myArray[0].getPoint().y;
}
// Recenter map based on global max/mins
function reCenterMap()
{
var bounds = new GLatLngBounds();
bounds.extend(new GLatLng(minLat, minLng));
bounds.extend(new GLatLng(maxLat, maxLng));
var center_lat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) / 2.0;
var center_lng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) / 2.0;
var center = new GLatLng(center_lat, center_lng);
var zoom = map.getBoundsZoomLevel(bounds);
map.setCenter(center,zoom);
//map.setCenter(center,11);
/*
var center = new GPoint( (maxLng + minLng)/2, (maxLat+minLat)/2 );
var delta = new GSize(maxLng - minLng, maxLat - minLat);
var minZoom = map.spec.getLowestZoomLevel(center, delta, map.viewSize);
if (minZoom < 4) minZoom = 4; // Lowest possible zoom is 4
map.centerAndZoom(center, minZoom);
*/
}
// Fires when drop down list of schools changes
function selectChange(selection)
{
var myVal = selection.options[selection.selectedIndex].value;
map.closeInfoWindow();
// Add entire array based on variable type
if (myVal.indexOf('all') != -1 && myVal != 'all')
{
var temp = myVal.split('=');
var showArray = temp[1];
// If Array is > X amount of markers, then open in a new page
if (eval(showArray).length > 20)
// New window depends on whether or not we're on the search page
if (location.href.indexOf('nearby_schools.php') == -1)
window.open(location.href + '/map/' + showArray);
else
window.open('/search/////2/' + showArray);
map.removeOverlays(Amherst);
map.removeOverlays(Antrim);
map.removeOverlays(Bedford);
map.removeOverlays(Greenfield);
map.removeOverlays(Hillsborough);
map.removeOverlays(Litchfield);
map.removeOverlays(Manchester);
map.removeOverlays(Merrimack);
map.removeOverlays(Milford);
map.removeOverlays(Nashua);
map.removeOverlays(Peterborough);
map.removeOverlays(Wilton);
map.removeOverlays(Windsor);
map.addOverlays(eval(showArray));
centerByArray(eval(showArray), true, true); // Center and zoom on set of markers
}
// Add individual markers
if (myVal.indexOf('all') == -1 && myVal != 'all' && myVal.length)
{
var temp = myVal.split('=');
var myArray = temp[0];
var myIndex = parseInt(temp[1]) - 1;
document.getElementById('map').width = "750";
map.removeOverlay(eval(myArray)[myIndex]);
map.addOverlay(eval(myArray)[myIndex]);
GEvent.trigger(eval(myArray)[myIndex],'click');
}
// Show all markers
if (myVal == 'all')
{
cntMarker = 0;
reMaxMin(Antrim);map.removeOverlays(Amherst);
map.removeOverlays(Antrim);
map.removeOverlays(Bedford);
map.removeOverlays(Greenfield);
map.removeOverlays(Hillsborough);
map.removeOverlays(Litchfield);
map.removeOverlays(Manchester);
map.removeOverlays(Merrimack);
map.removeOverlays(Milford);
map.removeOverlays(Nashua);
map.removeOverlays(Peterborough);
map.removeOverlays(Wilton);
map.removeOverlays(Windsor);
map.addOverlays(Amherst);
centerByArray(Amherst, false, false);
cntMarker += Amherst.length;
map.addOverlays(Antrim);
centerByArray(Antrim, false, false);
cntMarker += Antrim.length;
map.addOverlays(Bedford);
centerByArray(Bedford, false, false);
cntMarker += Bedford.length;
map.addOverlays(Greenfield);
centerByArray(Greenfield, false, false);
cntMarker += Greenfield.length;
map.addOverlays(Hillsborough);
centerByArray(Hillsborough, false, false);
cntMarker += Hillsborough.length;
map.addOverlays(Litchfield);
centerByArray(Litchfield, false, false);
cntMarker += Litchfield.length;
map.addOverlays(Manchester);
centerByArray(Manchester, false, false);
cntMarker += Manchester.length;
map.addOverlays(Merrimack);
centerByArray(Merrimack, false, false);
cntMarker += Merrimack.length;
map.addOverlays(Milford);
centerByArray(Milford, false, false);
cntMarker += Milford.length;
map.addOverlays(Nashua);
centerByArray(Nashua, false, false);
cntMarker += Nashua.length;
map.addOverlays(Peterborough);
centerByArray(Peterborough, false, false);
cntMarker += Peterborough.length;
map.addOverlays(Wilton);
centerByArray(Wilton, false, false);
cntMarker += Wilton.length;
map.addOverlays(Windsor);
centerByArray(Windsor, false, false);
cntMarker += Windsor.length;
centerByArray(Antrim,true, false);
if (cntMarker > 20)
// New window depends on whether or not we're on the search page
if (location.href.indexOf('schools-by-distance') == -1)
window.open(location.href + '/map/all');
else
window.open('/search////all');
//window.open('/map.php?type=1&schools=&school_level=2&radius=&zipcode=&school_type_search=&school_type_code=');
}
}
function createMarker(point, label, icon)
{
var marker = new GMarker(point, icon);
var html = label;
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}