function addMarkers(){
mySelect = document.getElementById('selection');
Carlsbad = [];Mill_Valley = [];Pasadena = [];Sacramento = [];Coronado = [];Berkeley = [];Claremont = [];Campbell = [];Idyllwild = [];San_Mateo = [];Ojai = [];San_Diego = [];San_Marino = [];Stanford = [];Upland = [];Oceanside = [];Los_Angeles = [];mySelect.options[mySelect.options.length] = new Option("Berkeley Schools",'all=Berkeley');
mySelect.options[mySelect.options.length] = new Option("Campbell Schools",'all=Campbell');
mySelect.options[mySelect.options.length] = new Option("Carlsbad Schools",'all=Carlsbad');
mySelect.options[mySelect.options.length] = new Option("Claremont Schools",'all=Claremont');
mySelect.options[mySelect.options.length] = new Option("Coronado Schools",'all=Coronado');
mySelect.options[mySelect.options.length] = new Option("Idyllwild Schools",'all=Idyllwild');
mySelect.options[mySelect.options.length] = new Option("Los Angeles Schools",'all=Los_Angeles');
mySelect.options[mySelect.options.length] = new Option("Mill Valley Schools",'all=Mill_Valley');
mySelect.options[mySelect.options.length] = new Option("Oceanside Schools",'all=Oceanside');
mySelect.options[mySelect.options.length] = new Option("Ojai Schools",'all=Ojai');
mySelect.options[mySelect.options.length] = new Option("Pasadena Schools",'all=Pasadena');
mySelect.options[mySelect.options.length] = new Option("Sacramento Schools",'all=Sacramento');
mySelect.options[mySelect.options.length] = new Option("San Diego Schools",'all=San_Diego');
mySelect.options[mySelect.options.length] = new Option("San Marino Schools",'all=San_Marino');
mySelect.options[mySelect.options.length] = new Option("San Mateo Schools",'all=San_Mateo');
mySelect.options[mySelect.options.length] = new Option("Stanford Schools",'all=Stanford');
mySelect.options[mySelect.options.length] = new Option("Upland Schools",'all=Upland');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Carlsbad[Carlsbad.length] = createMarker(new GLatLng(33.16234860,-117.35425000),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Academy By The Sea / Camp Pacific",'Carlsbad=' + Carlsbad.length);
Mill_Valley[Mill_Valley.length] = createMarker(new GLatLng(37.89362200,-122.51630300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Adventures Cross-country",'Mill_Valley=' + Mill_Valley.length);
Pasadena[Pasadena.length] = createMarker(new GLatLng(34.14492600,-118.14976700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Brighton",'Pasadena=' + Pasadena.length);
Sacramento[Sacramento.length] = createMarker(new GLatLng(38.58766800,-121.41938800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("California State Summer School For The Arts/inner Spark",'Sacramento=' + Sacramento.length);
Coronado[Coronado.length] = createMarker(new GLatLng(32.69710430,-117.17179720),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Camp La Jolla",'Coronado=' + Coronado.length);
Berkeley[Berkeley.length] = createMarker(new GLatLng(37.87657360,-122.26895000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Education Unlimited",'Berkeley=' + Berkeley.length);
Pasadena[Pasadena.length] = createMarker(new GLatLng(34.14492600,-118.14976700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Fls International",'Pasadena=' + Pasadena.length);
Claremont[Claremont.length] = createMarker(new GLatLng(34.12159500,-117.71590100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Guided Discoveries",'Claremont=' + Claremont.length);
Campbell[Campbell.length] = createMarker(new GLatLng(37.28954200,-121.95013400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Id Tech Camps",'Campbell=' + Campbell.length);
Idyllwild[Idyllwild.length] = createMarker(new GLatLng(33.73986800,-116.71960000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Idyllwild Arts Foundation",'Idyllwild=' + Idyllwild.length);
San_Mateo[San_Mateo.length] = createMarker(new GLatLng(37.56358500,-122.32462100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Junior Statesmen Foundation",'San_Mateo=' + San_Mateo.length);
Ojai[Ojai.length] = createMarker(new GLatLng(34.44403400,-119.25728100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Ojai Valley School",'Ojai=' + Ojai.length);
San_Diego[San_Diego.length] = createMarker(new GLatLng(32.71568500,-117.16172400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Seaworld Adventure Park",'San_Diego=' + San_Diego.length);
San_Marino[San_Marino.length] = createMarker(new GLatLng(34.11514900,-118.13212300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Southwestern Academy",'San_Marino=' + San_Marino.length);
Stanford[Stanford.length] = createMarker(new GLatLng(49.31544610,-124.31235180),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Stanford University Summer Session",'Stanford=' + Stanford.length);
Upland[Upland.length] = createMarker(new GLatLng(34.09747700,-117.64878300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Summer Camp For The Young Actor, Inc.",'Upland=' + Upland.length);
Oceanside[Oceanside.length] = createMarker(new GLatLng(33.17594400,-117.36314500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Supercamp",'Oceanside=' + Oceanside.length);
Los_Angeles[Los_Angeles.length] = createMarker(new GLatLng(34.02204700,-118.28673000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("University Of Southern California, School Of Architecture",'Los_Angeles=' + Los_Angeles.length);
map.removeOverlays(Berkeley);
map.removeOverlays(Campbell);
map.removeOverlays(Carlsbad);
map.removeOverlays(Claremont);
map.removeOverlays(Coronado);
map.removeOverlays(Idyllwild);
map.removeOverlays(Los_Angeles);
map.removeOverlays(Mill_Valley);
map.removeOverlays(Oceanside);
map.removeOverlays(Ojai);
map.removeOverlays(Pasadena);
map.removeOverlays(Sacramento);
map.removeOverlays(San_Diego);
map.removeOverlays(San_Marino);
map.removeOverlays(San_Mateo);
map.removeOverlays(Stanford);
map.removeOverlays(Upland);
setTimeout(function(){map.addOverlays(Berkeley)},1000);
setTimeout(function(){map.addOverlays(Campbell)},1000);
setTimeout(function(){map.addOverlays(Carlsbad)},1000);
setTimeout(function(){map.addOverlays(Claremont)},1000);
setTimeout(function(){map.addOverlays(Coronado)},1000);
setTimeout(function(){map.addOverlays(Idyllwild)},1000);
setTimeout(function(){map.addOverlays(Los_Angeles)},1000);
setTimeout(function(){map.addOverlays(Mill_Valley)},1000);
setTimeout(function(){map.addOverlays(Oceanside)},1000);
setTimeout(function(){map.addOverlays(Ojai)},1000);
setTimeout(function(){map.addOverlays(Pasadena)},1000);
setTimeout(function(){map.addOverlays(Sacramento)},1000);
setTimeout(function(){map.addOverlays(San_Diego)},1000);
setTimeout(function(){map.addOverlays(San_Marino)},1000);
setTimeout(function(){map.addOverlays(San_Mateo)},1000);
setTimeout(function(){map.addOverlays(Stanford)},1000);
setTimeout(function(){map.addOverlays(Upland)},1000);
maxLng = -116.71960000;
maxLat = 49.31544610;
minLng = -124.31235180;
minLat = 32.69710430;
reCenterMap();
}
// End addStateMarkers JavaScript Function
function openAll() {
if (map) {
selectChange("all");
} else {
setTimeout("openAll()",200);
}
}
// 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].point.x;
var markLat = myArray[i].point.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){
//alert(myArray[0].point.x);
maxLng = myArray[0].point.x;
maxLat = myArray[0].point.y;
minLng = myArray[0].point.x;
minLat = myArray[0].point.y;
}
// Recenter map based on global max/mins
function reCenterMap(){
//alert('#' + minLat + '#' + minLng + '#' + maxLat + '#' + maxLng);
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);
if(minLat == maxLat) zoom = 9;
map.setCenter(center,zoom);
//map.setCenter(center,10);
/*
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////all');
map.removeOverlays(Berkeley);
map.removeOverlays(Campbell);
map.removeOverlays(Carlsbad);
map.removeOverlays(Claremont);
map.removeOverlays(Coronado);
map.removeOverlays(Idyllwild);
map.removeOverlays(Los_Angeles);
map.removeOverlays(Mill_Valley);
map.removeOverlays(Oceanside);
map.removeOverlays(Ojai);
map.removeOverlays(Pasadena);
map.removeOverlays(Sacramento);
map.removeOverlays(San_Diego);
map.removeOverlays(San_Marino);
map.removeOverlays(San_Mateo);
map.removeOverlays(Stanford);
map.removeOverlays(Upland);
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(Carlsbad);map.removeOverlays(Berkeley);
map.removeOverlays(Campbell);
map.removeOverlays(Carlsbad);
map.removeOverlays(Claremont);
map.removeOverlays(Coronado);
map.removeOverlays(Idyllwild);
map.removeOverlays(Los_Angeles);
map.removeOverlays(Mill_Valley);
map.removeOverlays(Oceanside);
map.removeOverlays(Ojai);
map.removeOverlays(Pasadena);
map.removeOverlays(Sacramento);
map.removeOverlays(San_Diego);
map.removeOverlays(San_Marino);
map.removeOverlays(San_Mateo);
map.removeOverlays(Stanford);
map.removeOverlays(Upland);
map.addOverlays(Berkeley);
centerByArray(Berkeley, false, false);
cntMarker += Berkeley.length;
map.addOverlays(Campbell);
centerByArray(Campbell, false, false);
cntMarker += Campbell.length;
map.addOverlays(Carlsbad);
centerByArray(Carlsbad, false, false);
cntMarker += Carlsbad.length;
map.addOverlays(Claremont);
centerByArray(Claremont, false, false);
cntMarker += Claremont.length;
map.addOverlays(Coronado);
centerByArray(Coronado, false, false);
cntMarker += Coronado.length;
map.addOverlays(Idyllwild);
centerByArray(Idyllwild, false, false);
cntMarker += Idyllwild.length;
map.addOverlays(Los_Angeles);
centerByArray(Los_Angeles, false, false);
cntMarker += Los_Angeles.length;
map.addOverlays(Mill_Valley);
centerByArray(Mill_Valley, false, false);
cntMarker += Mill_Valley.length;
map.addOverlays(Oceanside);
centerByArray(Oceanside, false, false);
cntMarker += Oceanside.length;
map.addOverlays(Ojai);
centerByArray(Ojai, false, false);
cntMarker += Ojai.length;
map.addOverlays(Pasadena);
centerByArray(Pasadena, false, false);
cntMarker += Pasadena.length;
map.addOverlays(Sacramento);
centerByArray(Sacramento, false, false);
cntMarker += Sacramento.length;
map.addOverlays(San_Diego);
centerByArray(San_Diego, false, false);
cntMarker += San_Diego.length;
map.addOverlays(San_Marino);
centerByArray(San_Marino, false, false);
cntMarker += San_Marino.length;
map.addOverlays(San_Mateo);
centerByArray(San_Mateo, false, false);
cntMarker += San_Mateo.length;
map.addOverlays(Stanford);
centerByArray(Stanford, false, false);
cntMarker += Stanford.length;
map.addOverlays(Upland);
centerByArray(Upland, false, false);
cntMarker += Upland.length;
centerByArray(Carlsbad,true, false);
//if (cntMarker > 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/all');
//else
//window.open('/search////all');
}
}
function createMarker(point, label, icon){
var marker = new GMarker(point, icon);
var html = label;
GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); });
return marker;
}