function addMarkers(){
mySelect = document.getElementById('selection');
Bangor = [];Berwick = [];Cape_Elizabeth = [];Falmouth = [];Kennebunk = [];Orono = [];Portland = [];Presque_Isle = [];Scarborough = [];South_Portland = [];W_Buxton = [];Westbrook = [];mySelect.options[mySelect.options.length] = new Option("Bangor schools",'all=Bangor');
mySelect.options[mySelect.options.length] = new Option("Berwick schools",'all=Berwick');
mySelect.options[mySelect.options.length] = new Option("Cape Elizabeth schools",'all=Cape_Elizabeth');
mySelect.options[mySelect.options.length] = new Option("Falmouth schools",'all=Falmouth');
mySelect.options[mySelect.options.length] = new Option("Kennebunk schools",'all=Kennebunk');
mySelect.options[mySelect.options.length] = new Option("Orono schools",'all=Orono');
mySelect.options[mySelect.options.length] = new Option("Portland schools",'all=Portland');
mySelect.options[mySelect.options.length] = new Option("Presque Isle schools",'all=Presque_Isle');
mySelect.options[mySelect.options.length] = new Option("Scarborough schools",'all=Scarborough');
mySelect.options[mySelect.options.length] = new Option("South Portland schools",'all=South_Portland');
mySelect.options[mySelect.options.length] = new Option("W Buxton schools",'all=W_Buxton');
mySelect.options[mySelect.options.length] = new Option("Westbrook schools",'all=Westbrook');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Bangor[Bangor.length] = createMarker(new GPoint(-68.77390000,44.80480000),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Building Blocks,inc.",'Bangor=' + Bangor.length);
Bangor[Bangor.length] = createMarker(new GPoint(-68.78078400,44.80740600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hilltop School",'Bangor=' + Bangor.length);
Berwick[Berwick.length] = createMarker(new GPoint(-70.86951900,43.27124800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Cornerstone Kindergarten Inc",'Berwick=' + Berwick.length);
Cape_Elizabeth[Cape_Elizabeth.length] = createMarker(new GPoint(-70.21868900,43.56971200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Appletree School",'Cape_Elizabeth=' + Cape_Elizabeth.length);
Cape_Elizabeth[Cape_Elizabeth.length] = createMarker(new GPoint(-70.23355000,43.62517800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Ledgemere Country Day School",'Cape_Elizabeth=' + Cape_Elizabeth.length);
Falmouth[Falmouth.length] = createMarker(new GPoint(-70.29933200,43.75115500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Children's Odyssey",'Falmouth=' + Falmouth.length);
Kennebunk[Kennebunk.length] = createMarker(new GPoint(-70.51158600,43.37417400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Cocoons Inc",'Kennebunk=' + Kennebunk.length);
Orono[Orono.length] = createMarker(new GPoint(-68.66170000,44.90440000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Katherine Miles Durst Child De",'Orono=' + Orono.length);
Portland[Portland.length] = createMarker(new GPoint(-70.26129000,43.65300200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Elizabeth's Child Development",'Portland=' + Portland.length);
Portland[Portland.length] = createMarker(new GPoint(-70.29362600,43.68315100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Childrens Center",'Portland=' + Portland.length);
Portland[Portland.length] = createMarker(new GPoint(-70.29362600,43.68315100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Childrens Center",'Portland=' + Portland.length);
Presque_Isle[Presque_Isle.length] = createMarker(new GPoint(-68.03883900,46.69578600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Circle Of Learning",'Presque_Isle=' + Presque_Isle.length);
Scarborough[Scarborough.length] = createMarker(new GPoint(-70.35781800,43.57956700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Toddle Inn Child Care",'Scarborough=' + Scarborough.length);
South_Portland[South_Portland.length] = createMarker(new GPoint(-70.26538600,43.62324800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Lighthouse School",'South_Portland=' + South_Portland.length);
W_Buxton[W_Buxton.length] = createMarker(new GPoint(-70.53930000,43.64380000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Deer Pond Edu-care Inc",'W_Buxton=' + W_Buxton.length);
Westbrook[Westbrook.length] = createMarker(new GPoint(-70.34758900,43.65050400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Little Dolphin School Foundation",'Westbrook=' + Westbrook.length);
map.removeOverlays(Bangor);
map.removeOverlays(Berwick);
map.removeOverlays(Cape_Elizabeth);
map.removeOverlays(Falmouth);
map.removeOverlays(Kennebunk);
map.removeOverlays(Orono);
map.removeOverlays(Portland);
map.removeOverlays(Presque_Isle);
map.removeOverlays(Scarborough);
map.removeOverlays(South_Portland);
map.removeOverlays(W_Buxton);
map.removeOverlays(Westbrook);
setTimeout(function(){map.addOverlays(Bangor)},1000);
setTimeout(function(){map.addOverlays(Berwick)},1000);
setTimeout(function(){map.addOverlays(Cape_Elizabeth)},1000);
setTimeout(function(){map.addOverlays(Falmouth)},1000);
setTimeout(function(){map.addOverlays(Kennebunk)},1000);
setTimeout(function(){map.addOverlays(Orono)},1000);
setTimeout(function(){map.addOverlays(Portland)},1000);
setTimeout(function(){map.addOverlays(Presque_Isle)},1000);
setTimeout(function(){map.addOverlays(Scarborough)},1000);
setTimeout(function(){map.addOverlays(South_Portland)},1000);
setTimeout(function(){map.addOverlays(W_Buxton)},1000);
setTimeout(function(){map.addOverlays(Westbrook)},1000);
maxLng = -68.03883900;
maxLat = 46.69578600;
minLng = -70.86951900;
minLat = 43.27124800;
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(Bangor);
map.removeOverlays(Berwick);
map.removeOverlays(Cape_Elizabeth);
map.removeOverlays(Falmouth);
map.removeOverlays(Kennebunk);
map.removeOverlays(Orono);
map.removeOverlays(Portland);
map.removeOverlays(Presque_Isle);
map.removeOverlays(Scarborough);
map.removeOverlays(South_Portland);
map.removeOverlays(W_Buxton);
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(Bangor);map.removeOverlays(Bangor);
map.removeOverlays(Berwick);
map.removeOverlays(Cape_Elizabeth);
map.removeOverlays(Falmouth);
map.removeOverlays(Kennebunk);
map.removeOverlays(Orono);
map.removeOverlays(Portland);
map.removeOverlays(Presque_Isle);
map.removeOverlays(Scarborough);
map.removeOverlays(South_Portland);
map.removeOverlays(W_Buxton);
map.removeOverlays(Westbrook);
map.addOverlays(Bangor);
centerByArray(Bangor, false, false);
cntMarker += Bangor.length;
map.addOverlays(Berwick);
centerByArray(Berwick, false, false);
cntMarker += Berwick.length;
map.addOverlays(Cape_Elizabeth);
centerByArray(Cape_Elizabeth, false, false);
cntMarker += Cape_Elizabeth.length;
map.addOverlays(Falmouth);
centerByArray(Falmouth, false, false);
cntMarker += Falmouth.length;
map.addOverlays(Kennebunk);
centerByArray(Kennebunk, false, false);
cntMarker += Kennebunk.length;
map.addOverlays(Orono);
centerByArray(Orono, false, false);
cntMarker += Orono.length;
map.addOverlays(Portland);
centerByArray(Portland, false, false);
cntMarker += Portland.length;
map.addOverlays(Presque_Isle);
centerByArray(Presque_Isle, false, false);
cntMarker += Presque_Isle.length;
map.addOverlays(Scarborough);
centerByArray(Scarborough, false, false);
cntMarker += Scarborough.length;
map.addOverlays(South_Portland);
centerByArray(South_Portland, false, false);
cntMarker += South_Portland.length;
map.addOverlays(W_Buxton);
centerByArray(W_Buxton, false, false);
cntMarker += W_Buxton.length;
map.addOverlays(Westbrook);
centerByArray(Westbrook, false, false);
cntMarker += Westbrook.length;
centerByArray(Bangor,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=2&schools=&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;
}