//sortByIconScript.js
//This javascript file deals with the marker sort option which allows us to restrict markers only to certain icons.
//Max Sklar, June 11, 2006

//This variable is zero when we're not in sort by icon mode.
//When we are in sort-by-icon mode, this is set to the id number of the icon
var inSortByIconMode = 0;

//Special version of loadMarkers() in mainMap.
function iconSortLoadMarkers(icon) {	
	map.clearOverlays();

	//get bounds
	var bounds = map.getBounds();
	var sw = bounds.getSouthWest();
	var ne = bounds.getNorthEast();
	
	var apparentZoomLevel = map.getZoom();
	
	var URL = "getMarkersXml.php?";
	URL += "&maxLat=" + ne.lat() + "&minLat=" + sw.lat() + "&maxLng=" + ne.lng() + "&minLng=" + sw.lng();
	URL += "&iconsearch=" + icon;
	URL += "&iebug=" + Math.random();
	
	doWithFile(URL, true, function(xmlDoc) {
		var markers = xmlDoc.documentElement.getElementsByTagName("marker");
		
		if (markers.length > 150) {
			document.getElementById("sifter_overflow_message").style.display = "block";
		}
		else {
			document.getElementById("sifter_overflow_message").style.display = "none";
		
			//Go through each marker.
			for(var i = 0; i < markers.length; i++) {
				//This line of code is here in case the zoom level is changed as the markers are loading.
				if (map.getZoom() != apparentZoomLevel) break;
			
				var markerInfo = markers[i];
				
				var point = new GLatLng(markerInfo.getAttribute("y"), markerInfo.getAttribute("x"));
				var title = markerInfo.getAttribute("title");
				var id = markerInfo.getAttribute("id");
				var iconid = markerInfo.getAttribute("icon");
			
				createMarker(point, title, iconid, id);		
			}
		}
	});
}