function addMarkers()
{
mySelect = document.getElementById('selection');
Tucson = [];Phoenix = [];Glendale = [];Mesa = [];Gilbert = [];Surprise = [];Thatcher = [];Show_Low = [];Centennial_Park = [];Nogales = [];Tempe = [];mySelect.options[mySelect.options.length] = new Option("Centennial Park schools",'all=Centennial_Park');
mySelect.options[mySelect.options.length] = new Option("Gilbert schools",'all=Gilbert');
mySelect.options[mySelect.options.length] = new Option("Glendale schools",'all=Glendale');
mySelect.options[mySelect.options.length] = new Option("Mesa schools",'all=Mesa');
mySelect.options[mySelect.options.length] = new Option("Nogales schools",'all=Nogales');
mySelect.options[mySelect.options.length] = new Option("Phoenix schools",'all=Phoenix');
mySelect.options[mySelect.options.length] = new Option("Show Low schools",'all=Show_Low');
mySelect.options[mySelect.options.length] = new Option("Surprise schools",'all=Surprise');
mySelect.options[mySelect.options.length] = new Option("Tempe schools",'all=Tempe');
mySelect.options[mySelect.options.length] = new Option("Thatcher schools",'all=Thatcher');
mySelect.options[mySelect.options.length] = new Option("Tucson schools",'all=Tucson');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Tucson[Tucson.length] = createMarker(new GPoint(-110.99889374,32.27206421),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Academy Of Math And Science",'Tucson=' + Tucson.length);
Phoenix[Phoenix.length] = createMarker(new GPoint(-112.07111359,33.46300125),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Arizona School For Arts",'Phoenix=' + Phoenix.length);
Glendale[Glendale.length] = createMarker(new GPoint(-112.18421173,33.64281464),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Challenge Charter School",'Glendale=' + Glendale.length);
Mesa[Mesa.length] = createMarker(new GPoint(-111.74160767,33.43013763),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Entz Elementary School",'Mesa=' + Mesa.length);
Mesa[Mesa.length] = createMarker(new GPoint(-111.67713928,33.42984009),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Franklin Northeast School",'Mesa=' + Mesa.length);
Mesa[Mesa.length] = createMarker(new GPoint(-111.82906342,33.40990067),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Franklin West Elementary School",'Mesa=' + Mesa.length);
Gilbert[Gilbert.length] = createMarker(new GPoint(-111.79705811,33.36050797),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Gps Traditional Academy",'Gilbert=' + Gilbert.length);
Gilbert[Gilbert.length] = createMarker(new GPoint(-111.78976440,33.34663391),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Highland High School",'Gilbert=' + Gilbert.length);
Surprise[Surprise.length] = createMarker(new GPoint(-112.37649300,33.59051000),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Imagine Charter Elementary School At Rosefield",'Surprise=' + Surprise.length);
Thatcher[Thatcher.length] = createMarker(new GPoint(-109.76110077,32.82979965),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Jack Daley Primary School",'Thatcher=' + Thatcher.length);
Show_Low[Show_Low.length] = createMarker(new GPoint(-110.04792000,34.25697500),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Linden Elementary School",'Show_Low=' + Show_Low.length);
Mesa[Mesa.length] = createMarker(new GPoint(-111.79323578,33.40918732),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Longfellow Elementary School",'Mesa=' + Mesa.length);
Phoenix[Phoenix.length] = createMarker(new GPoint(-112.03476715,33.54100418),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Madison Heights School",'Phoenix=' + Phoenix.length);
Centennial_Park[Centennial_Park.length] = createMarker(new GPoint(-112.55400085,34.59519958),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Masada Charter School",'Centennial_Park=' + Centennial_Park.length);
Tucson[Tucson.length] = createMarker(new GPoint(-110.94366455,32.14844131),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Ocotillo Elementary School",'Tucson=' + Tucson.length);
Tucson[Tucson.length] = createMarker(new GPoint(-110.94673157,32.26493835),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Presidio High School",'Tucson=' + Tucson.length);
Nogales[Nogales.length] = createMarker(new GPoint(-110.97309875,31.39809990),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Robert Bracker Elementary School",'Nogales=' + Nogales.length);
Tempe[Tempe.length] = createMarker(new GPoint(-111.91893005,33.39294434),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Tempe Preparatory Academy",'Tempe=' + Tempe.length);
Tucson[Tucson.length] = createMarker(new GPoint(-110.88825989,32.22623444),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("University High School",'Tucson=' + Tucson.length);
map.removeOverlays(Centennial_Park);
map.removeOverlays(Gilbert);
map.removeOverlays(Glendale);
map.removeOverlays(Mesa);
map.removeOverlays(Nogales);
map.removeOverlays(Phoenix);
map.removeOverlays(Show_Low);
map.removeOverlays(Surprise);
map.removeOverlays(Tempe);
map.removeOverlays(Thatcher);
map.removeOverlays(Tucson);
setTimeout(function(){map.addOverlays(Centennial_Park)},1000);
setTimeout(function(){map.addOverlays(Gilbert)},1000);
setTimeout(function(){map.addOverlays(Glendale)},1000);
setTimeout(function(){map.addOverlays(Mesa)},1000);
setTimeout(function(){map.addOverlays(Nogales)},1000);
setTimeout(function(){map.addOverlays(Phoenix)},1000);
setTimeout(function(){map.addOverlays(Show_Low)},1000);
setTimeout(function(){map.addOverlays(Surprise)},1000);
setTimeout(function(){map.addOverlays(Tempe)},1000);
setTimeout(function(){map.addOverlays(Thatcher)},1000);
setTimeout(function(){map.addOverlays(Tucson)},1000);
maxLng = -109.76110077;
maxLat = 34.59519958;
minLng = -112.55400085;
minLat = 31.39809990;
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,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////' + showArray);
map.removeOverlays(Centennial_Park);
map.removeOverlays(Gilbert);
map.removeOverlays(Glendale);
map.removeOverlays(Mesa);
map.removeOverlays(Nogales);
map.removeOverlays(Phoenix);
map.removeOverlays(Show_Low);
map.removeOverlays(Surprise);
map.removeOverlays(Tempe);
map.removeOverlays(Thatcher);
map.removeOverlays(Tucson);
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(Tucson);map.removeOverlays(Centennial_Park);
map.removeOverlays(Gilbert);
map.removeOverlays(Glendale);
map.removeOverlays(Mesa);
map.removeOverlays(Nogales);
map.removeOverlays(Phoenix);
map.removeOverlays(Show_Low);
map.removeOverlays(Surprise);
map.removeOverlays(Tempe);
map.removeOverlays(Thatcher);
map.removeOverlays(Tucson);
map.addOverlays(Centennial_Park);
centerByArray(Centennial_Park, false, false);
cntMarker += Centennial_Park.length;
map.addOverlays(Gilbert);
centerByArray(Gilbert, false, false);
cntMarker += Gilbert.length;
map.addOverlays(Glendale);
centerByArray(Glendale, false, false);
cntMarker += Glendale.length;
map.addOverlays(Mesa);
centerByArray(Mesa, false, false);
cntMarker += Mesa.length;
map.addOverlays(Nogales);
centerByArray(Nogales, false, false);
cntMarker += Nogales.length;
map.addOverlays(Phoenix);
centerByArray(Phoenix, false, false);
cntMarker += Phoenix.length;
map.addOverlays(Show_Low);
centerByArray(Show_Low, false, false);
cntMarker += Show_Low.length;
map.addOverlays(Surprise);
centerByArray(Surprise, false, false);
cntMarker += Surprise.length;
map.addOverlays(Tempe);
centerByArray(Tempe, false, false);
cntMarker += Tempe.length;
map.addOverlays(Thatcher);
centerByArray(Thatcher, false, false);
cntMarker += Thatcher.length;
map.addOverlays(Tucson);
centerByArray(Tucson, false, false);
cntMarker += Tucson.length;
centerByArray(Tucson,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///2613,1948,1969,2492,2136,3493,1948,2492,2136,2242,2625,2089,2844,2899,2841,2865,2959,1948,2801,122877,125739,3383,2492,3335,2136,/all');
}
}