function addMarkers(){
mySelect = document.getElementById('selection');
Appomattox = [];Danville = [];Newport_News = [];Lynchburg = [];Wytheville = [];Powhatan = [];Richmond = [];Manassas = [];Fredericksburg = [];Hampton = [];Dryden = [];Roanoke = [];Petersburg = [];New_Market = [];Stanley = [];Tappahannock = [];Chesapeake = [];Vienna = [];Yale = [];mySelect.options[mySelect.options.length] = new Option("Appomattox schools",'all=Appomattox');
mySelect.options[mySelect.options.length] = new Option("Chesapeake schools",'all=Chesapeake');
mySelect.options[mySelect.options.length] = new Option("Danville schools",'all=Danville');
mySelect.options[mySelect.options.length] = new Option("Dryden schools",'all=Dryden');
mySelect.options[mySelect.options.length] = new Option("Fredericksburg schools",'all=Fredericksburg');
mySelect.options[mySelect.options.length] = new Option("Hampton schools",'all=Hampton');
mySelect.options[mySelect.options.length] = new Option("Lynchburg schools",'all=Lynchburg');
mySelect.options[mySelect.options.length] = new Option("Manassas schools",'all=Manassas');
mySelect.options[mySelect.options.length] = new Option("New Market schools",'all=New_Market');
mySelect.options[mySelect.options.length] = new Option("Newport News schools",'all=Newport_News');
mySelect.options[mySelect.options.length] = new Option("Petersburg schools",'all=Petersburg');
mySelect.options[mySelect.options.length] = new Option("Powhatan schools",'all=Powhatan');
mySelect.options[mySelect.options.length] = new Option("Richmond schools",'all=Richmond');
mySelect.options[mySelect.options.length] = new Option("Roanoke schools",'all=Roanoke');
mySelect.options[mySelect.options.length] = new Option("Stanley schools",'all=Stanley');
mySelect.options[mySelect.options.length] = new Option("Tappahannock schools",'all=Tappahannock');
mySelect.options[mySelect.options.length] = new Option("Vienna schools",'all=Vienna');
mySelect.options[mySelect.options.length] = new Option("Wytheville schools",'all=Wytheville');
mySelect.options[mySelect.options.length] = new Option("Yale schools",'all=Yale');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Appomattox[Appomattox.length] = createMarker(new GPoint(-78.83194100,37.36062600),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Appomattox Sda School",'Appomattox=' + Appomattox.length);
Danville[Danville.length] = createMarker(new GPoint(-79.45709600,36.58923600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("B & P Young Seventh-day Adventist School",'Danville=' + Danville.length);
Newport_News[Newport_News.length] = createMarker(new GPoint(-76.43660000,37.01910000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Calvary Sda School",'Newport_News=' + Newport_News.length);
Lynchburg[Lynchburg.length] = createMarker(new GPoint(-79.18580400,37.32132600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Desmond T Doss Junior Academy",'Lynchburg=' + Lynchburg.length);
Wytheville[Wytheville.length] = createMarker(new GPoint(-81.04468100,36.94419900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Echo Valley Christian School",'Wytheville=' + Wytheville.length);
Powhatan[Powhatan.length] = createMarker(new GPoint(-77.86292500,37.47051400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Ephaugh Academy",'Powhatan=' + Powhatan.length);
Richmond[Richmond.length] = createMarker(new GPoint(-77.47360100,37.51040000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Ephesus Sda School",'Richmond=' + Richmond.length);
Manassas[Manassas.length] = createMarker(new GPoint(-77.49611700,38.77756000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Fairmont Christian Preparatory School",'Manassas=' + Manassas.length);
Fredericksburg[Fredericksburg.length] = createMarker(new GPoint(-77.58918000,38.29363000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Fredericksburg Sda Jr. Academy",'Fredericksburg=' + Fredericksburg.length);
Hampton[Hampton.length] = createMarker(new GPoint(-76.36492400,37.00773300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hampton Roads Sda School",'Hampton=' + Hampton.length);
Dryden[Dryden.length] = createMarker(new GPoint(-82.93220000,36.77890000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Powell Valley Christ School",'Dryden=' + Dryden.length);
Richmond[Richmond.length] = createMarker(new GPoint(-77.48604600,37.56416300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Richmond Academy",'Richmond=' + Richmond.length);
Roanoke[Roanoke.length] = createMarker(new GPoint(-79.97244800,37.26685900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Roanoke Adventist Preparatory",'Roanoke=' + Roanoke.length);
Petersburg[Petersburg.length] = createMarker(new GPoint(-77.36127500,37.18936400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Robert A Lewis Sda School",'Petersburg=' + Petersburg.length);
New_Market[New_Market.length] = createMarker(new GPoint(-78.68966600,38.64923600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Shenandoah Valley Academy",'New_Market=' + New_Market.length);
New_Market[New_Market.length] = createMarker(new GPoint(-78.68692000,38.65097700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Shenandoah Valley Adventist Elementary School",'New_Market=' + New_Market.length);
Stanley[Stanley.length] = createMarker(new GPoint(-78.51709100,38.57782200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Stanley Sda School",'Stanley=' + Stanley.length);
Tappahannock[Tappahannock.length] = createMarker(new GPoint(-76.90002200,37.90545100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Tappahannock Junior Academy",'Tappahannock=' + Tappahannock.length);
Chesapeake[Chesapeake.length] = createMarker(new GPoint(-76.18547900,36.75789400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Tidewater Adventist Academy",'Chesapeake=' + Chesapeake.length);
Vienna[Vienna.length] = createMarker(new GPoint(-77.26726500,38.89393500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Vienna Adventist Academy",'Vienna=' + Vienna.length);
Yale[Yale.length] = createMarker(new GPoint(-77.29017100,36.85807200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Yale Sda School",'Yale=' + Yale.length);
map.removeOverlays(Appomattox);
map.removeOverlays(Chesapeake);
map.removeOverlays(Danville);
map.removeOverlays(Dryden);
map.removeOverlays(Fredericksburg);
map.removeOverlays(Hampton);
map.removeOverlays(Lynchburg);
map.removeOverlays(Manassas);
map.removeOverlays(New_Market);
map.removeOverlays(Newport_News);
map.removeOverlays(Petersburg);
map.removeOverlays(Powhatan);
map.removeOverlays(Richmond);
map.removeOverlays(Roanoke);
map.removeOverlays(Stanley);
map.removeOverlays(Tappahannock);
map.removeOverlays(Vienna);
map.removeOverlays(Wytheville);
map.removeOverlays(Yale);
setTimeout(function(){map.addOverlays(Appomattox)},1000);
setTimeout(function(){map.addOverlays(Chesapeake)},1000);
setTimeout(function(){map.addOverlays(Danville)},1000);
setTimeout(function(){map.addOverlays(Dryden)},1000);
setTimeout(function(){map.addOverlays(Fredericksburg)},1000);
setTimeout(function(){map.addOverlays(Hampton)},1000);
setTimeout(function(){map.addOverlays(Lynchburg)},1000);
setTimeout(function(){map.addOverlays(Manassas)},1000);
setTimeout(function(){map.addOverlays(New_Market)},1000);
setTimeout(function(){map.addOverlays(Newport_News)},1000);
setTimeout(function(){map.addOverlays(Petersburg)},1000);
setTimeout(function(){map.addOverlays(Powhatan)},1000);
setTimeout(function(){map.addOverlays(Richmond)},1000);
setTimeout(function(){map.addOverlays(Roanoke)},1000);
setTimeout(function(){map.addOverlays(Stanley)},1000);
setTimeout(function(){map.addOverlays(Tappahannock)},1000);
setTimeout(function(){map.addOverlays(Vienna)},1000);
setTimeout(function(){map.addOverlays(Wytheville)},1000);
setTimeout(function(){map.addOverlays(Yale)},1000);
maxLng = -76.18547900;
maxLat = 38.89393500;
minLng = -82.93220000;
minLat = 36.58923600;
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(Appomattox);
map.removeOverlays(Chesapeake);
map.removeOverlays(Danville);
map.removeOverlays(Dryden);
map.removeOverlays(Fredericksburg);
map.removeOverlays(Hampton);
map.removeOverlays(Lynchburg);
map.removeOverlays(Manassas);
map.removeOverlays(New_Market);
map.removeOverlays(Newport_News);
map.removeOverlays(Petersburg);
map.removeOverlays(Powhatan);
map.removeOverlays(Richmond);
map.removeOverlays(Roanoke);
map.removeOverlays(Stanley);
map.removeOverlays(Tappahannock);
map.removeOverlays(Vienna);
map.removeOverlays(Wytheville);
map.removeOverlays(Yale);
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(Appomattox);map.removeOverlays(Appomattox);
map.removeOverlays(Chesapeake);
map.removeOverlays(Danville);
map.removeOverlays(Dryden);
map.removeOverlays(Fredericksburg);
map.removeOverlays(Hampton);
map.removeOverlays(Lynchburg);
map.removeOverlays(Manassas);
map.removeOverlays(New_Market);
map.removeOverlays(Newport_News);
map.removeOverlays(Petersburg);
map.removeOverlays(Powhatan);
map.removeOverlays(Richmond);
map.removeOverlays(Roanoke);
map.removeOverlays(Stanley);
map.removeOverlays(Tappahannock);
map.removeOverlays(Vienna);
map.removeOverlays(Wytheville);
map.removeOverlays(Yale);
map.addOverlays(Appomattox);
centerByArray(Appomattox, false, false);
cntMarker += Appomattox.length;
map.addOverlays(Chesapeake);
centerByArray(Chesapeake, false, false);
cntMarker += Chesapeake.length;
map.addOverlays(Danville);
centerByArray(Danville, false, false);
cntMarker += Danville.length;
map.addOverlays(Dryden);
centerByArray(Dryden, false, false);
cntMarker += Dryden.length;
map.addOverlays(Fredericksburg);
centerByArray(Fredericksburg, false, false);
cntMarker += Fredericksburg.length;
map.addOverlays(Hampton);
centerByArray(Hampton, false, false);
cntMarker += Hampton.length;
map.addOverlays(Lynchburg);
centerByArray(Lynchburg, false, false);
cntMarker += Lynchburg.length;
map.addOverlays(Manassas);
centerByArray(Manassas, false, false);
cntMarker += Manassas.length;
map.addOverlays(New_Market);
centerByArray(New_Market, false, false);
cntMarker += New_Market.length;
map.addOverlays(Newport_News);
centerByArray(Newport_News, false, false);
cntMarker += Newport_News.length;
map.addOverlays(Petersburg);
centerByArray(Petersburg, false, false);
cntMarker += Petersburg.length;
map.addOverlays(Powhatan);
centerByArray(Powhatan, false, false);
cntMarker += Powhatan.length;
map.addOverlays(Richmond);
centerByArray(Richmond, false, false);
cntMarker += Richmond.length;
map.addOverlays(Roanoke);
centerByArray(Roanoke, false, false);
cntMarker += Roanoke.length;
map.addOverlays(Stanley);
centerByArray(Stanley, false, false);
cntMarker += Stanley.length;
map.addOverlays(Tappahannock);
centerByArray(Tappahannock, false, false);
cntMarker += Tappahannock.length;
map.addOverlays(Vienna);
centerByArray(Vienna, false, false);
cntMarker += Vienna.length;
map.addOverlays(Wytheville);
centerByArray(Wytheville, false, false);
cntMarker += Wytheville.length;
map.addOverlays(Yale);
centerByArray(Yale, false, false);
cntMarker += Yale.length;
centerByArray(Appomattox,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///28491,28140,28396,28365,28473,28045,28491,28136,28353,28178,34501,28140,28157,28397,28087,28376,28150,33234,28365,28374,28455,28473,28511,28145,28547,/all');
//window.open('/map.php?type=2&schools=28491,28140,28396,28365,28473,28045,28491,28136,28353,28178,34501,28140,28157,28397,28087,28376,28150,33234,28365,28374,28455,28473,28511,28145,28547,&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;
}