function addMarkers(){
mySelect = document.getElementById('selection');
Liberty_Corner = [];Belle_Mead = [];Gladstone = [];Bound_Brook = [];Somerville = [];Peapack = [];Watchung = [];North_Branch = [];Somerset = [];Martinsville = [];Zarepath = [];Far_Hills = [];mySelect.options[mySelect.options.length] = new Option("Belle Mead schools",'all=Belle_Mead');
mySelect.options[mySelect.options.length] = new Option("Bound Brook schools",'all=Bound_Brook');
mySelect.options[mySelect.options.length] = new Option("Far Hills schools",'all=Far_Hills');
mySelect.options[mySelect.options.length] = new Option("Gladstone schools",'all=Gladstone');
mySelect.options[mySelect.options.length] = new Option("Liberty Corner schools",'all=Liberty_Corner');
mySelect.options[mySelect.options.length] = new Option("Martinsville schools",'all=Martinsville');
mySelect.options[mySelect.options.length] = new Option("North Branch schools",'all=North_Branch');
mySelect.options[mySelect.options.length] = new Option("Peapack schools",'all=Peapack');
mySelect.options[mySelect.options.length] = new Option("Somerset schools",'all=Somerset');
mySelect.options[mySelect.options.length] = new Option("Somerville schools",'all=Somerville');
mySelect.options[mySelect.options.length] = new Option("Watchung schools",'all=Watchung');
mySelect.options[mySelect.options.length] = new Option("Zarepath schools",'all=Zarepath');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Liberty_Corner[Liberty_Corner.length] = createMarker(new GPoint(-74.57770000,40.66470000),"
",iconBl);
mySelect.options[mySelect.options.length] = new Option("Bonnie Brae School",'Liberty_Corner=' + Liberty_Corner.length);
Belle_Mead[Belle_Mead.length] = createMarker(new GPoint(-74.64570000,40.44930000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("East Mountain School",'Belle_Mead=' + Belle_Mead.length);
Gladstone[Gladstone.length] = createMarker(new GPoint(-74.66558400,40.72250000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Gill St Bernard's School",'Gladstone=' + Gladstone.length);
Bound_Brook[Bound_Brook.length] = createMarker(new GPoint(-74.53990000,40.56910000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Green Brook Academy",'Bound_Brook=' + Bound_Brook.length);
Somerville[Somerville.length] = createMarker(new GPoint(-74.61880900,40.57971400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Immaculata High School",'Somerville=' + Somerville.length);
Peapack[Peapack.length] = createMarker(new GPoint(-74.66210000,40.70970000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Matheny Medical & Educational Center",'Peapack=' + Peapack.length);
Watchung[Watchung.length] = createMarker(new GPoint(-74.43770000,40.64310000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mc Auley School For Exceptiona",'Watchung=' + Watchung.length);
North_Branch[North_Branch.length] = createMarker(new GPoint(-74.61938900,40.57070500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Midland School",'North_Branch=' + North_Branch.length);
Watchung[Watchung.length] = createMarker(new GPoint(-74.44690000,40.62195000),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Mt St Mary Academy (high School)",'Watchung=' + Watchung.length);
Somerset[Somerset.length] = createMarker(new GPoint(-74.54923400,40.53057800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("New Road School of Somerset",'Somerset=' + Somerset.length);
Martinsville[Martinsville.length] = createMarker(new GPoint(-74.55370000,40.59620000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Pingry School",'Martinsville=' + Martinsville.length);
Somerset[Somerset.length] = createMarker(new GPoint(-74.49659300,40.52579600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Rutgers Preparatory School",'Somerset=' + Somerset.length);
Zarepath[Zarepath.length] = createMarker(new GPoint(-74.57708200,40.53570200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Somerset Christian Academy",'Zarepath=' + Zarepath.length);
Far_Hills[Far_Hills.length] = createMarker(new GPoint(-74.64992700,40.64532000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Somerset Hills Learning Institute",'Far_Hills=' + Far_Hills.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/////2/' + showArray);
map.removeOverlays(Belle_Mead);
map.removeOverlays(Bound_Brook);
map.removeOverlays(Far_Hills);
map.removeOverlays(Gladstone);
map.removeOverlays(Liberty_Corner);
map.removeOverlays(Martinsville);
map.removeOverlays(North_Branch);
map.removeOverlays(Peapack);
map.removeOverlays(Somerset);
map.removeOverlays(Somerville);
map.removeOverlays(Watchung);
map.removeOverlays(Zarepath);
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(Liberty_Corner);map.removeOverlays(Belle_Mead);
map.removeOverlays(Bound_Brook);
map.removeOverlays(Far_Hills);
map.removeOverlays(Gladstone);
map.removeOverlays(Liberty_Corner);
map.removeOverlays(Martinsville);
map.removeOverlays(North_Branch);
map.removeOverlays(Peapack);
map.removeOverlays(Somerset);
map.removeOverlays(Somerville);
map.removeOverlays(Watchung);
map.removeOverlays(Zarepath);
map.addOverlays(Belle_Mead);
centerByArray(Belle_Mead, false, false);
cntMarker += Belle_Mead.length;
map.addOverlays(Bound_Brook);
centerByArray(Bound_Brook, false, false);
cntMarker += Bound_Brook.length;
map.addOverlays(Far_Hills);
centerByArray(Far_Hills, false, false);
cntMarker += Far_Hills.length;
map.addOverlays(Gladstone);
centerByArray(Gladstone, false, false);
cntMarker += Gladstone.length;
map.addOverlays(Liberty_Corner);
centerByArray(Liberty_Corner, false, false);
cntMarker += Liberty_Corner.length;
map.addOverlays(Martinsville);
centerByArray(Martinsville, false, false);
cntMarker += Martinsville.length;
map.addOverlays(North_Branch);
centerByArray(North_Branch, false, false);
cntMarker += North_Branch.length;
map.addOverlays(Peapack);
centerByArray(Peapack, false, false);
cntMarker += Peapack.length;
map.addOverlays(Somerset);
centerByArray(Somerset, false, false);
cntMarker += Somerset.length;
map.addOverlays(Somerville);
centerByArray(Somerville, false, false);
cntMarker += Somerville.length;
map.addOverlays(Watchung);
centerByArray(Watchung, false, false);
cntMarker += Watchung.length;
map.addOverlays(Zarepath);
centerByArray(Zarepath, false, false);
cntMarker += Zarepath.length;
centerByArray(Liberty_Corner,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=2&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;
}