function addMarkers(){
mySelect = document.getElementById('selection');
Detroit = [];Dearborn = [];Canton = [];Flint = [];Swartz_Creek = [];East_Lansing = [];Franklin = [];Ann_Arbor = [];mySelect.options[mySelect.options.length] = new Option("Ann Arbor schools",'all=Ann_Arbor');
mySelect.options[mySelect.options.length] = new Option("Canton schools",'all=Canton');
mySelect.options[mySelect.options.length] = new Option("Dearborn schools",'all=Dearborn');
mySelect.options[mySelect.options.length] = new Option("Detroit schools",'all=Detroit');
mySelect.options[mySelect.options.length] = new Option("East Lansing schools",'all=East_Lansing');
mySelect.options[mySelect.options.length] = new Option("Flint schools",'all=Flint');
mySelect.options[mySelect.options.length] = new Option("Franklin schools",'all=Franklin');
mySelect.options[mySelect.options.length] = new Option("Swartz Creek schools",'all=Swartz_Creek');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Detroit[Detroit.length] = createMarker(new GPoint(-83.04091000,42.39073700),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Al-ikhlas Training Academy",'Detroit=' + Detroit.length);
Dearborn[Dearborn.length] = createMarker(new GPoint(-83.17668400,42.33698200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("American Islamic Academy",'Dearborn=' + Dearborn.length);
Canton[Canton.length] = createMarker(new GPoint(-83.43827500,42.29421800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Crescent Academy International",'Canton=' + Canton.length);
Flint[Flint.length] = createMarker(new GPoint(-83.71256900,43.06733700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Flint Islamic Pre-school/doren",'Flint=' + Flint.length);
Swartz_Creek[Swartz_Creek.length] = createMarker(new GPoint(-83.86801200,43.00076300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Genesee Academy",'Swartz_Creek=' + Swartz_Creek.length);
East_Lansing[East_Lansing.length] = createMarker(new GPoint(-84.49408600,42.72391200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Greater Lansing Islamic School",'East_Lansing=' + East_Lansing.length);
Franklin[Franklin.length] = createMarker(new GPoint(-83.30561300,42.52326300),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Huda School And Montessori",'Franklin=' + Franklin.length);
Ann_Arbor[Ann_Arbor.length] = createMarker(new GPoint(-83.71330000,42.30166500),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Michigan Islamic Academy",'Ann_Arbor=' + Ann_Arbor.length);
Detroit[Detroit.length] = createMarker(new GPoint(-83.15935400,42.39891700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Muhammad University Islam",'Detroit=' + Detroit.length);
Dearborn[Dearborn.length] = createMarker(new GPoint(-83.22649900,42.32903700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Muslim American Youth Academy",'Dearborn=' + Dearborn.length);
map.removeOverlays(Ann_Arbor);
map.removeOverlays(Canton);
map.removeOverlays(Dearborn);
map.removeOverlays(Detroit);
map.removeOverlays(East_Lansing);
map.removeOverlays(Flint);
map.removeOverlays(Franklin);
map.removeOverlays(Swartz_Creek);
setTimeout(function(){map.addOverlays(Ann_Arbor)},1000);
setTimeout(function(){map.addOverlays(Canton)},1000);
setTimeout(function(){map.addOverlays(Dearborn)},1000);
setTimeout(function(){map.addOverlays(Detroit)},1000);
setTimeout(function(){map.addOverlays(East_Lansing)},1000);
setTimeout(function(){map.addOverlays(Flint)},1000);
setTimeout(function(){map.addOverlays(Franklin)},1000);
setTimeout(function(){map.addOverlays(Swartz_Creek)},1000);
maxLng = -83.04091000;
maxLat = 43.06733700;
minLng = -84.49408600;
minLat = 42.29421800;
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(Ann_Arbor);
map.removeOverlays(Canton);
map.removeOverlays(Dearborn);
map.removeOverlays(Detroit);
map.removeOverlays(East_Lansing);
map.removeOverlays(Flint);
map.removeOverlays(Franklin);
map.removeOverlays(Swartz_Creek);
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(Detroit);map.removeOverlays(Ann_Arbor);
map.removeOverlays(Canton);
map.removeOverlays(Dearborn);
map.removeOverlays(Detroit);
map.removeOverlays(East_Lansing);
map.removeOverlays(Flint);
map.removeOverlays(Franklin);
map.removeOverlays(Swartz_Creek);
map.addOverlays(Ann_Arbor);
centerByArray(Ann_Arbor, false, false);
cntMarker += Ann_Arbor.length;
map.addOverlays(Canton);
centerByArray(Canton, false, false);
cntMarker += Canton.length;
map.addOverlays(Dearborn);
centerByArray(Dearborn, false, false);
cntMarker += Dearborn.length;
map.addOverlays(Detroit);
centerByArray(Detroit, false, false);
cntMarker += Detroit.length;
map.addOverlays(East_Lansing);
centerByArray(East_Lansing, false, false);
cntMarker += East_Lansing.length;
map.addOverlays(Flint);
centerByArray(Flint, false, false);
cntMarker += Flint.length;
map.addOverlays(Franklin);
centerByArray(Franklin, false, false);
cntMarker += Franklin.length;
map.addOverlays(Swartz_Creek);
centerByArray(Swartz_Creek, false, false);
cntMarker += Swartz_Creek.length;
centerByArray(Detroit,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///14140,13741,13734,13950,14140,13864,13741,14182,13734,14176,13981,13933,14042,13950,/all');
//window.open('/map.php?type=2&schools=14140,13741,13734,13950,14140,13864,13741,14182,13734,14176,13981,13933,14042,13950,&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;
}