function addMarkers(){
mySelect = document.getElementById('selection');
Aptos = [];Santa_Cruz = [];Scotts_Valley = [];Soquel = [];Watsonville = [];Boulder_Creek = [];La_Selva_Beach = [];Felton = [];Corralitos = [];mySelect.options[mySelect.options.length] = new Option("Aptos schools",'all=Aptos');
mySelect.options[mySelect.options.length] = new Option("Boulder Creek schools",'all=Boulder_Creek');
mySelect.options[mySelect.options.length] = new Option("Corralitos schools",'all=Corralitos');
mySelect.options[mySelect.options.length] = new Option("Felton schools",'all=Felton');
mySelect.options[mySelect.options.length] = new Option("La Selva Beach schools",'all=La_Selva_Beach');
mySelect.options[mySelect.options.length] = new Option("Santa Cruz schools",'all=Santa_Cruz');
mySelect.options[mySelect.options.length] = new Option("Scotts Valley schools",'all=Scotts_Valley');
mySelect.options[mySelect.options.length] = new Option("Soquel schools",'all=Soquel');
mySelect.options[mySelect.options.length] = new Option("Watsonville schools",'all=Watsonville');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Aptos[Aptos.length] = createMarker(new GPoint(-121.86467000,36.95763800),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Aptos Academy, The",'Aptos=' + Aptos.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-121.97715100,36.98457200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Bay School",'Santa_Cruz=' + Santa_Cruz.length);
Scotts_Valley[Scotts_Valley.length] = createMarker(new GPoint(-122.00236700,37.06070300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Baymonte Christian School",'Scotts_Valley=' + Scotts_Valley.length);
Soquel[Soquel.length] = createMarker(new GPoint(-121.94030000,37.05543700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Beach High School",'Soquel=' + Soquel.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.03408900,36.98695800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Empire Academy",'Santa_Cruz=' + Santa_Cruz.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.02678900,36.95493700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Gateway School",'Santa_Cruz=' + Santa_Cruz.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.03544800,36.98687800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Georgiana Bruce Kirby Preparat",'Santa_Cruz=' + Santa_Cruz.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-121.97283400,36.98488800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Good Shepherd Catholic School",'Santa_Cruz=' + Santa_Cruz.length);
Watsonville[Watsonville.length] = createMarker(new GPoint(-121.77663000,36.93061400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Green Valley Christian School",'Watsonville=' + Watsonville.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.02966300,36.97785300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Holy Cross School",'Santa_Cruz=' + Santa_Cruz.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.00721600,36.97588400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Listen",'Santa_Cruz=' + Santa_Cruz.length);
Boulder_Creek[Boulder_Creek.length] = createMarker(new GPoint(-122.13570000,37.14830000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Little People S School",'Boulder_Creek=' + Boulder_Creek.length);
Aptos[Aptos.length] = createMarker(new GPoint(-121.88452300,36.99232000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Magic Apple School",'Aptos=' + Aptos.length);
Soquel[Soquel.length] = createMarker(new GPoint(-121.96166700,37.01756800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Merit Academy",'Soquel=' + Soquel.length);
Watsonville[Watsonville.length] = createMarker(new GPoint(-121.76794900,36.98208100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Monte Vista Christian School",'Watsonville=' + Watsonville.length);
La_Selva_Beach[La_Selva_Beach.length] = createMarker(new GPoint(-121.83099500,36.91412100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Monterey Bay Academy",'La_Selva_Beach=' + La_Selva_Beach.length);
Watsonville[Watsonville.length] = createMarker(new GPoint(-121.75943200,36.91524300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Moreland Notre Dame School",'Watsonville=' + Watsonville.length);
Watsonville[Watsonville.length] = createMarker(new GPoint(-121.74165500,37.02919000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mount Madonna School",'Watsonville=' + Watsonville.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.03072900,36.97484000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("New Horizons School",'Santa_Cruz=' + Santa_Cruz.length);
Aptos[Aptos.length] = createMarker(new GPoint(-121.88502400,36.99442500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Orchard School",'Aptos=' + Aptos.length);
Watsonville[Watsonville.length] = createMarker(new GPoint(-121.73839000,36.94348200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Francis Central Coast Catholic High School",'Watsonville=' + Watsonville.length);
Felton[Felton.length] = createMarker(new GPoint(-122.07306100,37.05102600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Lawrence Academy",'Felton=' + Felton.length);
Corralitos[Corralitos.length] = createMarker(new GPoint(-121.81766000,37.00263700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Salesian Elementary & Junior High School",'Corralitos=' + Corralitos.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.00521000,36.97982900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Santa Cruz Children's School",'Santa_Cruz=' + Santa_Cruz.length);
Aptos[Aptos.length] = createMarker(new GPoint(-121.93189800,36.99020200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Santa Cruz Montessori School",'Aptos=' + Aptos.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.07358600,37.00543700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Santa Cruz Waldorf School",'Santa_Cruz=' + Santa_Cruz.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.00398700,36.97776100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Seabright Montessori",'Santa_Cruz=' + Santa_Cruz.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-122.03502300,36.96517400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Spring Hill Advanced Elementary School",'Santa_Cruz=' + Santa_Cruz.length);
Soquel[Soquel.length] = createMarker(new GPoint(-121.93761800,37.00645700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Tara Redwood School",'Soquel=' + Soquel.length);
Watsonville[Watsonville.length] = createMarker(new GPoint(-121.78270100,36.92322100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Trinity Lutheran School",'Watsonville=' + Watsonville.length);
Aptos[Aptos.length] = createMarker(new GPoint(-121.92763100,36.98400500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Twin Lakes Christian School",'Aptos=' + Aptos.length);
Santa_Cruz[Santa_Cruz.length] = createMarker(new GPoint(-121.99258000,36.98090300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Vhm Christian School",'Santa_Cruz=' + Santa_Cruz.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(Aptos);
map.removeOverlays(Boulder_Creek);
map.removeOverlays(Corralitos);
map.removeOverlays(Felton);
map.removeOverlays(La_Selva_Beach);
map.removeOverlays(Santa_Cruz);
map.removeOverlays(Scotts_Valley);
map.removeOverlays(Soquel);
map.removeOverlays(Watsonville);
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(Aptos);map.removeOverlays(Aptos);
map.removeOverlays(Boulder_Creek);
map.removeOverlays(Corralitos);
map.removeOverlays(Felton);
map.removeOverlays(La_Selva_Beach);
map.removeOverlays(Santa_Cruz);
map.removeOverlays(Scotts_Valley);
map.removeOverlays(Soquel);
map.removeOverlays(Watsonville);
map.addOverlays(Aptos);
centerByArray(Aptos, false, false);
cntMarker += Aptos.length;
map.addOverlays(Boulder_Creek);
centerByArray(Boulder_Creek, false, false);
cntMarker += Boulder_Creek.length;
map.addOverlays(Corralitos);
centerByArray(Corralitos, false, false);
cntMarker += Corralitos.length;
map.addOverlays(Felton);
centerByArray(Felton, false, false);
cntMarker += Felton.length;
map.addOverlays(La_Selva_Beach);
centerByArray(La_Selva_Beach, false, false);
cntMarker += La_Selva_Beach.length;
map.addOverlays(Santa_Cruz);
centerByArray(Santa_Cruz, false, false);
cntMarker += Santa_Cruz.length;
map.addOverlays(Scotts_Valley);
centerByArray(Scotts_Valley, false, false);
cntMarker += Scotts_Valley.length;
map.addOverlays(Soquel);
centerByArray(Soquel, false, false);
cntMarker += Soquel.length;
map.addOverlays(Watsonville);
centerByArray(Watsonville, false, false);
cntMarker += Watsonville.length;
centerByArray(Aptos,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;
}