//<![CDATA[
		var schoolXML = "";
		
		var markerArry = new Array();
		var step = 20;
		var startIndex = 0; var endIndex = 1;
		var totalSchools = 1;
		
		// Creates a marker at the given point with the given number label
		function createMarker(point, number, index) {
				// Create our "tiny" marker icon
			var icon = new GIcon();
			icon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
			icon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
			icon.iconSize = new GSize(12, 20);
			icon.shadowSize = new GSize(22, 20);
			icon.iconAnchor = new GPoint(6, 20);
			icon.infoWindowAnchor = new GPoint(5, 1);
			
			var marker = new GMarker(point, icon);
			markerArry[index] = marker;
			
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml("<b>" + number + "</b>");
			});
			
			return marker;
		}
	
		function writeScrollIndex()
		{
			var beginIndex = startIndex;
			if(beginIndex == 0)
				beginIndex = 1;
			
			var nextPage = "";
			var nextPageStartIndex = startIndex + step;
			var nextPageEndIndex = nextPageStartIndex + step;		
			if(endIndex < totalSchools)
				nextPage = "<span style=\"cursor: pointer\" title=\"Next Page\" style=\"color: #01315a; text-decoration: none;\" href='#' onclick=\"scrollPage(" + nextPageStartIndex + "," + nextPageEndIndex + ")\">>></span>";
		
			var prevPage = "";
			var prevPageStartIndex = beginIndex - step;
			var prevPageEndIndex = prevPageStartIndex + step;
			if(startIndex != 0)
				prevPage = "<span style=\"cursor:pointer\" title=\"Previous Page\" style=\"color: #01315a; text-decoration: none;\" href='#' onclick=\"scrollPage(" + prevPageStartIndex + "," + prevPageEndIndex + ")\"><<</span>";
					
			var result = "<span style=\"font-weight: bold; float:left; font-size: 1.3em; color: #01315a;\">Search Results</span>	<span style=\"float:right; color: #01315a; font-size: 1.2em\"> ( Showing " +
				beginIndex + " - " + endIndex + " of " + totalSchools + " ) " +
				prevPage + " " +  nextPage + "</span>";
			
			$("searchResultsHeader").innerHTML = result;		
		}
		
		function scrollPage(begin, end)
		{
			startIndex = begin;
			if(startIndex == 1)
				startIndex = 0;
				
			endIndex = end;
			
			writeSchoolList(startIndex, endIndex);
			writeScrollIndex();
		}
		
		function writeSchoolList(begin, end)
		{
			var xml = GXml.parse(schoolXML);
			var root = xml.documentElement;
	
			var result = "<ul style=\"list-style-type: none; padding-left: 10px;\">";					
			totalSchools = root.childNodes.length;
			
			if(end > totalSchools) {
				end = totalSchools;
				endIndex = totalSchools;
			}
				
			for(var i=begin; i<end; i++) {
				var childNode = root.childNodes[i];
				
				var lat = childNode.getAttribute("lat");
				var lng = childNode.getAttribute("lng");
							
				var name = childNode.childNodes[0].childNodes[0].nodeValue;
				
				var numCourses = childNode.childNodes[2].childNodes.length;
				var crsList = "Courses Offered\n<ul style=\"list-style-type: none; margin-left: -20px; padding-top: 3px; \">";
				for( var j=0; j<numCourses; j++) 
					crsList += "<li>" + childNode.childNodes[2].childNodes[j].childNodes[0].nodeValue + "</li>";
				crsList += "</ul>";
				
				var bgColor = "#fff";
				if(i%2 == 0)
					bgColor = "#f9eede";
					
				result += "<li><div id=\"school" + i + "\" style=\"padding-bottom: 5px; padding-top: 5px; padding-left: 10px; color: #fa6d17; background-color:" + bgColor + "\">" + 
						"<a href=# title=\"Click to see school in map\" style=\"color: #fa6d17; text-decoration: none\" onclick=\"centerMap(" + lat + "," + lng +  ",'" + 
						name +  "'," + i + ")\">" + name + "</a>&nbsp;&nbsp;<span style=\"cursor: pointer; font-size: 11px;\" href='#' title=\"Click to view courses offered\" onclick='toggleDisplay(" + i + ")'>View courses offered</span><br>" +
						"<div id=\"schoolDetails" + i + "\" style=\" display:none; font-size: 0.9em; color: #01315a; font-weight: 800%; padding-top: 3px; padding-left: 5px;\">" + 
						crsList + "</div>" + "</div>" + "</li>";	
			}
			$("searchResults").innerHTML = result;
		}
		
		function toggleDisplay(index)
		{
			var display = $("schoolDetails"+index).style.display;
			if(display == "none")
				display = "block";
			else 
				display = "none";
			$("schoolDetails"+index).style.display = display;
			
		}
		
		function centerMap(lat, lng, name, index)
		{
			var point = new GLatLng(lat, lng);
			map.setCenter(point, 10);
			
			marker = markerArry[index];
			marker.openInfoWindowHtml("<b>" + name + "</b>");
		}
		
		var map;
	
		function getSchoolXML(state, course, name)
		{
			var url = "handler.php";
			var qry = "action=getXML&state="+ state + "&course=" + course + "&name=" + name;
	
			var request = new Ajax.Request(
								url,
								{
									method: 'post',
									postBody: qry,
									onFailure: function() { alert("Error"); },
									onSuccess: function(req) { schoolXML = req.responseText; load(); }
								});
		}
		
		function searchSchools()
		{
			var form = document.forms["searchSchool"];
			var srchType  = form.searchSchools.selectedIndex
			if(srchType == 0)
			{
				alert("Choose a category and then click 'Go'");
				return;
			}
			var course = form.courseoffered.options[form.courseoffered.selectedIndex].value;
			var state = form.state.options[form.state.selectedIndex].value;
			var name = form.schoolname.options[form.schoolname.selectedIndex].value;
			
			var value = form.searchSchools.options[form.searchSchools.selectedIndex].value;
			if(value == "schoolname") {
				state = "%";
				course = "%";
			}
			
			if(value == "course") {
				state = "%";
				name = "%";
			}
	
			if(value == "state") {
				name = "%";
				course = "%";
			}
			
			startIndex = 0;
			endIndex = 1;
			getSchoolXML(state, course, name);
		}
		
		function toggleSearch()
		{
			var form = document.forms["searchSchool"];
			var box = form.searchSchools.selectedIndex;
			
			var value = form.searchSchools.options[box].value;
			if(value == "%") {
				$("state").style.display = "none";
				$("courseoffered").style.display = "none";
				$("schoolname").style.display = "none";
			}
			
			if(value == "courseoffered") {
				$("state").style.display = "none";
				$("courseoffered").style.display = "inline";
				$("schoolname").style.display = "none";
			}
	
			if(value == "state") {
				$("state").style.display = "inline";
				$("courseoffered").style.display = "none";
				$("schoolname").style.display = "none";			
			}
	
			if(value == "schoolname") {
				$("state").style.display = "none";
				$("courseoffered").style.display = "none";
				$("schoolname").style.display = "inline";			
			}
	
			
		}
		
		function load() {
		  if (GBrowserIsCompatible()) {
			map = new GMap2($("map"));
			map.addControl(new GSmallMapControl());
			map.setCenter(new GLatLng(43.042453, -76.128972400), 10);
			
			var xml = GXml.parse(schoolXML);
			var root = xml.documentElement;
	
	
			var lastPoint = "";	
				
			for(var i=0; i<root.childNodes.length; i++) {
				var childNode = root.childNodes[i];
			
				var name = childNode.childNodes[0].childNodes[0].nodeValue;
				
				var point = new GLatLng(childNode.getAttribute("lat"), childNode.getAttribute("lng"));
				map.addOverlay(createMarker(point, name, i));
				
				lastPoint = point;
			}
			
			map.setCenter(lastPoint, 6);
		  }
		  if(endIndex <= 1)
			endIndex = step;
			
		  writeSchoolList(startIndex, endIndex);
		  writeScrollIndex();
		}
   //]]>
