function addMarkers(){
mySelect = document.getElementById('selection');
Canterbury = [];Hampton = [];Woodstock = [];Ashford = [];Brooklyn = [];Thompson = [];Moosup = [];Pomfret = [];Putnam = [];Willimantic = [];Danielson = [];North_Grosvenordale = [];mySelect.options[mySelect.options.length] = new Option("Ashford schools",'all=Ashford');
mySelect.options[mySelect.options.length] = new Option("Brooklyn schools",'all=Brooklyn');
mySelect.options[mySelect.options.length] = new Option("Canterbury schools",'all=Canterbury');
mySelect.options[mySelect.options.length] = new Option("Danielson schools",'all=Danielson');
mySelect.options[mySelect.options.length] = new Option("Hampton schools",'all=Hampton');
mySelect.options[mySelect.options.length] = new Option("Moosup schools",'all=Moosup');
mySelect.options[mySelect.options.length] = new Option("North Grosvenordale schools",'all=North_Grosvenordale');
mySelect.options[mySelect.options.length] = new Option("Pomfret schools",'all=Pomfret');
mySelect.options[mySelect.options.length] = new Option("Putnam schools",'all=Putnam');
mySelect.options[mySelect.options.length] = new Option("Thompson schools",'all=Thompson');
mySelect.options[mySelect.options.length] = new Option("Willimantic schools",'all=Willimantic');
mySelect.options[mySelect.options.length] = new Option("Woodstock schools",'all=Woodstock');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Canterbury[Canterbury.length] = createMarker(new GPoint(-71.98832300,41.70524300),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Children's Discovery Center",'Canterbury=' + Canterbury.length);
Hampton[Hampton.length] = createMarker(new GPoint(-72.05528300,41.77851400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Greenwood Sudbury School",'Hampton=' + Hampton.length);
Woodstock[Woodstock.length] = createMarker(new GPoint(-71.99430000,41.95980000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hyde School",'Woodstock=' + Woodstock.length);
Ashford[Ashford.length] = createMarker(new GPoint(-72.21103900,41.91560300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Kidderbrook Montessori School",'Ashford=' + Ashford.length);
Brooklyn[Brooklyn.length] = createMarker(new GPoint(-71.95367800,41.80896300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Learning Clinic Inc (the)",'Brooklyn=' + Brooklyn.length);
Thompson[Thompson.length] = createMarker(new GPoint(-71.86126400,41.96046100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Marianapolis Preparatory School",'Thompson=' + Thompson.length);
Moosup[Moosup.length] = createMarker(new GPoint(-71.88593700,41.71335200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Plainfield Catholic School",'Moosup=' + Moosup.length);
Pomfret[Pomfret.length] = createMarker(new GPoint(-71.96010900,41.89768900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Pomfret School",'Pomfret=' + Pomfret.length);
Putnam[Putnam.length] = createMarker(new GPoint(-71.91292500,41.91563900),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Putnum Science Academy",'Putnam=' + Putnam.length);
Pomfret[Pomfret.length] = createMarker(new GPoint(-71.95916200,41.89777900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Rectory School",'Pomfret=' + Pomfret.length);
Willimantic[Willimantic.length] = createMarker(new GPoint(-72.20861300,41.71300200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Mary St. Joseph School",'Willimantic=' + Willimantic.length);
Putnam[Putnam.length] = createMarker(new GPoint(-71.91252200,41.92344400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Mary School",'Putnam=' + Putnam.length);
Danielson[Danielson.length] = createMarker(new GPoint(-71.88547100,41.80235300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St James School",'Danielson=' + Danielson.length);
North_Grosvenordale[North_Grosvenordale.length] = createMarker(new GPoint(-71.90220300,41.97924000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Joseph School",'North_Grosvenordale=' + North_Grosvenordale.length);
Putnam[Putnam.length] = createMarker(new GPoint(-71.81783800,41.91257000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Tri-state Christian Academy",'Putnam=' + Putnam.length);
Willimantic[Willimantic.length] = createMarker(new GPoint(-72.20301800,41.70766600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Windham Christian Academy",'Willimantic=' + Willimantic.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/////3/' + showArray);
map.removeOverlays(Ashford);
map.removeOverlays(Brooklyn);
map.removeOverlays(Canterbury);
map.removeOverlays(Danielson);
map.removeOverlays(Hampton);
map.removeOverlays(Moosup);
map.removeOverlays(North_Grosvenordale);
map.removeOverlays(Pomfret);
map.removeOverlays(Putnam);
map.removeOverlays(Thompson);
map.removeOverlays(Willimantic);
map.removeOverlays(Woodstock);
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(Canterbury);map.removeOverlays(Ashford);
map.removeOverlays(Brooklyn);
map.removeOverlays(Canterbury);
map.removeOverlays(Danielson);
map.removeOverlays(Hampton);
map.removeOverlays(Moosup);
map.removeOverlays(North_Grosvenordale);
map.removeOverlays(Pomfret);
map.removeOverlays(Putnam);
map.removeOverlays(Thompson);
map.removeOverlays(Willimantic);
map.removeOverlays(Woodstock);
map.addOverlays(Ashford);
centerByArray(Ashford, false, false);
cntMarker += Ashford.length;
map.addOverlays(Brooklyn);
centerByArray(Brooklyn, false, false);
cntMarker += Brooklyn.length;
map.addOverlays(Canterbury);
centerByArray(Canterbury, false, false);
cntMarker += Canterbury.length;
map.addOverlays(Danielson);
centerByArray(Danielson, false, false);
cntMarker += Danielson.length;
map.addOverlays(Hampton);
centerByArray(Hampton, false, false);
cntMarker += Hampton.length;
map.addOverlays(Moosup);
centerByArray(Moosup, false, false);
cntMarker += Moosup.length;
map.addOverlays(North_Grosvenordale);
centerByArray(North_Grosvenordale, false, false);
cntMarker += North_Grosvenordale.length;
map.addOverlays(Pomfret);
centerByArray(Pomfret, false, false);
cntMarker += Pomfret.length;
map.addOverlays(Putnam);
centerByArray(Putnam, false, false);
cntMarker += Putnam.length;
map.addOverlays(Thompson);
centerByArray(Thompson, false, false);
cntMarker += Thompson.length;
map.addOverlays(Willimantic);
centerByArray(Willimantic, false, false);
cntMarker += Willimantic.length;
map.addOverlays(Woodstock);
centerByArray(Woodstock, false, false);
cntMarker += Woodstock.length;
centerByArray(Canterbury,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=3&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;
}