function addMarkers(){
mySelect = document.getElementById('selection');
Milford = [];West_Haven = [];Hamden = [];Waterbury = [];Cheshire = [];New_Haven = [];Wallingford = [];Meriden = [];North_Haven = [];Madison = [];Orange = [];Middlebury = [];mySelect.options[mySelect.options.length] = new Option("Cheshire schools",'all=Cheshire');
mySelect.options[mySelect.options.length] = new Option("Hamden schools",'all=Hamden');
mySelect.options[mySelect.options.length] = new Option("Madison schools",'all=Madison');
mySelect.options[mySelect.options.length] = new Option("Meriden schools",'all=Meriden');
mySelect.options[mySelect.options.length] = new Option("Middlebury schools",'all=Middlebury');
mySelect.options[mySelect.options.length] = new Option("Milford schools",'all=Milford');
mySelect.options[mySelect.options.length] = new Option("New Haven schools",'all=New_Haven');
mySelect.options[mySelect.options.length] = new Option("North Haven schools",'all=North_Haven');
mySelect.options[mySelect.options.length] = new Option("Orange schools",'all=Orange');
mySelect.options[mySelect.options.length] = new Option("Wallingford schools",'all=Wallingford');
mySelect.options[mySelect.options.length] = new Option("Waterbury schools",'all=Waterbury');
mySelect.options[mySelect.options.length] = new Option("West Haven schools",'all=West_Haven');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Milford[Milford.length] = createMarker(new GPoint(-73.06204500,41.22420200),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Academy Of Our Lady Of Mercy, Lauralton Hall",'Milford=' + Milford.length);
West_Haven[West_Haven.length] = createMarker(new GPoint(-72.98115200,41.26943100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Benhaven School",'West_Haven=' + West_Haven.length);
Milford[Milford.length] = createMarker(new GPoint(-73.01317400,41.22669900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Berean Christian Academy",'Milford=' + Milford.length);
Hamden[Hamden.length] = createMarker(new GPoint(-72.91932600,41.33529400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Cedarhurst School",'Hamden=' + Hamden.length);
Waterbury[Waterbury.length] = createMarker(new GPoint(-73.06580700,41.54737900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Chase Collegiate School",'Waterbury=' + Waterbury.length);
Cheshire[Cheshire.length] = createMarker(new GPoint(-72.90108900,41.50066200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Cheshire Academy",'Cheshire=' + Cheshire.length);
New_Haven[New_Haven.length] = createMarker(new GPoint(-72.92857200,41.28877400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Children's Community Programs Of Ct",'New_Haven=' + New_Haven.length);
Wallingford[Wallingford.length] = createMarker(new GPoint(-72.80751100,41.45667000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Choate Rosemary Hall",'Wallingford=' + Wallingford.length);
Meriden[Meriden.length] = createMarker(new GPoint(-72.80534100,41.52766100),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Curtis School",'Meriden=' + Meriden.length);
North_Haven[North_Haven.length] = createMarker(new GPoint(-72.89800400,41.35699900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Elizabeth Ives School For Special Children",'North_Haven=' + North_Haven.length);
New_Haven[New_Haven.length] = createMarker(new GPoint(-72.91979200,41.32688400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Foote School",'New_Haven=' + New_Haven.length);
Milford[Milford.length] = createMarker(new GPoint(-73.02489400,41.24023200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Foundation School",'Milford=' + Milford.length);
Madison[Madison.length] = createMarker(new GPoint(-72.60900000,41.30420000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Grove School",'Madison=' + Madison.length);
Hamden[Hamden.length] = createMarker(new GPoint(-72.91285800,41.34199900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hamden Hall School",'Hamden=' + Hamden.length);
Wallingford[Wallingford.length] = createMarker(new GPoint(-72.82335900,41.45061700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Heritage Baptist Academy",'Wallingford=' + Wallingford.length);
Wallingford[Wallingford.length] = createMarker(new GPoint(-72.80592000,41.47618700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("High Road Student Learning Center",'Wallingford=' + Wallingford.length);
Waterbury[Waterbury.length] = createMarker(new GPoint(-73.06629500,41.53131900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Holy Cross High School",'Waterbury=' + Waterbury.length);
Milford[Milford.length] = createMarker(new GPoint(-104.82510000,38.78910000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hope Academy",'Milford=' + Milford.length);
New_Haven[New_Haven.length] = createMarker(new GPoint(-72.97060200,41.31886600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hopkins School",'New_Haven=' + New_Haven.length);
Milford[Milford.length] = createMarker(new GPoint(-73.04951700,41.22224400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Milford Academy",'Milford=' + Milford.length);
Orange[Orange.length] = createMarker(new GPoint(-73.00816800,41.29892300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("New Haven Hebrew Day School",'Orange=' + Orange.length);
West_Haven[West_Haven.length] = createMarker(new GPoint(-72.96154500,41.28891800),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Notre Dame High School",'West_Haven=' + West_Haven.length);
Hamden[Hamden.length] = createMarker(new GPoint(-72.93215300,41.36503700),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Sacred Heart Academy",'Hamden=' + Hamden.length);
Waterbury[Waterbury.length] = createMarker(new GPoint(-73.03798900,41.55165800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Sacred Heart High School",'Waterbury=' + Waterbury.length);
New_Haven[New_Haven.length] = createMarker(new GPoint(-72.92150300,41.32948800),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("St. Francis Home For Children",'New_Haven=' + New_Haven.length);
Waterbury[Waterbury.length] = createMarker(new GPoint(-81.71043400,33.52344900),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Stepping Stones School",'Waterbury=' + Waterbury.length);
Cheshire[Cheshire.length] = createMarker(new GPoint(-72.91581400,41.53277700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Webb School At Cheshire",'Cheshire=' + Cheshire.length);
Hamden[Hamden.length] = createMarker(new GPoint(-72.89717800,41.33869200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("West Woods Christian Academy",'Hamden=' + Hamden.length);
Middlebury[Middlebury.length] = createMarker(new GPoint(-73.12313800,41.52724400),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Westover School",'Middlebury=' + Middlebury.length);
New_Haven[New_Haven.length] = createMarker(new GPoint(-72.94696000,41.31673900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Yeshiva Of New Haven",'New_Haven=' + New_Haven.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(Cheshire);
map.removeOverlays(Hamden);
map.removeOverlays(Madison);
map.removeOverlays(Meriden);
map.removeOverlays(Middlebury);
map.removeOverlays(Milford);
map.removeOverlays(New_Haven);
map.removeOverlays(North_Haven);
map.removeOverlays(Orange);
map.removeOverlays(Wallingford);
map.removeOverlays(Waterbury);
map.removeOverlays(West_Haven);
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(Milford);map.removeOverlays(Cheshire);
map.removeOverlays(Hamden);
map.removeOverlays(Madison);
map.removeOverlays(Meriden);
map.removeOverlays(Middlebury);
map.removeOverlays(Milford);
map.removeOverlays(New_Haven);
map.removeOverlays(North_Haven);
map.removeOverlays(Orange);
map.removeOverlays(Wallingford);
map.removeOverlays(Waterbury);
map.removeOverlays(West_Haven);
map.addOverlays(Cheshire);
centerByArray(Cheshire, false, false);
cntMarker += Cheshire.length;
map.addOverlays(Hamden);
centerByArray(Hamden, false, false);
cntMarker += Hamden.length;
map.addOverlays(Madison);
centerByArray(Madison, false, false);
cntMarker += Madison.length;
map.addOverlays(Meriden);
centerByArray(Meriden, false, false);
cntMarker += Meriden.length;
map.addOverlays(Middlebury);
centerByArray(Middlebury, false, false);
cntMarker += Middlebury.length;
map.addOverlays(Milford);
centerByArray(Milford, false, false);
cntMarker += Milford.length;
map.addOverlays(New_Haven);
centerByArray(New_Haven, false, false);
cntMarker += New_Haven.length;
map.addOverlays(North_Haven);
centerByArray(North_Haven, false, false);
cntMarker += North_Haven.length;
map.addOverlays(Orange);
centerByArray(Orange, false, false);
cntMarker += Orange.length;
map.addOverlays(Wallingford);
centerByArray(Wallingford, false, false);
cntMarker += Wallingford.length;
map.addOverlays(Waterbury);
centerByArray(Waterbury, false, false);
cntMarker += Waterbury.length;
map.addOverlays(West_Haven);
centerByArray(West_Haven, false, false);
cntMarker += West_Haven.length;
centerByArray(Milford,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;
}