function addMarkers(){
mySelect = document.getElementById('selection');
Glendale = [];Phoenix = [];Rimrock = [];Tucson = [];Scottsdale = [];Kingman = [];Chandler = [];Mayer = [];Tempe = [];Paradise_Valley = [];Gilbert = [];Mesa = [];Prescott = [];mySelect.options[mySelect.options.length] = new Option("Chandler schools",'all=Chandler');
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("Kingman schools",'all=Kingman');
mySelect.options[mySelect.options.length] = new Option("Mayer schools",'all=Mayer');
mySelect.options[mySelect.options.length] = new Option("Mesa schools",'all=Mesa');
mySelect.options[mySelect.options.length] = new Option("Paradise Valley schools",'all=Paradise_Valley');
mySelect.options[mySelect.options.length] = new Option("Phoenix schools",'all=Phoenix');
mySelect.options[mySelect.options.length] = new Option("Prescott schools",'all=Prescott');
mySelect.options[mySelect.options.length] = new Option("Rimrock schools",'all=Rimrock');
mySelect.options[mySelect.options.length] = new Option("Scottsdale schools",'all=Scottsdale');
mySelect.options[mySelect.options.length] = new Option("Tempe schools",'all=Tempe');
mySelect.options[mySelect.options.length] = new Option("Tucson schools",'all=Tucson');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Glendale[Glendale.length] = createMarker(new GPoint(-112.18963300,33.58168300),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Abcs/smithey-link Education Center",'Glendale=' + Glendale.length);
Phoenix[Phoenix.length] = createMarker(new GPoint(-112.11300000,34.74880000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Arcadia Montessori School",'Phoenix=' + Phoenix.length);
Rimrock[Rimrock.length] = createMarker(new GPoint(-111.78037100,34.64175600),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Copper Canyon Academy",'Rimrock=' + Rimrock.length);
Tucson[Tucson.length] = createMarker(new GPoint(-110.85270000,32.25010000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Desert Christian High School",'Tucson=' + Tucson.length);
Phoenix[Phoenix.length] = createMarker(new GPoint(-112.00779600,33.58265800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Desert Voices Oral Learning Center",'Phoenix=' + Phoenix.length);
Tucson[Tucson.length] = createMarker(new GPoint(-110.81388400,32.30155100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Fenster School",'Tucson=' + Tucson.length);
Phoenix[Phoenix.length] = createMarker(new GPoint(-111.98074600,33.62054600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Jess Schwartz College Prep: The Jewish Community's High School",'Phoenix=' + Phoenix.length);
Scottsdale[Scottsdale.length] = createMarker(new GPoint(-111.92565000,33.60173600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The King David School",'Scottsdale=' + Scottsdale.length);
Kingman[Kingman.length] = createMarker(new GPoint(-114.05542800,35.18882400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Kingman Adventist Christian School",'Kingman=' + Kingman.length);
Tucson[Tucson.length] = createMarker(new GPoint(-110.96133400,32.32669400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Kino School",'Tucson=' + Tucson.length);
Chandler[Chandler.length] = createMarker(new GPoint(-111.87056400,33.33525700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Montessori Day Schools Lakeshore",'Chandler=' + Chandler.length);
Mayer[Mayer.length] = createMarker(new GPoint(-112.15059200,34.34842300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Orme School Of Arizona",'Mayer=' + Mayer.length);
Tempe[Tempe.length] = createMarker(new GPoint(-111.92613500,33.40593000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Our Lady Of Mount Carmel School",'Tempe=' + Tempe.length);
Paradise_Valley[Paradise_Valley.length] = createMarker(new GPoint(-111.99745200,33.51710000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Phoenix Country Day School",'Paradise_Valley=' + Paradise_Valley.length);
Gilbert[Gilbert.length] = createMarker(new GPoint(-111.78958400,33.32589500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Rancho Solano Private Schools",'Gilbert=' + Gilbert.length);
Scottsdale[Scottsdale.length] = createMarker(new GPoint(-111.95881500,33.62619900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Rancho Solano Private Schools-greenway Campus",'Scottsdale=' + Scottsdale.length);
Mesa[Mesa.length] = createMarker(new GPoint(-111.80512400,33.42853100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Redeemer Christian School (Classical)",'Mesa=' + Mesa.length);
Prescott[Prescott.length] = createMarker(new GPoint(-112.47491400,34.54271200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Sacred Heart Catholic School",'Prescott=' + Prescott.length);
Tucson[Tucson.length] = createMarker(new GPoint(-110.89198800,32.24353700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St. Cyril Elementary School",'Tucson=' + Tucson.length);
Scottsdale[Scottsdale.length] = createMarker(new GPoint(-111.91769800,33.49586100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Scottsdale United Methodist Co Operative Preschool and Kindergarten",'Scottsdale=' + Scottsdale.length);
Tucson[Tucson.length] = createMarker(new GPoint(-110.93536100,32.21899300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Ambrose School",'Tucson=' + Tucson.length);
Tucson[Tucson.length] = createMarker(new GPoint(-111.02955400,32.36177300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Elizabeth Ann Seton School",'Tucson=' + Tucson.length);
Phoenix[Phoenix.length] = createMarker(new GPoint(-112.13393400,33.58449800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Jerome Elementary School",'Phoenix=' + Phoenix.length);
Phoenix[Phoenix.length] = createMarker(new GPoint(-112.10365400,33.45133700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("St Matthew School",'Phoenix=' + Phoenix.length);
Phoenix[Phoenix.length] = createMarker(new GPoint(-111.99490900,33.59688800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Valley Child Care & Learning Center",'Phoenix=' + Phoenix.length);
map.removeOverlays(Chandler);
map.removeOverlays(Gilbert);
map.removeOverlays(Glendale);
map.removeOverlays(Kingman);
map.removeOverlays(Mayer);
map.removeOverlays(Mesa);
map.removeOverlays(Paradise_Valley);
map.removeOverlays(Phoenix);
map.removeOverlays(Prescott);
map.removeOverlays(Rimrock);
map.removeOverlays(Scottsdale);
map.removeOverlays(Tempe);
map.removeOverlays(Tucson);
setTimeout(function(){map.addOverlays(Chandler)},1000);
setTimeout(function(){map.addOverlays(Gilbert)},1000);
setTimeout(function(){map.addOverlays(Glendale)},1000);
setTimeout(function(){map.addOverlays(Kingman)},1000);
setTimeout(function(){map.addOverlays(Mayer)},1000);
setTimeout(function(){map.addOverlays(Mesa)},1000);
setTimeout(function(){map.addOverlays(Paradise_Valley)},1000);
setTimeout(function(){map.addOverlays(Phoenix)},1000);
setTimeout(function(){map.addOverlays(Prescott)},1000);
setTimeout(function(){map.addOverlays(Rimrock)},1000);
setTimeout(function(){map.addOverlays(Scottsdale)},1000);
setTimeout(function(){map.addOverlays(Tempe)},1000);
setTimeout(function(){map.addOverlays(Tucson)},1000);
maxLng = -110.81388400;
maxLat = 35.18882400;
minLng = -114.05542800;
minLat = 32.21899300;
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(Chandler);
map.removeOverlays(Gilbert);
map.removeOverlays(Glendale);
map.removeOverlays(Kingman);
map.removeOverlays(Mayer);
map.removeOverlays(Mesa);
map.removeOverlays(Paradise_Valley);
map.removeOverlays(Phoenix);
map.removeOverlays(Prescott);
map.removeOverlays(Rimrock);
map.removeOverlays(Scottsdale);
map.removeOverlays(Tempe);
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(Glendale);map.removeOverlays(Chandler);
map.removeOverlays(Gilbert);
map.removeOverlays(Glendale);
map.removeOverlays(Kingman);
map.removeOverlays(Mayer);
map.removeOverlays(Mesa);
map.removeOverlays(Paradise_Valley);
map.removeOverlays(Phoenix);
map.removeOverlays(Prescott);
map.removeOverlays(Rimrock);
map.removeOverlays(Scottsdale);
map.removeOverlays(Tempe);
map.removeOverlays(Tucson);
map.addOverlays(Chandler);
centerByArray(Chandler, false, false);
cntMarker += Chandler.length;
map.addOverlays(Gilbert);
centerByArray(Gilbert, false, false);
cntMarker += Gilbert.length;
map.addOverlays(Glendale);
centerByArray(Glendale, false, false);
cntMarker += Glendale.length;
map.addOverlays(Kingman);
centerByArray(Kingman, false, false);
cntMarker += Kingman.length;
map.addOverlays(Mayer);
centerByArray(Mayer, false, false);
cntMarker += Mayer.length;
map.addOverlays(Mesa);
centerByArray(Mesa, false, false);
cntMarker += Mesa.length;
map.addOverlays(Paradise_Valley);
centerByArray(Paradise_Valley, false, false);
cntMarker += Paradise_Valley.length;
map.addOverlays(Phoenix);
centerByArray(Phoenix, false, false);
cntMarker += Phoenix.length;
map.addOverlays(Prescott);
centerByArray(Prescott, false, false);
cntMarker += Prescott.length;
map.addOverlays(Rimrock);
centerByArray(Rimrock, false, false);
cntMarker += Rimrock.length;
map.addOverlays(Scottsdale);
centerByArray(Scottsdale, false, false);
cntMarker += Scottsdale.length;
map.addOverlays(Tempe);
centerByArray(Tempe, false, false);
cntMarker += Tempe.length;
map.addOverlays(Tucson);
centerByArray(Tucson, false, false);
cntMarker += Tucson.length;
centerByArray(Glendale,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///35805,737,668,653,35799,541,548,35798,605,35804,35805,35796,35800,737,668,653,507,788,703,711,35806,671,686,35802,818,637,605,698,694,35803,/all');
//window.open('/map.php?type=2&schools=35805,737,668,653,35799,541,548,35798,605,35804,35805,35796,35800,737,668,653,507,788,703,711,35806,671,686,35802,818,637,605,698,694,35803,&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;
}