function addMarkers(){
mySelect = document.getElementById('selection');
Bethlehem = [];New_Milford = [];Litchfield = [];Woodbury = [];Washington = [];Washington_Depot = [];Lakeville = [];Kent = [];Northfield = [];Winsted = [];Oakville = [];Thomaston = [];Salisbury = [];South_Kent = [];Torrington = [];Watertown = [];New_Preston = [];mySelect.options[mySelect.options.length] = new Option("Bethlehem schools",'all=Bethlehem');
mySelect.options[mySelect.options.length] = new Option("Kent schools",'all=Kent');
mySelect.options[mySelect.options.length] = new Option("Lakeville schools",'all=Lakeville');
mySelect.options[mySelect.options.length] = new Option("Litchfield schools",'all=Litchfield');
mySelect.options[mySelect.options.length] = new Option("New Milford schools",'all=New_Milford');
mySelect.options[mySelect.options.length] = new Option("New Preston schools",'all=New_Preston');
mySelect.options[mySelect.options.length] = new Option("Northfield schools",'all=Northfield');
mySelect.options[mySelect.options.length] = new Option("Oakville schools",'all=Oakville');
mySelect.options[mySelect.options.length] = new Option("Salisbury schools",'all=Salisbury');
mySelect.options[mySelect.options.length] = new Option("South Kent schools",'all=South_Kent');
mySelect.options[mySelect.options.length] = new Option("Thomaston schools",'all=Thomaston');
mySelect.options[mySelect.options.length] = new Option("Torrington schools",'all=Torrington');
mySelect.options[mySelect.options.length] = new Option("Washington schools",'all=Washington');
mySelect.options[mySelect.options.length] = new Option("Washington Depot schools",'all=Washington_Depot');
mySelect.options[mySelect.options.length] = new Option("Watertown schools",'all=Watertown');
mySelect.options[mySelect.options.length] = new Option("Winsted schools",'all=Winsted');
mySelect.options[mySelect.options.length] = new Option("Woodbury schools",'all=Woodbury');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Bethlehem[Bethlehem.length] = createMarker(new GPoint(-73.20910000,41.63680000),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Arch Bridge School",'Bethlehem=' + Bethlehem.length);
New_Milford[New_Milford.length] = createMarker(new GPoint(-73.41263400,41.58564900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Canterbury School",'New_Milford=' + New_Milford.length);
New_Milford[New_Milford.length] = createMarker(new GPoint(-73.40994800,41.57129200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Connecticut Conservatory Of Th",'New_Milford=' + New_Milford.length);
Litchfield[Litchfield.length] = createMarker(new GPoint(-73.19950000,41.75260000),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Connecticut Junior Republic",'Litchfield=' + Litchfield.length);
Woodbury[Woodbury.length] = createMarker(new GPoint(-73.20484800,41.52477400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Creative Arts Studio",'Woodbury=' + Woodbury.length);
Litchfield[Litchfield.length] = createMarker(new GPoint(-73.19184500,41.75711000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Forman School",'Litchfield=' + Litchfield.length);
Washington[Washington.length] = createMarker(new GPoint(-73.30192300,41.64738300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Glenholme School",'Washington=' + Washington.length);
Washington[Washington.length] = createMarker(new GPoint(-73.31056500,41.62932900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Gunnery",'Washington=' + Washington.length);
Washington_Depot[Washington_Depot.length] = createMarker(new GPoint(-73.31840400,41.64120000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Horace Mann School John Dorr Nature Laboratory",'Washington_Depot=' + Washington_Depot.length);
Lakeville[Lakeville.length] = createMarker(new GPoint(-73.44046900,41.96427000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Hotchkiss School",'Lakeville=' + Lakeville.length);
Lakeville[Lakeville.length] = createMarker(new GPoint(-73.46703800,41.93744900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Indian Mountain School",'Lakeville=' + Lakeville.length);
Kent[Kent.length] = createMarker(new GPoint(-73.47267400,41.72670000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Kent School",'Kent=' + Kent.length);
Northfield[Northfield.length] = createMarker(new GPoint(-73.10561800,41.69797400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Litchfield Montessori School",'Northfield=' + Northfield.length);
Kent[Kent.length] = createMarker(new GPoint(-73.45540300,41.78202900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Marvelwood School",'Kent=' + Kent.length);
Washington_Depot[Washington_Depot.length] = createMarker(new GPoint(-73.29740700,41.68106300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Rumsey Hall School",'Washington_Depot=' + Washington_Depot.length);
Winsted[Winsted.length] = createMarker(new GPoint(-73.06429000,41.92281300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Anthony School",'Winsted=' + Winsted.length);
Oakville[Oakville.length] = createMarker(new GPoint(-73.08376900,41.59105000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Mary Magdalen School",'Oakville=' + Oakville.length);
Thomaston[Thomaston.length] = createMarker(new GPoint(-73.07164100,41.67506700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Thomas School",'Thomaston=' + Thomaston.length);
Salisbury[Salisbury.length] = createMarker(new GPoint(-73.39292900,42.00093800),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Salisbury School",'Salisbury=' + Salisbury.length);
South_Kent[South_Kent.length] = createMarker(new GPoint(-73.47548400,41.67641500),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("South Kent School",'South_Kent=' + South_Kent.length);
Torrington[Torrington.length] = createMarker(new GPoint(-73.12255500,41.80500900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Francis Of Assisi School",'Torrington=' + Torrington.length);
Watertown[Watertown.length] = createMarker(new GPoint(-73.11460800,41.60036600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St John The Evangelist",'Watertown=' + Watertown.length);
Torrington[Torrington.length] = createMarker(new GPoint(-73.11879000,41.80252000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Peter School",'Torrington=' + Torrington.length);
Watertown[Watertown.length] = createMarker(new GPoint(-73.12333000,41.60295900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Taft School",'Watertown=' + Watertown.length);
Torrington[Torrington.length] = createMarker(new GPoint(-73.09920100,41.80643700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Torrington Christian Academy",'Torrington=' + Torrington.length);
Litchfield[Litchfield.length] = createMarker(new GPoint(-73.15012400,41.75766700),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Touchstone School",'Litchfield=' + Litchfield.length);
Lakeville[Lakeville.length] = createMarker(new GPoint(-73.44370000,41.95390000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Town Hill School",'Lakeville=' + Lakeville.length);
New_Preston[New_Preston.length] = createMarker(new GPoint(-73.30120200,41.70256100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Washington Montessori School",'New_Preston=' + New_Preston.length);
Bethlehem[Bethlehem.length] = createMarker(new GPoint(-73.20730000,41.63960000),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("The Woodhall School",'Bethlehem=' + Bethlehem.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(Bethlehem);
map.removeOverlays(Kent);
map.removeOverlays(Lakeville);
map.removeOverlays(Litchfield);
map.removeOverlays(New_Milford);
map.removeOverlays(New_Preston);
map.removeOverlays(Northfield);
map.removeOverlays(Oakville);
map.removeOverlays(Salisbury);
map.removeOverlays(South_Kent);
map.removeOverlays(Thomaston);
map.removeOverlays(Torrington);
map.removeOverlays(Washington);
map.removeOverlays(Washington_Depot);
map.removeOverlays(Watertown);
map.removeOverlays(Winsted);
map.removeOverlays(Woodbury);
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(Bethlehem);map.removeOverlays(Bethlehem);
map.removeOverlays(Kent);
map.removeOverlays(Lakeville);
map.removeOverlays(Litchfield);
map.removeOverlays(New_Milford);
map.removeOverlays(New_Preston);
map.removeOverlays(Northfield);
map.removeOverlays(Oakville);
map.removeOverlays(Salisbury);
map.removeOverlays(South_Kent);
map.removeOverlays(Thomaston);
map.removeOverlays(Torrington);
map.removeOverlays(Washington);
map.removeOverlays(Washington_Depot);
map.removeOverlays(Watertown);
map.removeOverlays(Winsted);
map.removeOverlays(Woodbury);
map.addOverlays(Bethlehem);
centerByArray(Bethlehem, false, false);
cntMarker += Bethlehem.length;
map.addOverlays(Kent);
centerByArray(Kent, false, false);
cntMarker += Kent.length;
map.addOverlays(Lakeville);
centerByArray(Lakeville, false, false);
cntMarker += Lakeville.length;
map.addOverlays(Litchfield);
centerByArray(Litchfield, false, false);
cntMarker += Litchfield.length;
map.addOverlays(New_Milford);
centerByArray(New_Milford, false, false);
cntMarker += New_Milford.length;
map.addOverlays(New_Preston);
centerByArray(New_Preston, false, false);
cntMarker += New_Preston.length;
map.addOverlays(Northfield);
centerByArray(Northfield, false, false);
cntMarker += Northfield.length;
map.addOverlays(Oakville);
centerByArray(Oakville, false, false);
cntMarker += Oakville.length;
map.addOverlays(Salisbury);
centerByArray(Salisbury, false, false);
cntMarker += Salisbury.length;
map.addOverlays(South_Kent);
centerByArray(South_Kent, false, false);
cntMarker += South_Kent.length;
map.addOverlays(Thomaston);
centerByArray(Thomaston, false, false);
cntMarker += Thomaston.length;
map.addOverlays(Torrington);
centerByArray(Torrington, false, false);
cntMarker += Torrington.length;
map.addOverlays(Washington);
centerByArray(Washington, false, false);
cntMarker += Washington.length;
map.addOverlays(Washington_Depot);
centerByArray(Washington_Depot, false, false);
cntMarker += Washington_Depot.length;
map.addOverlays(Watertown);
centerByArray(Watertown, false, false);
cntMarker += Watertown.length;
map.addOverlays(Winsted);
centerByArray(Winsted, false, false);
cntMarker += Winsted.length;
map.addOverlays(Woodbury);
centerByArray(Woodbury, false, false);
cntMarker += Woodbury.length;
centerByArray(Bethlehem,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;
}