function addMarkers(){
mySelect = document.getElementById('selection');
Cresson = [];Ebensburg = [];Johnstown = [];Nicktown = [];Portage = [];Elton = [];Gallitzin = [];Carrolltown = [];Nanty_Glo = [];Loretto = [];mySelect.options[mySelect.options.length] = new Option("Carrolltown schools",'all=Carrolltown');
mySelect.options[mySelect.options.length] = new Option("Cresson schools",'all=Cresson');
mySelect.options[mySelect.options.length] = new Option("Ebensburg schools",'all=Ebensburg');
mySelect.options[mySelect.options.length] = new Option("Elton schools",'all=Elton');
mySelect.options[mySelect.options.length] = new Option("Gallitzin schools",'all=Gallitzin');
mySelect.options[mySelect.options.length] = new Option("Johnstown schools",'all=Johnstown');
mySelect.options[mySelect.options.length] = new Option("Loretto schools",'all=Loretto');
mySelect.options[mySelect.options.length] = new Option("Nanty Glo schools",'all=Nanty_Glo');
mySelect.options[mySelect.options.length] = new Option("Nicktown schools",'all=Nicktown');
mySelect.options[mySelect.options.length] = new Option("Portage schools",'all=Portage');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Cresson[Cresson.length] = createMarker(new GPoint(-78.58752900,40.46487800),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("All Saints Catholic School",'Cresson=' + Cresson.length);
Ebensburg[Ebensburg.length] = createMarker(new GPoint(-78.73325500,40.48508800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Bishop Carroll High School",'Ebensburg=' + Ebensburg.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.91680600,40.30508400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Bishop Mc Cort High School",'Johnstown=' + Johnstown.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.83724800,40.44422200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Cambria County Christian School",'Johnstown=' + Johnstown.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.94215600,40.29906600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Cathedral Catholic Academy",'Johnstown=' + Johnstown.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.91182700,40.32578800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Central Catholic Elementary School",'Johnstown=' + Johnstown.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.86220000,40.28890000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Greater Johnstown Christian Academy",'Johnstown=' + Johnstown.length);
Ebensburg[Ebensburg.length] = createMarker(new GPoint(-78.72614800,40.48793700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Holy Name Elementary School",'Ebensburg=' + Ebensburg.length);
Nicktown[Nicktown.length] = createMarker(new GPoint(-78.81480000,40.59810000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Northern Cambria Catholic School",'Nicktown=' + Nicktown.length);
Portage[Portage.length] = createMarker(new GPoint(-78.67071700,40.38449200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Our Lady Of The Sacred Heart School",'Portage=' + Portage.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.93269000,40.32065200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Our Mother Of Sorrows School",'Johnstown=' + Johnstown.length);
Elton[Elton.length] = createMarker(new GPoint(-78.80370000,40.27940000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Richland Academy",'Elton=' + Elton.length);
Gallitzin[Gallitzin.length] = createMarker(new GPoint(-78.54457800,40.48052000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Demetrius School",'Gallitzin=' + Gallitzin.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.92846200,40.28677500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Andrews School",'Johnstown=' + Johnstown.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.87612900,40.29661300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Benedict Elementary School",'Johnstown=' + Johnstown.length);
Carrolltown[Carrolltown.length] = createMarker(new GPoint(-78.71510000,40.60050000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Benedict Elementary School",'Carrolltown=' + Carrolltown.length);
Nanty_Glo[Nanty_Glo.length] = createMarker(new GPoint(-78.83815900,40.47081000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Mary Elementary School",'Nanty_Glo=' + Nanty_Glo.length);
Loretto[Loretto.length] = createMarker(new GPoint(-78.62840000,40.50670000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Michael Elementary School",'Loretto=' + Loretto.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.91152900,40.29632300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Patrick Elementary School",'Johnstown=' + Johnstown.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.94144400,40.29822800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Sophia Orthodox Christian Academy",'Johnstown=' + Johnstown.length);
Portage[Portage.length] = createMarker(new GPoint(-78.66485900,40.36737500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Wesleyan Holiness Academy",'Portage=' + Portage.length);
Johnstown[Johnstown.length] = createMarker(new GPoint(-78.92608300,40.34031600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("West End Catholic School",'Johnstown=' + Johnstown.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/////3/' + showArray);
map.removeOverlays(Carrolltown);
map.removeOverlays(Cresson);
map.removeOverlays(Ebensburg);
map.removeOverlays(Elton);
map.removeOverlays(Gallitzin);
map.removeOverlays(Johnstown);
map.removeOverlays(Loretto);
map.removeOverlays(Nanty_Glo);
map.removeOverlays(Nicktown);
map.removeOverlays(Portage);
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(Cresson);map.removeOverlays(Carrolltown);
map.removeOverlays(Cresson);
map.removeOverlays(Ebensburg);
map.removeOverlays(Elton);
map.removeOverlays(Gallitzin);
map.removeOverlays(Johnstown);
map.removeOverlays(Loretto);
map.removeOverlays(Nanty_Glo);
map.removeOverlays(Nicktown);
map.removeOverlays(Portage);
map.addOverlays(Carrolltown);
centerByArray(Carrolltown, false, false);
cntMarker += Carrolltown.length;
map.addOverlays(Cresson);
centerByArray(Cresson, false, false);
cntMarker += Cresson.length;
map.addOverlays(Ebensburg);
centerByArray(Ebensburg, false, false);
cntMarker += Ebensburg.length;
map.addOverlays(Elton);
centerByArray(Elton, false, false);
cntMarker += Elton.length;
map.addOverlays(Gallitzin);
centerByArray(Gallitzin, false, false);
cntMarker += Gallitzin.length;
map.addOverlays(Johnstown);
centerByArray(Johnstown, false, false);
cntMarker += Johnstown.length;
map.addOverlays(Loretto);
centerByArray(Loretto, false, false);
cntMarker += Loretto.length;
map.addOverlays(Nanty_Glo);
centerByArray(Nanty_Glo, false, false);
cntMarker += Nanty_Glo.length;
map.addOverlays(Nicktown);
centerByArray(Nicktown, false, false);
cntMarker += Nicktown.length;
map.addOverlays(Portage);
centerByArray(Portage, false, false);
cntMarker += Portage.length;
centerByArray(Cresson,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=3&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;
}