function addMarkers(){
mySelect = document.getElementById('selection');
Lakewood = [];Passaic = [];West_Long_Branch = [];Ocean = [];Elberon = [];Livingston = [];Newark = [];East_Windsor = [];Edison = [];River_Edge = [];Piscataway = [];mySelect.options[mySelect.options.length] = new Option("East Windsor schools",'all=East_Windsor');
mySelect.options[mySelect.options.length] = new Option("Edison schools",'all=Edison');
mySelect.options[mySelect.options.length] = new Option("Elberon schools",'all=Elberon');
mySelect.options[mySelect.options.length] = new Option("Lakewood schools",'all=Lakewood');
mySelect.options[mySelect.options.length] = new Option("Livingston schools",'all=Livingston');
mySelect.options[mySelect.options.length] = new Option("Newark schools",'all=Newark');
mySelect.options[mySelect.options.length] = new Option("Ocean schools",'all=Ocean');
mySelect.options[mySelect.options.length] = new Option("Passaic schools",'all=Passaic');
mySelect.options[mySelect.options.length] = new Option("Piscataway schools",'all=Piscataway');
mySelect.options[mySelect.options.length] = new Option("River Edge schools",'all=River_Edge');
mySelect.options[mySelect.options.length] = new Option("West Long Branch schools",'all=West_Long_Branch');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Lakewood[Lakewood.length] = createMarker(new GPoint(-74.20680000,40.07860000),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Bais Kaila Torah Preparatory High School For Girls",'Lakewood=' + Lakewood.length);
Lakewood[Lakewood.length] = createMarker(new GPoint(-74.21245000,40.10249400),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Bais Rochel",'Lakewood=' + Lakewood.length);
Passaic[Passaic.length] = createMarker(new GPoint(-74.12815800,40.85230000),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Bais Yaakov Of Passaic High School For Girls",'Passaic=' + Passaic.length);
West_Long_Branch[West_Long_Branch.length] = createMarker(new GPoint(-74.01720000,40.29050000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Deal Yeshiva",'West_Long_Branch=' + West_Long_Branch.length);
Ocean[Ocean.length] = createMarker(new GPoint(-74.03323600,40.23633300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Deal Yeshiva - Boys Division",'Ocean=' + Ocean.length);
Elberon[Elberon.length] = createMarker(new GPoint(-73.99883900,40.27028500),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Ilan High School",'Elberon=' + Elberon.length);
Livingston[Livingston.length] = createMarker(new GPoint(-74.35974300,40.77566500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Joseph Kushner Hebrew Academy",'Livingston=' + Livingston.length);
Lakewood[Lakewood.length] = createMarker(new GPoint(-74.22022600,40.10457100),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Mesivta Keser Torah",'Lakewood=' + Lakewood.length);
Newark[Newark.length] = createMarker(new GPoint(-74.16937100,40.74357200),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("The Mesivta Of North Jersey",'Newark=' + Newark.length);
East_Windsor[East_Windsor.length] = createMarker(new GPoint(-74.48542200,40.26599300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Morris Namias Shalom Torah Academy",'East_Windsor=' + East_Windsor.length);
Edison[Edison.length] = createMarker(new GPoint(-74.39821900,40.50063900),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Rabbi Jacob Joseph Yeshiva",'Edison=' + Edison.length);
Passaic[Passaic.length] = createMarker(new GPoint(-74.13502500,40.84123500),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Yeshiva Ktana Of Passaic Girls",'Passaic=' + Passaic.length);
Lakewood[Lakewood.length] = createMarker(new GPoint(-74.20609400,40.09137900),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Yeshiva Masoras Avos",'Lakewood=' + Lakewood.length);
River_Edge[River_Edge.length] = createMarker(new GPoint(-74.03373100,40.93133700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Yeshiva Of North Jersey",'River_Edge=' + River_Edge.length);
Lakewood[Lakewood.length] = createMarker(new GPoint(-74.23861900,40.09548000),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Yeshiva Orchos Chaim",'Lakewood=' + Lakewood.length);
Piscataway[Piscataway.length] = createMarker(new GPoint(-74.48883900,40.52703900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Yeshiva Shaarei Tzion Girls School",'Piscataway=' + Piscataway.length);
map.removeOverlays(East_Windsor);
map.removeOverlays(Edison);
map.removeOverlays(Elberon);
map.removeOverlays(Lakewood);
map.removeOverlays(Livingston);
map.removeOverlays(Newark);
map.removeOverlays(Ocean);
map.removeOverlays(Passaic);
map.removeOverlays(Piscataway);
map.removeOverlays(River_Edge);
map.removeOverlays(West_Long_Branch);
setTimeout(function(){map.addOverlays(East_Windsor)},1000);
setTimeout(function(){map.addOverlays(Edison)},1000);
setTimeout(function(){map.addOverlays(Elberon)},1000);
setTimeout(function(){map.addOverlays(Lakewood)},1000);
setTimeout(function(){map.addOverlays(Livingston)},1000);
setTimeout(function(){map.addOverlays(Newark)},1000);
setTimeout(function(){map.addOverlays(Ocean)},1000);
setTimeout(function(){map.addOverlays(Passaic)},1000);
setTimeout(function(){map.addOverlays(Piscataway)},1000);
setTimeout(function(){map.addOverlays(River_Edge)},1000);
setTimeout(function(){map.addOverlays(West_Long_Branch)},1000);
maxLng = -73.99883900;
maxLat = 40.93133700;
minLng = -74.48883900;
minLat = 40.07860000;
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(East_Windsor);
map.removeOverlays(Edison);
map.removeOverlays(Elberon);
map.removeOverlays(Lakewood);
map.removeOverlays(Livingston);
map.removeOverlays(Newark);
map.removeOverlays(Ocean);
map.removeOverlays(Passaic);
map.removeOverlays(Piscataway);
map.removeOverlays(River_Edge);
map.removeOverlays(West_Long_Branch);
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(Lakewood);map.removeOverlays(East_Windsor);
map.removeOverlays(Edison);
map.removeOverlays(Elberon);
map.removeOverlays(Lakewood);
map.removeOverlays(Livingston);
map.removeOverlays(Newark);
map.removeOverlays(Ocean);
map.removeOverlays(Passaic);
map.removeOverlays(Piscataway);
map.removeOverlays(River_Edge);
map.removeOverlays(West_Long_Branch);
map.addOverlays(East_Windsor);
centerByArray(East_Windsor, false, false);
cntMarker += East_Windsor.length;
map.addOverlays(Edison);
centerByArray(Edison, false, false);
cntMarker += Edison.length;
map.addOverlays(Elberon);
centerByArray(Elberon, false, false);
cntMarker += Elberon.length;
map.addOverlays(Lakewood);
centerByArray(Lakewood, false, false);
cntMarker += Lakewood.length;
map.addOverlays(Livingston);
centerByArray(Livingston, false, false);
cntMarker += Livingston.length;
map.addOverlays(Newark);
centerByArray(Newark, false, false);
cntMarker += Newark.length;
map.addOverlays(Ocean);
centerByArray(Ocean, false, false);
cntMarker += Ocean.length;
map.addOverlays(Passaic);
centerByArray(Passaic, false, false);
cntMarker += Passaic.length;
map.addOverlays(Piscataway);
centerByArray(Piscataway, false, false);
cntMarker += Piscataway.length;
map.addOverlays(River_Edge);
centerByArray(River_Edge, false, false);
cntMarker += River_Edge.length;
map.addOverlays(West_Long_Branch);
centerByArray(West_Long_Branch, false, false);
cntMarker += West_Long_Branch.length;
centerByArray(Lakewood,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///17629,17344,17076,17458,34401,17209,17080,18095,17973,17489,17077,18097,34162,17378,17209,18095,18102,18098,17973,/all');
//window.open('/map.php?type=2&schools=17629,17344,17076,17458,34401,17209,17080,18095,17973,17489,17077,18097,34162,17378,17209,18095,18102,18098,17973,&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;
}