function addMarkers()
{
mySelect = document.getElementById('selection');
Barnesville = [];Moorhead = [];Dilworth = [];Glyndon = [];Hawley = [];Ulen = [];mySelect.options[mySelect.options.length] = new Option("Barnesville schools",'all=Barnesville');
mySelect.options[mySelect.options.length] = new Option("Dilworth schools",'all=Dilworth');
mySelect.options[mySelect.options.length] = new Option("Glyndon schools",'all=Glyndon');
mySelect.options[mySelect.options.length] = new Option("Hawley schools",'all=Hawley');
mySelect.options[mySelect.options.length] = new Option("Moorhead schools",'all=Moorhead');
mySelect.options[mySelect.options.length] = new Option("Ulen schools",'all=Ulen');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Barnesville[Barnesville.length] = createMarker(new GPoint(-96.40920258,46.67789841),"
",iconRd);
mySelect.options[mySelect.options.length] = new Option("Barnesville Elementary School",'Barnesville=' + Barnesville.length);
Barnesville[Barnesville.length] = createMarker(new GPoint(-96.40920258,46.67789841),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Barnesville Secondary School",'Barnesville=' + Barnesville.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.74256134,46.87192917),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Clay County Outreach Center",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.77166400,46.87504500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Clay County Shelter Care",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.76531982,46.88356400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Clay County Shelter Care High School",'Moorhead=' + Moorhead.length);
Dilworth[Dilworth.length] = createMarker(new GPoint(-96.70089722,46.87829971),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Dilworth Elementary School",'Dilworth=' + Dilworth.length);
Dilworth[Dilworth.length] = createMarker(new GPoint(-96.70089722,46.87829971),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Dilworth-glyndon-felton Junior Middle School",'Dilworth=' + Dilworth.length);
Glyndon[Glyndon.length] = createMarker(new GPoint(-96.57039642,46.88259888),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Dilworth-glyndon-felton Senior High School",'Glyndon=' + Glyndon.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.75730133,46.86280823),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Edison Elementary School",'Moorhead=' + Moorhead.length);
Glyndon[Glyndon.length] = createMarker(new GPoint(-96.57039642,46.88259888),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Glyndon-felton Elementary School",'Glyndon=' + Glyndon.length);
Hawley[Hawley.length] = createMarker(new GPoint(-96.30439758,46.87670135),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Hawley Elementary School",'Hawley=' + Hawley.length);
Hawley[Hawley.length] = createMarker(new GPoint(-96.30439758,46.87670135),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Hawley Secondary School",'Hawley=' + Hawley.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.77160900,46.87504000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Moorhead Alternative Program",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.76259613,46.85469818),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Moorhead Junior Middle School",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.74419403,46.87143707),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Moorhead Senior High School",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.76290131,46.84203720),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Moorhead Ts",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.75745400,46.85121000),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Probstfield Center For Ed.",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.75720978,46.85108185),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Probstfield Elementary School",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.76229858,46.88510513),"",iconBl);
mySelect.options[mySelect.options.length] = new Option("Robert Asp Elementary School",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.76290131,46.84203720),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Rralc",'Moorhead=' + Moorhead.length);
Hawley[Hawley.length] = createMarker(new GPoint(-96.30439758,46.87670135),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Spring Prairie Elementary School",'Hawley=' + Hawley.length);
Ulen[Ulen.length] = createMarker(new GPoint(-96.28160095,47.09049988),"",iconRd);
mySelect.options[mySelect.options.length] = new Option("Ulen-hitterdal Elementary School",'Ulen=' + Ulen.length);
Ulen[Ulen.length] = createMarker(new GPoint(-96.28160095,47.09049988),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Ulen-hitterdal Secondary School",'Ulen=' + Ulen.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.76531982,46.88356400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("W. Central Juvenile Center",'Moorhead=' + Moorhead.length);
Moorhead[Moorhead.length] = createMarker(new GPoint(-96.74543762,46.86206436),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Youth Educational Services High School",'Moorhead=' + Moorhead.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,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(Barnesville);
map.removeOverlays(Dilworth);
map.removeOverlays(Glyndon);
map.removeOverlays(Hawley);
map.removeOverlays(Moorhead);
map.removeOverlays(Ulen);
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(Barnesville);map.removeOverlays(Barnesville);
map.removeOverlays(Dilworth);
map.removeOverlays(Glyndon);
map.removeOverlays(Hawley);
map.removeOverlays(Moorhead);
map.removeOverlays(Ulen);
map.addOverlays(Barnesville);
centerByArray(Barnesville, false, false);
cntMarker += Barnesville.length;
map.addOverlays(Dilworth);
centerByArray(Dilworth, false, false);
cntMarker += Dilworth.length;
map.addOverlays(Glyndon);
centerByArray(Glyndon, false, false);
cntMarker += Glyndon.length;
map.addOverlays(Hawley);
centerByArray(Hawley, false, false);
cntMarker += Hawley.length;
map.addOverlays(Moorhead);
centerByArray(Moorhead, false, false);
cntMarker += Moorhead.length;
map.addOverlays(Ulen);
centerByArray(Ulen, false, false);
cntMarker += Ulen.length;
centerByArray(Barnesville,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');
}
}