function addMarkers(){
mySelect = document.getElementById('selection');
Baltic = [];Milford = [];Greenwich = [];Simsbury = [];Hartford = [];Middletown = [];Farmington = [];Hamden = [];Stamford = [];Waterbury = [];Manchester = [];Litchfield = [];Middlebury = [];mySelect.options[mySelect.options.length] = new Option("Baltic schools",'all=Baltic');
mySelect.options[mySelect.options.length] = new Option("Farmington schools",'all=Farmington');
mySelect.options[mySelect.options.length] = new Option("Greenwich schools",'all=Greenwich');
mySelect.options[mySelect.options.length] = new Option("Hamden schools",'all=Hamden');
mySelect.options[mySelect.options.length] = new Option("Hartford schools",'all=Hartford');
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("Middlebury schools",'all=Middlebury');
mySelect.options[mySelect.options.length] = new Option("Middletown schools",'all=Middletown');
mySelect.options[mySelect.options.length] = new Option("Milford schools",'all=Milford');
mySelect.options[mySelect.options.length] = new Option("Simsbury schools",'all=Simsbury');
mySelect.options[mySelect.options.length] = new Option("Stamford schools",'all=Stamford');
mySelect.options[mySelect.options.length] = new Option("Waterbury schools",'all=Waterbury');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Baltic[Baltic.length] = createMarker(new GPoint(-72.08453500,41.61682500),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Academy Of The Holy Family",'Baltic=' + Baltic.length);
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);
Greenwich[Greenwich.length] = createMarker(new GPoint(-73.69725500,41.06922700),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Convent Of The Sacred Heart",'Greenwich=' + Greenwich.length);
Simsbury[Simsbury.length] = createMarker(new GPoint(-72.83537300,41.84930200),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Ethel Walker School",'Simsbury=' + Simsbury.length);
Hartford[Hartford.length] = createMarker(new GPoint(-72.68368300,41.77019600),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Gray Lodge School",'Hartford=' + Hartford.length);
Greenwich[Greenwich.length] = createMarker(new GPoint(-73.62525700,41.04169300),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Greenwich Academy",'Greenwich=' + Greenwich.length);
Middletown[Middletown.length] = createMarker(new GPoint(-72.67520300,41.53135400),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Mercy High School",'Middletown=' + Middletown.length);
Farmington[Farmington.length] = createMarker(new GPoint(-72.82930500,41.72230500),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Miss Porter's School",'Farmington=' + Farmington.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);
Stamford[Stamford.length] = createMarker(new GPoint(-73.53355400,41.06674600),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Sacred Heart Academy Of Stamford",'Stamford=' + Stamford.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);
Manchester[Manchester.length] = createMarker(new GPoint(-72.52265200,41.76442100),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Summit School/new Hope Manor",'Manchester=' + Manchester.length);
Litchfield[Litchfield.length] = createMarker(new GPoint(-73.15012400,41.75766700),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Touchstone School",'Litchfield=' + Litchfield.length);
Middlebury[Middlebury.length] = createMarker(new GPoint(-73.12313800,41.52724400),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Westover School",'Middlebury=' + Middlebury.length);
map.removeOverlays(Baltic);
map.removeOverlays(Farmington);
map.removeOverlays(Greenwich);
map.removeOverlays(Hamden);
map.removeOverlays(Hartford);
map.removeOverlays(Litchfield);
map.removeOverlays(Manchester);
map.removeOverlays(Middlebury);
map.removeOverlays(Middletown);
map.removeOverlays(Milford);
map.removeOverlays(Simsbury);
map.removeOverlays(Stamford);
map.removeOverlays(Waterbury);
setTimeout(function(){map.addOverlays(Baltic)},1000);
setTimeout(function(){map.addOverlays(Farmington)},1000);
setTimeout(function(){map.addOverlays(Greenwich)},1000);
setTimeout(function(){map.addOverlays(Hamden)},1000);
setTimeout(function(){map.addOverlays(Hartford)},1000);
setTimeout(function(){map.addOverlays(Litchfield)},1000);
setTimeout(function(){map.addOverlays(Manchester)},1000);
setTimeout(function(){map.addOverlays(Middlebury)},1000);
setTimeout(function(){map.addOverlays(Middletown)},1000);
setTimeout(function(){map.addOverlays(Milford)},1000);
setTimeout(function(){map.addOverlays(Simsbury)},1000);
setTimeout(function(){map.addOverlays(Stamford)},1000);
setTimeout(function(){map.addOverlays(Waterbury)},1000);
maxLng = -72.08453500;
maxLat = 41.84930200;
minLng = -81.71043400;
minLat = 33.52344900;
reCenterMap();
} // 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//////' + showArray);
map.removeOverlays(Baltic);
map.removeOverlays(Farmington);
map.removeOverlays(Greenwich);
map.removeOverlays(Hamden);
map.removeOverlays(Hartford);
map.removeOverlays(Litchfield);
map.removeOverlays(Manchester);
map.removeOverlays(Middlebury);
map.removeOverlays(Middletown);
map.removeOverlays(Milford);
map.removeOverlays(Simsbury);
map.removeOverlays(Stamford);
map.removeOverlays(Waterbury);
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(Baltic);map.removeOverlays(Baltic);
map.removeOverlays(Farmington);
map.removeOverlays(Greenwich);
map.removeOverlays(Hamden);
map.removeOverlays(Hartford);
map.removeOverlays(Litchfield);
map.removeOverlays(Manchester);
map.removeOverlays(Middlebury);
map.removeOverlays(Middletown);
map.removeOverlays(Milford);
map.removeOverlays(Simsbury);
map.removeOverlays(Stamford);
map.removeOverlays(Waterbury);
map.addOverlays(Baltic);
centerByArray(Baltic, false, false);
cntMarker += Baltic.length;
map.addOverlays(Farmington);
centerByArray(Farmington, false, false);
cntMarker += Farmington.length;
map.addOverlays(Greenwich);
centerByArray(Greenwich, false, false);
cntMarker += Greenwich.length;
map.addOverlays(Hamden);
centerByArray(Hamden, false, false);
cntMarker += Hamden.length;
map.addOverlays(Hartford);
centerByArray(Hartford, false, false);
cntMarker += Hartford.length;
map.addOverlays(Litchfield);
centerByArray(Litchfield, false, false);
cntMarker += Litchfield.length;
map.addOverlays(Manchester);
centerByArray(Manchester, false, false);
cntMarker += Manchester.length;
map.addOverlays(Middlebury);
centerByArray(Middlebury, false, false);
cntMarker += Middlebury.length;
map.addOverlays(Middletown);
centerByArray(Middletown, false, false);
cntMarker += Middletown.length;
map.addOverlays(Milford);
centerByArray(Milford, false, false);
cntMarker += Milford.length;
map.addOverlays(Simsbury);
centerByArray(Simsbury, false, false);
cntMarker += Simsbury.length;
map.addOverlays(Stamford);
centerByArray(Stamford, false, false);
cntMarker += Stamford.length;
map.addOverlays(Waterbury);
centerByArray(Waterbury, false, false);
cntMarker += Waterbury.length;
centerByArray(Baltic,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///5272,5388,5306,35605,5433,5332,34877,5558,5600,5386,5271,5319,5434,25761,5306,35605,5319,/all');
//window.open('/map.php?type=2&schools=5272,5388,5306,35605,5433,5332,34877,5558,5600,5386,5271,5319,5434,25761,5306,35605,5319,&school_level=&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;
}