function addMarkers(){
mySelect = document.getElementById('selection');
Montgomery = [];Athens = [];Birmingham = [];Troy = [];Madison = [];Florence = [];Huntsville = [];Mobile = [];Decatur = [];Dothan = [];Enterprise = [];mySelect.options[mySelect.options.length] = new Option("Athens schools",'all=Athens');
mySelect.options[mySelect.options.length] = new Option("Birmingham schools",'all=Birmingham');
mySelect.options[mySelect.options.length] = new Option("Decatur schools",'all=Decatur');
mySelect.options[mySelect.options.length] = new Option("Dothan schools",'all=Dothan');
mySelect.options[mySelect.options.length] = new Option("Enterprise schools",'all=Enterprise');
mySelect.options[mySelect.options.length] = new Option("Florence schools",'all=Florence');
mySelect.options[mySelect.options.length] = new Option("Huntsville schools",'all=Huntsville');
mySelect.options[mySelect.options.length] = new Option("Madison schools",'all=Madison');
mySelect.options[mySelect.options.length] = new Option("Mobile schools",'all=Mobile');
mySelect.options[mySelect.options.length] = new Option("Montgomery schools",'all=Montgomery');
mySelect.options[mySelect.options.length] = new Option("Troy schools",'all=Troy');
mySelect.options[mySelect.options.length] = new Option("---------------------------",'');
Montgomery[Montgomery.length] = createMarker(new GPoint(-86.21795400,32.38892100),"
",iconGr);
mySelect.options[mySelect.options.length] = new Option("Alabama Christian Academy",'Montgomery=' + Montgomery.length);
Athens[Athens.length] = createMarker(new GPoint(-86.95673200,34.79806900),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Athens Bible School",'Athens=' + Athens.length);
Birmingham[Birmingham.length] = createMarker(new GPoint(-86.73793500,33.39673700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Cahaba Valley Church Preschool",'Birmingham=' + Birmingham.length);
Montgomery[Montgomery.length] = createMarker(new GPoint(-86.22681000,32.33852000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Carriage Hills Kindergarten",'Montgomery=' + Montgomery.length);
Troy[Troy.length] = createMarker(new GPoint(-85.97406000,31.80134000),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Collegedale Christian School",'Troy=' + Troy.length);
Birmingham[Birmingham.length] = createMarker(new GPoint(-86.64569300,33.54885700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Jefferson Christian Academy",'Birmingham=' + Birmingham.length);
Madison[Madison.length] = createMarker(new GPoint(-86.70667100,34.70156700),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Madison Academy",'Madison=' + Madison.length);
Florence[Florence.length] = createMarker(new GPoint(-87.66082100,34.84398800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mars Hill Bible School",'Florence=' + Florence.length);
Huntsville[Huntsville.length] = createMarker(new GPoint(-86.55811800,34.68986200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mayfair Child Development Center",'Huntsville=' + Huntsville.length);
Mobile[Mobile.length] = createMarker(new GPoint(-88.17909400,30.64329200),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Mobile Christian School",'Mobile=' + Mobile.length);
Decatur[Decatur.length] = createMarker(new GPoint(-86.99926600,34.59960400),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Tennessee Valley Christian School",'Decatur=' + Decatur.length);
Dothan[Dothan.length] = createMarker(new GPoint(-85.43514000,31.24009600),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Westgate Christian School",'Dothan=' + Dothan.length);
Enterprise[Enterprise.length] = createMarker(new GPoint(-85.85554300,31.31332800),"",iconGr);
mySelect.options[mySelect.options.length] = new Option("Wiregrass Christian Academy",'Enterprise=' + Enterprise.length);
map.removeOverlays(Athens);
map.removeOverlays(Birmingham);
map.removeOverlays(Decatur);
map.removeOverlays(Dothan);
map.removeOverlays(Enterprise);
map.removeOverlays(Florence);
map.removeOverlays(Huntsville);
map.removeOverlays(Madison);
map.removeOverlays(Mobile);
map.removeOverlays(Montgomery);
map.removeOverlays(Troy);
setTimeout(function(){map.addOverlays(Athens)},1000);
setTimeout(function(){map.addOverlays(Birmingham)},1000);
setTimeout(function(){map.addOverlays(Decatur)},1000);
setTimeout(function(){map.addOverlays(Dothan)},1000);
setTimeout(function(){map.addOverlays(Enterprise)},1000);
setTimeout(function(){map.addOverlays(Florence)},1000);
setTimeout(function(){map.addOverlays(Huntsville)},1000);
setTimeout(function(){map.addOverlays(Madison)},1000);
setTimeout(function(){map.addOverlays(Mobile)},1000);
setTimeout(function(){map.addOverlays(Montgomery)},1000);
setTimeout(function(){map.addOverlays(Troy)},1000);
maxLng = -85.43514000;
maxLat = 34.84398800;
minLng = -88.17909400;
minLat = 30.64329200;
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(Athens);
map.removeOverlays(Birmingham);
map.removeOverlays(Decatur);
map.removeOverlays(Dothan);
map.removeOverlays(Enterprise);
map.removeOverlays(Florence);
map.removeOverlays(Huntsville);
map.removeOverlays(Madison);
map.removeOverlays(Mobile);
map.removeOverlays(Montgomery);
map.removeOverlays(Troy);
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(Montgomery);map.removeOverlays(Athens);
map.removeOverlays(Birmingham);
map.removeOverlays(Decatur);
map.removeOverlays(Dothan);
map.removeOverlays(Enterprise);
map.removeOverlays(Florence);
map.removeOverlays(Huntsville);
map.removeOverlays(Madison);
map.removeOverlays(Mobile);
map.removeOverlays(Montgomery);
map.removeOverlays(Troy);
map.addOverlays(Athens);
centerByArray(Athens, false, false);
cntMarker += Athens.length;
map.addOverlays(Birmingham);
centerByArray(Birmingham, false, false);
cntMarker += Birmingham.length;
map.addOverlays(Decatur);
centerByArray(Decatur, false, false);
cntMarker += Decatur.length;
map.addOverlays(Dothan);
centerByArray(Dothan, false, false);
cntMarker += Dothan.length;
map.addOverlays(Enterprise);
centerByArray(Enterprise, false, false);
cntMarker += Enterprise.length;
map.addOverlays(Florence);
centerByArray(Florence, false, false);
cntMarker += Florence.length;
map.addOverlays(Huntsville);
centerByArray(Huntsville, false, false);
cntMarker += Huntsville.length;
map.addOverlays(Madison);
centerByArray(Madison, false, false);
cntMarker += Madison.length;
map.addOverlays(Mobile);
centerByArray(Mobile, false, false);
cntMarker += Mobile.length;
map.addOverlays(Montgomery);
centerByArray(Montgomery, false, false);
cntMarker += Montgomery.length;
map.addOverlays(Troy);
centerByArray(Troy, false, false);
cntMarker += Troy.length;
centerByArray(Montgomery,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///12,34212,282,170,162,178,4,12,348,34212,282,331,334,170,171,162,178,4,35,32011,/all');
//window.open('/map.php?type=2&schools=12,34212,282,170,162,178,4,12,348,34212,282,331,334,170,171,162,178,4,35,32011,&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;
}