function addMarkers(){
mySelect = document.getElementById('selection');
Avon = [];Greenwich = [];Litchfield = [];Meriden = [];Fairfield = [];Deep_River = [];West_Haven = [];Westbrook = [];Putnam = [];Portland = [];New_Haven = [];Oakdale = [];Salisbury = [];South_Kent = [];Bethlehem = [];Middletown = [];Stamford = [];mySelect.options[mySelect.options.length] = new Option("Avon schools",'all=Avon');
mySelect.options[mySelect.options.length] = new Option("Bethlehem schools",'all=Bethlehem');
mySelect.options[mySelect.options.length] = new Option("Deep River schools",'all=Deep_River');
mySelect.options[mySelect.options.length] = new Option("Fairfield schools",'all=Fairfield');
mySelect.options[mySelect.options.length] = new Option("Greenwich schools",'all=Greenwich');
mySelect.options[mySelect.options.length] = new Option("Litchfield schools",'all=Litchfield');
mySelect.options[mySelect.options.length] = new Option("Meriden schools",'all=Meriden');
mySelect.options[mySelect.options.length] = new Option("Middletown schools",'all=Middletown');
mySelect.options[mySelect.options.length] = new Option("New Haven schools",'all=New_Haven');
mySelect.options[mySelect.options.length] = new Option("Oakdale schools",'all=Oakdale');
mySelect.options[mySelect.options.length] = new Option("Portland schools",'all=Portland');
mySelect.options[mySelect.options.length] = new Option("Putnam schools",'all=Putnam');
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("Stamford schools",'all=Stamford');
mySelect.options[mySelect.options.length] = new Option("West Haven schools",'all=West_Haven');
mySelect.options[mySelect.options.length] = new Option("Westbrook schools",'all=Westbrook');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Avon[Avon.length] = createMarker(new GPoint(-72.83650200,41.78126100),"
",iconBl);
mySelect.options[mySelect.options.length] = new Option("Avon Old Farms School",'Avon=' + Avon.length);
Greenwich[Greenwich.length] = createMarker(new GPoint(-73.62570100,41.03779600),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Brunswick School",'Greenwich=' + Greenwich.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);
Meriden[Meriden.length] = createMarker(new GPoint(-72.80534100,41.52766100),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Curtis School",'Meriden=' + Meriden.length);
Fairfield[Fairfield.length] = createMarker(new GPoint(-73.25463300,41.16179100),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Fairfield College Preparatory",'Fairfield=' + Fairfield.length);
Fairfield[Fairfield.length] = createMarker(new GPoint(-73.29131900,41.17253700),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Fairfield Country Day School",'Fairfield=' + Fairfield.length);
Deep_River[Deep_River.length] = createMarker(new GPoint(-72.42895300,41.39397800),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Mt Saint John",'Deep_River=' + Deep_River.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);
Westbrook[Westbrook.length] = createMarker(new GPoint(-72.44295800,41.28343400),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Oxford Academy",'Westbrook=' + Westbrook.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);
Portland[Portland.length] = createMarker(new GPoint(-72.63765100,41.57171100),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Rushford Academy",'Portland=' + Portland.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);
Oakdale[Oakdale.length] = createMarker(new GPoint(-72.21384900,41.51450100),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("St. Thomas More School",'Oakdale=' + Oakdale.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);
Bethlehem[Bethlehem.length] = createMarker(new GPoint(-73.20730000,41.63960000),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("The Woodhall School",'Bethlehem=' + Bethlehem.length);
Middletown[Middletown.length] = createMarker(new GPoint(-72.62082800,41.53384600),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Xavier High School",'Middletown=' + Middletown.length);
Stamford[Stamford.length] = createMarker(new GPoint(-73.53487300,41.05961200),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Yeshiva Bais Binyomin",'Stamford=' + Stamford.length);
map.removeOverlays(Avon);
map.removeOverlays(Bethlehem);
map.removeOverlays(Deep_River);
map.removeOverlays(Fairfield);
map.removeOverlays(Greenwich);
map.removeOverlays(Litchfield);
map.removeOverlays(Meriden);
map.removeOverlays(Middletown);
map.removeOverlays(New_Haven);
map.removeOverlays(Oakdale);
map.removeOverlays(Portland);
map.removeOverlays(Putnam);
map.removeOverlays(Salisbury);
map.removeOverlays(South_Kent);
map.removeOverlays(Stamford);
map.removeOverlays(West_Haven);
map.removeOverlays(Westbrook);
setTimeout(function(){map.addOverlays(Avon)},1000);
setTimeout(function(){map.addOverlays(Bethlehem)},1000);
setTimeout(function(){map.addOverlays(Deep_River)},1000);
setTimeout(function(){map.addOverlays(Fairfield)},1000);
setTimeout(function(){map.addOverlays(Greenwich)},1000);
setTimeout(function(){map.addOverlays(Litchfield)},1000);
setTimeout(function(){map.addOverlays(Meriden)},1000);
setTimeout(function(){map.addOverlays(Middletown)},1000);
setTimeout(function(){map.addOverlays(New_Haven)},1000);
setTimeout(function(){map.addOverlays(Oakdale)},1000);
setTimeout(function(){map.addOverlays(Portland)},1000);
setTimeout(function(){map.addOverlays(Putnam)},1000);
setTimeout(function(){map.addOverlays(Salisbury)},1000);
setTimeout(function(){map.addOverlays(South_Kent)},1000);
setTimeout(function(){map.addOverlays(Stamford)},1000);
setTimeout(function(){map.addOverlays(West_Haven)},1000);
setTimeout(function(){map.addOverlays(Westbrook)},1000);
maxLng = -71.91292500;
maxLat = 42.00093800;
minLng = -73.62570100;
minLat = 41.03779600;
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(Avon);
map.removeOverlays(Bethlehem);
map.removeOverlays(Deep_River);
map.removeOverlays(Fairfield);
map.removeOverlays(Greenwich);
map.removeOverlays(Litchfield);
map.removeOverlays(Meriden);
map.removeOverlays(Middletown);
map.removeOverlays(New_Haven);
map.removeOverlays(Oakdale);
map.removeOverlays(Portland);
map.removeOverlays(Putnam);
map.removeOverlays(Salisbury);
map.removeOverlays(South_Kent);
map.removeOverlays(Stamford);
map.removeOverlays(West_Haven);
map.removeOverlays(Westbrook);
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(Avon);map.removeOverlays(Avon);
map.removeOverlays(Bethlehem);
map.removeOverlays(Deep_River);
map.removeOverlays(Fairfield);
map.removeOverlays(Greenwich);
map.removeOverlays(Litchfield);
map.removeOverlays(Meriden);
map.removeOverlays(Middletown);
map.removeOverlays(New_Haven);
map.removeOverlays(Oakdale);
map.removeOverlays(Portland);
map.removeOverlays(Putnam);
map.removeOverlays(Salisbury);
map.removeOverlays(South_Kent);
map.removeOverlays(Stamford);
map.removeOverlays(West_Haven);
map.removeOverlays(Westbrook);
map.addOverlays(Avon);
centerByArray(Avon, false, false);
cntMarker += Avon.length;
map.addOverlays(Bethlehem);
centerByArray(Bethlehem, false, false);
cntMarker += Bethlehem.length;
map.addOverlays(Deep_River);
centerByArray(Deep_River, false, false);
cntMarker += Deep_River.length;
map.addOverlays(Fairfield);
centerByArray(Fairfield, false, false);
cntMarker += Fairfield.length;
map.addOverlays(Greenwich);
centerByArray(Greenwich, false, false);
cntMarker += Greenwich.length;
map.addOverlays(Litchfield);
centerByArray(Litchfield, false, false);
cntMarker += Litchfield.length;
map.addOverlays(Meriden);
centerByArray(Meriden, false, false);
cntMarker += Meriden.length;
map.addOverlays(Middletown);
centerByArray(Middletown, false, false);
cntMarker += Middletown.length;
map.addOverlays(New_Haven);
centerByArray(New_Haven, false, false);
cntMarker += New_Haven.length;
map.addOverlays(Oakdale);
centerByArray(Oakdale, false, false);
cntMarker += Oakdale.length;
map.addOverlays(Portland);
centerByArray(Portland, false, false);
cntMarker += Portland.length;
map.addOverlays(Putnam);
centerByArray(Putnam, false, false);
cntMarker += Putnam.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(Stamford);
centerByArray(Stamford, false, false);
cntMarker += Stamford.length;
map.addOverlays(West_Haven);
centerByArray(West_Haven, false, false);
cntMarker += West_Haven.length;
map.addOverlays(Westbrook);
centerByArray(Westbrook, false, false);
cntMarker += Westbrook.length;
centerByArray(Avon,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///35784,5581,5396,5321,5322,5287,5311,5610,5482,5549,35866,35337,5451,5457,5612,5408,5419,5322,5287,5305,5311,5482,/all');
//window.open('/map.php?type=2&schools=35784,5581,5396,5321,5322,5287,5311,5610,5482,5549,35866,35337,5451,5457,5612,5408,5419,5322,5287,5305,5311,5482,&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;
}