function addMarkers(){
mySelect = document.getElementById('selection');
South_Jordan = [];Salt_Lake_City = [];Murray = [];West_Jordan = [];West_Valley_City = [];Draper = [];Midvale = [];Kearns = [];Magna = [];Sandy = [];mySelect.options[mySelect.options.length] = new Option("Draper schools",'all=Draper');
mySelect.options[mySelect.options.length] = new Option("Kearns schools",'all=Kearns');
mySelect.options[mySelect.options.length] = new Option("Magna schools",'all=Magna');
mySelect.options[mySelect.options.length] = new Option("Midvale schools",'all=Midvale');
mySelect.options[mySelect.options.length] = new Option("Murray schools",'all=Murray');
mySelect.options[mySelect.options.length] = new Option("Salt Lake City schools",'all=Salt_Lake_City');
mySelect.options[mySelect.options.length] = new Option("Sandy schools",'all=Sandy');
mySelect.options[mySelect.options.length] = new Option("South Jordan schools",'all=South_Jordan');
mySelect.options[mySelect.options.length] = new Option("West Jordan schools",'all=West_Jordan');
mySelect.options[mySelect.options.length] = new Option("West Valley City schools",'all=West_Valley_City');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
South_Jordan[South_Jordan.length] = createMarker(new GPoint(-111.93885000,40.54908800),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("American Heritage of South Jordan",'South_Jordan=' + South_Jordan.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.83787000,40.64926300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Anchor Christian Academy",'Salt_Lake_City=' + Salt_Lake_City.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.90689500,40.68683300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Applied Scholastics Academy of Salt Lake City",'Salt_Lake_City=' + Salt_Lake_City.length);
Murray[Murray.length] = createMarker(new GPoint(-111.87447400,40.67247100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Benjamin Franklin Academy",'Murray=' + Murray.length);
West_Jordan[West_Jordan.length] = createMarker(new GPoint(-111.93875400,40.60675000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Copper Hills Youth Center",'West_Jordan=' + West_Jordan.length);
Murray[Murray.length] = createMarker(new GPoint(-111.90298200,40.65226900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Deseret Academy",'Murray=' + Murray.length);
West_Valley_City[West_Valley_City.length] = createMarker(new GPoint(-112.00774700,40.68213700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Grace Baptist School",'West_Valley_City=' + West_Valley_City.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.80521100,40.63269100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Intermountain Christian School",'Salt_Lake_City=' + Salt_Lake_City.length);
Draper[Draper.length] = createMarker(new GPoint(-111.88194200,40.53811100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Juan Diego Catholic High School",'Draper=' + Draper.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.85976100,40.75520400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Judge Memorial Catholic High School",'Salt_Lake_City=' + Salt_Lake_City.length);
Draper[Draper.length] = createMarker(new GPoint(-111.89046400,40.52227900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Pine Ridge Academy",'Draper=' + Draper.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.93408000,40.64671000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Primary Children's Medical Center School",'Salt_Lake_City=' + Salt_Lake_City.length);
Midvale[Midvale.length] = createMarker(new GPoint(-111.86579300,40.62536100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Prosperity Academy",'Midvale=' + Midvale.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.86548000,40.74420000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Realms Of Inquiry",'Salt_Lake_City=' + Salt_Lake_City.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.80845200,40.69690600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Reid School",'Salt_Lake_City=' + Salt_Lake_City.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.84550900,40.75354300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Rowland Hall St Marks School",'Salt_Lake_City=' + Salt_Lake_City.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.86566400,40.68416300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Salt Lake Lutheran High School",'Salt_Lake_City=' + Salt_Lake_City.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.85978000,40.72854300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Specialized Educational Progra",'Salt_Lake_City=' + Salt_Lake_City.length);
South_Jordan[South_Jordan.length] = createMarker(new GPoint(-111.93850000,40.54801100),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Stillwater Academy",'South_Jordan=' + South_Jordan.length);
Kearns[Kearns.length] = createMarker(new GPoint(-111.98216700,40.66770400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Valley Christian School",'Kearns=' + Kearns.length);
Magna[Magna.length] = createMarker(new GPoint(-112.08882800,40.71048900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Vista Private School",'Magna=' + Magna.length);
Sandy[Sandy.length] = createMarker(new GPoint(-111.84888600,40.58023300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("The Waterford School",'Sandy=' + Sandy.length);
West_Jordan[West_Jordan.length] = createMarker(new GPoint(-112.02188000,40.58303700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("West Ridge Academy (boys Ranch)",'West_Jordan=' + West_Jordan.length);
Salt_Lake_City[Salt_Lake_City.length] = createMarker(new GPoint(-111.86616800,40.64464500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Woodland Hills School",'Salt_Lake_City=' + Salt_Lake_City.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/////2/' + showArray);
map.removeOverlays(Draper);
map.removeOverlays(Kearns);
map.removeOverlays(Magna);
map.removeOverlays(Midvale);
map.removeOverlays(Murray);
map.removeOverlays(Salt_Lake_City);
map.removeOverlays(Sandy);
map.removeOverlays(South_Jordan);
map.removeOverlays(West_Jordan);
map.removeOverlays(West_Valley_City);
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(South_Jordan);map.removeOverlays(Draper);
map.removeOverlays(Kearns);
map.removeOverlays(Magna);
map.removeOverlays(Midvale);
map.removeOverlays(Murray);
map.removeOverlays(Salt_Lake_City);
map.removeOverlays(Sandy);
map.removeOverlays(South_Jordan);
map.removeOverlays(West_Jordan);
map.removeOverlays(West_Valley_City);
map.addOverlays(Draper);
centerByArray(Draper, false, false);
cntMarker += Draper.length;
map.addOverlays(Kearns);
centerByArray(Kearns, false, false);
cntMarker += Kearns.length;
map.addOverlays(Magna);
centerByArray(Magna, false, false);
cntMarker += Magna.length;
map.addOverlays(Midvale);
centerByArray(Midvale, false, false);
cntMarker += Midvale.length;
map.addOverlays(Murray);
centerByArray(Murray, false, false);
cntMarker += Murray.length;
map.addOverlays(Salt_Lake_City);
centerByArray(Salt_Lake_City, false, false);
cntMarker += Salt_Lake_City.length;
map.addOverlays(Sandy);
centerByArray(Sandy, false, false);
cntMarker += Sandy.length;
map.addOverlays(South_Jordan);
centerByArray(South_Jordan, false, false);
cntMarker += South_Jordan.length;
map.addOverlays(West_Jordan);
centerByArray(West_Jordan, false, false);
cntMarker += West_Jordan.length;
map.addOverlays(West_Valley_City);
centerByArray(West_Valley_City, false, false);
cntMarker += West_Valley_City.length;
centerByArray(South_Jordan,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=2&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;
}