G_MAP_TYPE = G_NORMAL_MAP;
G_SATELLITE_TYPE = G_SATELLITE_MAP;
G_HYBRID_TYPE = G_HYBRID_MAP;

// ==================================================
// Detect if the browser is IE or not.
// If it is not IE, we assume that the browser is NS.
var IE = document.all?true:false

// If NS -- that is, !IE -- then set up for mouse capture
if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
//document.getElementById('overlay').onmousemove = getMouseXY;

// Temporary variables to hold mouse x-y pos.s
var mouseX = 0
var mouseY = 0
// ==================================================


var changeMapNumbers=function (objID) { //number overlays large search area
	if (objID=="ajaxnext") {
	    lowMapNumber=lowMapNumber+10;
	    highMapNumber=highMapNumber+10;
	} else {
	   if (lowMapNumber==1) {}
	   else {
	      lowMapNumber=lowMapNumber-10;
	      highMapNumber=highMapNumber-10;
	  }
	}
	//alert("Table onChange");
        if (mapfile == "") showLabels();
};

// ----------------------------------------------------------------------------
// triggered when someone hovers over a highlighted area of the map
// ----------------------------------------------------------------------------
var getPolyData=function (PolyScore) { 
	//hidePopup("mapPopUP");
	hidePopup("namePopUP");
	var objPrefix = "";
	if (PolyScore==0 && document.getElementById("nhoodrank")) {
		xmlDocument=nhoodxmlDoc;
		objPrefix="nhood";
	} else {
		xmlDocument=xmlDoc;
	}
	var mapData = buildMapData(PolyScore);	
	if (typeof xmlDoc.getElementsByTagName("PG")[0] == "undefined") { }
	else {
	if (map.getBounds().contains(new GLatLng(mapData.n_lat, mapData.n_lon))) { // only show the popup over the map window
		//if (document.getElementById("nhoodNamePopUPText"))
		document.getElementById("nhoodNamePopUPText").innerHTML=mapData.nhoodname;
		//else alert("No nhoodNamePopUPText");
		document.getElementById("cityStPopUPText").innerHTML=mapData.cityst;
		showPopup ((mapData.x),(mapData.y-10), "map", "namePopUP");
		if (clickEvent=="selectPolyID") {
		    document.getElementById("namePopUP").onclick=function () {
			if (typeof selectPolyID1 == "undefined") {}
			else selectPolyID1(mapData.id);
		    }; 
		}
		else {
			document.getElementById("namePopUP").onclick=function () {
					document.getElementById(objPrefix+"mapPopUP_nhood").innerHTML=mapData.nhoodname;
					document.getElementById(objPrefix+"mapPopUP_citySt").innerHTML=mapData.cityst;
					if (document.getElementById(objPrefix+"mapPopUP_page")) {
						if (mapData.pg=="search map") {
							document.getElementById("mapPopUP_page").onclick=function () {
								clear_comparisonform();if(window.getScrolling!=undefined){document.forms['comparisonform'].elements['autoScroll'].value=getScrolling();}document.forms['comparisonform'].elements['comparisonform:_link_hidden_'].value='comparisonform:_idJsp288';document.forms['comparisonform'].elements['poly2'].value=mapData.id;if(document.forms['comparisonform'].onsubmit){var result=document.forms['comparisonform'].onsubmit();  if( (typeof result == 'undefined') || result ) {document.forms['comparisonform'].submit();}}else{document.forms['comparisonform'].submit();}return false;
							};
						}					   
						else document.getElementById("mapPopUP_page").href=mapData.url;
					}	   
					document.getElementById(objPrefix+"mapPopUP_buy").href=mapData.buyurl;

					if (document.getElementById(objPrefix+"mapPopUP_school")) {
						document.getElementById(objPrefix+"mapPopUP_overview").href=mapData.urlo;
						document.getElementById(objPrefix+"mapPopUP_school").href=mapData.urls;
						document.getElementById(objPrefix+"mapPopUP_crime").href=mapData.urlc;
						document.getElementById(objPrefix+"mapPopUP_appr").href=mapData.urlr;
					}					

					if (PolyScore==0 && document.getElementById("nhoodrank")) {
						document.getElementById(objPrefix+"ranking_data").innerHTML=mapData.val;
					} else {
						if (document.getElementById(objPrefix+"match_data")) {
							document.getElementById(objPrefix+"ranking_data").innerHTML=PolyScore;
							document.getElementById(objPrefix+"match_data").innerHTML=mapData.val;
						} else {
							document.getElementById(objPrefix+"ranking_data").innerHTML=mapData.val;
						}
					}

					if (mapData.zipurl=="") {
					  hideObj(objPrefix+"mapPopUP_zipdiv");
					}
					else {
						//this *was* temporarily being hidden for a test - #931
					  showObj(objPrefix+"mapPopUP_zipdiv");
					  document.getElementById(objPrefix+"mapPopUP_zip").href=mapData.zipurl;
					  document.getElementById(objPrefix+"mapPopUP_zip").target="_blank";
					}


					hidePopup("namePopUP");
					showPopup ((mapData.x),(mapData.y-51), "map", (objPrefix+"mapPopUP")); 
			};
		}
		document.getElementById("namePopUP").onmouseover=function () {
			//alert("onmouseover namePopUP");
			popupMouseOver=true;
		};
		document.getElementById("namePopUP").onmouseout=function () {
			//alert("onmouseout namePopUP");
			//if (popupMouseOver!=true) {
			//    hideObj("namePopUP");
			//}
			popupMouseOver=false;
		};
		
		showPopup ((mapData.x-10),(mapData.y-34), "map", "namePopUPMarker");
	}
	else {
		document.getElementById("nhoodNamePopUPText").innerHTML=mapData.nhoodname;
		//else alert("No nhoodNamePopUPText");
		document.getElementById("cityStPopUPText").innerHTML=mapData.cityst;
		showPopup (mouseX,mouseY, "map", "namePopUP");
		if (clickEvent=="selectPolyID") {
		    document.getElementById("namePopUP").onclick=function () {
			if (typeof selectPolyID1 == "undefined") {}
			else selectPolyID1(mapData.id);
		    }; 
		}
		else {
			document.getElementById("namePopUP").onclick=function () {
					document.getElementById(objPrefix+"mapPopUP_nhood").innerHTML=mapData.nhoodname;
					document.getElementById(objPrefix+"mapPopUP_citySt").innerHTML=mapData.cityst;
					if (document.getElementById(objPrefix+"mapPopUP_page")) {
						if (mapData.pg=="search map") {
							document.getElementById("mapPopUP_page").onclick=function () {
								clear_comparisonform();if(window.getScrolling!=undefined){document.forms['comparisonform'].elements['autoScroll'].value=getScrolling();}document.forms['comparisonform'].elements['comparisonform:_link_hidden_'].value='comparisonform:_idJsp288';document.forms['comparisonform'].elements['poly2'].value=mapData.id;if(document.forms['comparisonform'].onsubmit){var result=document.forms['comparisonform'].onsubmit();  if( (typeof result == 'undefined') || result ) {document.forms['comparisonform'].submit();}}else{document.forms['comparisonform'].submit();}return false;
							};
						}					   
						else document.getElementById("mapPopUP_page").href=mapData.url;
					}	   
					document.getElementById(objPrefix+"mapPopUP_buy").href=mapData.buyurl;

					if (document.getElementById(objPrefix+"mapPopUP_school")) {
						document.getElementById(objPrefix+"mapPopUP_overview").href=mapData.urlo;
						document.getElementById(objPrefix+"mapPopUP_school").href=mapData.urls;
						document.getElementById(objPrefix+"mapPopUP_crime").href=mapData.urlc;
						document.getElementById(objPrefix+"mapPopUP_appr").href=mapData.urlr;
					}					

					if (PolyScore==0 && document.getElementById("nhoodrank")) {
						document.getElementById(objPrefix+"ranking_data").innerHTML=mapData.val;
					} else {
						if (document.getElementById(objPrefix+"match_data")) {
							document.getElementById(objPrefix+"ranking_data").innerHTML=PolyScore;
							document.getElementById(objPrefix+"match_data").innerHTML=mapData.val;
						} else {
							document.getElementById(objPrefix+"ranking_data").innerHTML=mapData.val;
						}
					}
					if (mapData.zipurl=="") {
					  hideObj(objPrefix+"mapPopUP_zipdiv");
					}
					else {
						//this was temporarily being hidden for a test - #931
					  showObj(objPrefix+"mapPopUP_zipdiv");
					  document.getElementById(objPrefix+"mapPopUP_zip").href=mapData.zipurl;
					  document.getElementById(objPrefix+"mapPopUP_zip").target="_blank";
					}

					hidePopup("namePopUP");
					showPopup ((mapData.x),(mapData.y-51), "map", (objPrefix+"mapPopUP")); 
			};
		}
		document.getElementById("namePopUPMarker").onmouseover=function () {
			//alert("onmouseover namePopUPMarker");
			popupMouseOver=true;
		};
		document.getElementById("namePopUPMarker").onmouseout=function () {
			//alert("onmouseout namePopUPMarker");
			popupMouseOver=false;
		};

		showPopup (mouseX,mouseY, "map", "namePopUPMarker");
	}
	} // end if (xmlDoc.getElementsByTagName("PG")[0].childNodes[0].nodeValue) {
};

var selectPolyID=function (PolyScore) {
	xmlDocument=xmlDoc;
	var mapData = buildMapData(PolyScore);	
	if (typeof selectPolyID1 == "undefined") {}
	else selectPolyID1(mapData.id);
}; 

function findPos(obj) {
	var curleft = curtop = curwidth = 0;
	if (obj.offsetParent) {
	curwidth = obj.offsetWidth;
	do {
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
	} while (obj = obj.offsetParent);
	}
	return [curleft,curtop,curwidth];
}

// ----------------------------------------------------------------------------
// places large popup next to nav when left hand nav is clicked
// ----------------------------------------------------------------------------
var popUpPolyDataList=function (PolyScore) {
	ofs=findPos(document.getElementById(("list"+PolyScore)));
	//alert((ofs[0]+ofs[2])+","+ofs[1]);
	xmlDocument=xmlDoc;
	
	var mapData = buildMapData(PolyScore);

	document.getElementById("mapPopUP_nhood").innerHTML=mapData.nhoodname;
	document.getElementById("mapPopUP_citySt").innerHTML=mapData.cityst;
	if (document.getElementById("mapPopUP_page")) {
		if (mapData.pg=="search map") {
			document.getElementById("mapPopUP_page").onclick=function () {
				clear_comparisonform();if(window.getScrolling!=undefined){document.forms['comparisonform'].elements['autoScroll'].value=getScrolling();}document.forms['comparisonform'].elements['comparisonform:_link_hidden_'].value='comparisonform:_idJsp288';document.forms['comparisonform'].elements['poly2'].value=mapData.id;if(document.forms['comparisonform'].onsubmit){var result=document.forms['comparisonform'].onsubmit();  if( (typeof result == 'undefined') || result ) {document.forms['comparisonform'].submit();}}else{document.forms['comparisonform'].submit();}return false;
			};
		}					   
		else document.getElementById("mapPopUP_page").href=mapData.url;
	}	   
	document.getElementById("mapPopUP_buy").href=mapData.buyurl;

	if (document.getElementById("mapPopUP_school")) {
		document.getElementById("mapPopUP_overview").href=mapData.urlo;
		document.getElementById("mapPopUP_school").href=mapData.urls;
		document.getElementById("mapPopUP_crime").href=mapData.urlc;
		document.getElementById("mapPopUP_appr").href=mapData.urlr;
	}
	
	if (document.getElementById("match_data")) {
		document.getElementById("ranking_data").innerHTML=PolyScore;
		document.getElementById("match_data").innerHTML=mapData.val;
	} else {
		document.getElementById("ranking_data").innerHTML=mapData.val;
	}				
	if (mapData.zipurl=="") {
	  hideObj("mapPopUP_zipdiv");
	}
	else {
	//this was temporarily being hidden for a test - #931
	  showObj("mapPopUP_zipdiv");
	  document.getElementById("mapPopUP_zip").href=mapData.zipurl;
	  document.getElementById("mapPopUP_zip").target="_blank";
	}

//	showPopup ((ofs[0]+ofs[2]),(ofs[1]-51), "pagebody", "mapPopUP"); 
// hard-coded the x coordinate to work around an issue with this being placed according to the width of the browser window:
	showPopup ((210),(ofs[1]-51), "pagebody", "mapPopUP"); 
}

// ----------------------------------------------------------------------------
// triggered when you click on the left nav or hover over an area of the map
// ----------------------------------------------------------------------------
var staticMapData;
var buildMapData=function (PolyScore) {
	//alert(PolyScore);
	try {
		var ct = xmlDocument.getElementsByTagName("CT"+PolyScore);
		if (typeof xmlDocument.getElementsByTagName("PG")[0] == "undefined") { }
		else {

			var pg = xmlDocument.getElementsByTagName("PG")[0].childNodes[0].nodeValue;
			//alert("pg="+pg);
			var n_lon = ct[0].attributes[9].value;
			var n_lat = ct[0].attributes[10].value;
			
			var imgBoundPnt = (map.getCurrentMapType().getProjection().fromLatLngToPixel(map.getBounds().getNorthEast(),map.getZoom()));
			var imgMarkerPnt = (map.getCurrentMapType().getProjection().fromLatLngToPixel(new GLatLng(n_lat, n_lon),map.getZoom()));

			var mapData = new Object;
			mapData.n_lon=n_lon;
			mapData.n_lat=n_lat;
			mapData.pg=pg;
			mapData.id=ct[0].attributes[1].value;
			mapData.name=ct[0].attributes[2].value+", "+ct[0].attributes[6].value+" "+ct[0].attributes[4].value;
			mapData.cityst=ct[0].attributes[2].value+", "+ct[0].attributes[6].value
			if (ct[0].attributes[4].value=="" || ct[0].attributes[4].value==" ")
				mapData.nhoodname="";
			else
				mapData.nhoodname="("+ct[0].attributes[4].value+")";
			mapData.x=(Math.abs(imgBoundPnt.x-500-imgMarkerPnt.x));
			mapData.y=(500-(imgBoundPnt.y-imgMarkerPnt.y+500));
			mapData.val=ct[0].attributes[8].value;
			mapData.url=ct[0].attributes[7].value;

			if (ct[0].attributes[11] == undefined) { //make sure this exists
				mapData.nhoodcount = 1;
			} else {
				mapData.nhoodcount=ct[0].attributes[11].value; //get the number of availble neighborhoods, called znc because we needed this at the end of the list and the xml generator sorts by alpha
			}
			
			//default values
			mapData.urlo=mapData.url+"#goto-tab-overview";
			mapData.urls=mapData.url+"#goto-tab-schools";
			mapData.urlc=mapData.url+"#goto-tab-crime";
			mapData.urlr=mapData.url+"#goto-tab-appr";
			
			if (xmlDocument.getElementsByTagName("PT")[0]) { 	
				//We do not need to extract PT but here it is any way.	
				var pt = xmlDocument.getElementsByTagName("PT")[0].childNodes[0].nodeValue;
				
				if (mapData.nhoodcount > 1) {
					//more than one neighborhood? send them to the city level
					mapData.urlo=mapData.url;
					mapData.urls=mapData.url+"schools/";
					mapData.urlc=mapData.url+"crime/";
					mapData.urlr=mapData.url+"rates/";
				}
				//mapData.url=mapData.url + pt + "/";
				//mapData.urlthispage= + pt + "/";
			}

			if (pg=="state map") 
			{
				mapData.buyurl="/find-realtor/?pg="+ encodeURIComponent(pg) +"&c="
					+ encodeURIComponent(ct[0].attributes[2].value) + "&s=" + encodeURIComponent(ct[0].attributes[6].value);
			}
			else {
				mapData.buyurl="/find-realtor/?pg=" + encodeURIComponent(pg) + "&polyid="+
					encodeURIComponent(ct[0].attributes[1].value) + "&nbr=" + encodeURIComponent(mapData.name) + "&c=" + encodeURIComponent(ct[0].attributes[2].value) +
					"&s=" + encodeURIComponent(ct[0].attributes[6].value);
			
			}
			if (ct[0].attributes[0].value=="") {
				mapData.zipurl="";
			} else {
				mapData.zipurl="/servlet/ListingsServlet?pg=summary"+
					"&b_city="+ct[0].attributes[2].value+"&b_state="+ct[0].attributes[6].value+
					"&polyid="+ct[0].attributes[1].value+"&nbr="+mapData.name+
					"&url="+escape(ct[0].attributes[0].value);
			}

			staticMapData = mapData;
			//mapData.zipurl=ct[0].attributes[0].value;
		}
	} catch(err) {
		mapData = staticMapData;
	}
	
	return mapData;
};

// ----------------------------------------------------------------------------
// places larger popup over map when area is clicked
// ----------------------------------------------------------------------------
var popUpPolyData=function (PolyScore) {
	hidePopup("namePopUP");
	var objPrefix = "";
	if (PolyScore==0 && document.getElementById("nhoodrank")) {
		xmlDocument=nhoodxmlDoc;
		objPrefix="nhood";
	} else {
		xmlDocument=xmlDoc;
	}
	var mapData = buildMapData(PolyScore);
	if (map.getBounds().contains(new GLatLng(mapData.n_lat, mapData.n_lon))) { // only show the popup over the map window
		document.getElementById(objPrefix+"mapPopUP_nhood").innerHTML=mapData.nhoodname;
		document.getElementById(objPrefix+"mapPopUP_citySt").innerHTML=mapData.cityst;		
		if (document.getElementById(objPrefix+"mapPopUP_page")) {
			if (mapData.pg=="search map") {
				document.getElementById(objPrefix+"mapPopUP_page").onclick=function () {
					clear_comparisonform();if(window.getScrolling!=undefined){document.forms['comparisonform'].elements['autoScroll'].value=getScrolling();}document.forms['comparisonform'].elements['comparisonform:_link_hidden_'].value='comparisonform:_idJsp288';document.forms['comparisonform'].elements['poly2'].value=mapData.id;if(document.forms['comparisonform'].onsubmit){var result=document.forms['comparisonform'].onsubmit();  if( (typeof result == 'undefined') || result ) {document.forms['comparisonform'].submit();}}else{document.forms['comparisonform'].submit();}return false;
				};
			}					   
			else document.getElementById(objPrefix+"mapPopUP_page").href=mapData.url;
		}	   
		document.getElementById(objPrefix+"mapPopUP_buy").href=mapData.buyurl;

		if (document.getElementById(objPrefix+"mapPopUP_school")) {
			document.getElementById(objPrefix+"mapPopUP_overview").href=mapData.urlo;
			document.getElementById(objPrefix+"mapPopUP_school").href=mapData.urls;
			document.getElementById(objPrefix+"mapPopUP_crime").href=mapData.urlc;
			document.getElementById(objPrefix+"mapPopUP_appr").href=mapData.urlr;
		}
		
		if (PolyScore==0 && document.getElementById("nhoodrank")) {
			document.getElementById(objPrefix+"ranking_data").innerHTML=mapData.val;
		} else {
			if (document.getElementById(objPrefix+"match_data")) {
				document.getElementById(objPrefix+"ranking_data").innerHTML=PolyScore;
				document.getElementById(objPrefix+"match_data").innerHTML=mapData.val;
			} else {
				document.getElementById(objPrefix+"ranking_data").innerHTML=mapData.val;
			}
		}

		if (mapData.zipurl=="") {
		  hideObj(objPrefix+"mapPopUP_zipdiv");
		}
		else {
		//this was temporarily being hidden for a test - #931
		  showObj(objPrefix+"mapPopUP_zipdiv");
		  document.getElementById(objPrefix+"mapPopUP_zip").href=mapData.zipurl;
		  document.getElementById(objPrefix+"mapPopUP_zip").target="_blank";
		}


		showPopup ((mapData.x),(mapData.y-51), "map", (objPrefix+"mapPopUP")); 
	}
	else {
		document.getElementById(objPrefix+"mapPopUP_nhood").innerHTML=mapData.nhoodname;
		document.getElementById(objPrefix+"mapPopUP_citySt").innerHTML=mapData.cityst;
		if (document.getElementById(objPrefix+"mapPopUP_page"))
		   document.getElementById(objPrefix+"mapPopUP_page").href=mapData.url;
		document.getElementById(objPrefix+"mapPopUP_buy").href=mapData.buyurl;

		if (document.getElementById(objPrefix+"mapPopUP_school")) {
			document.getElementById(objPrefix+"mapPopUP_overview").href=mapData.urlo;
			document.getElementById(objPrefix+"mapPopUP_school").href=mapData.urls;
			document.getElementById(objPrefix+"mapPopUP_crime").href=mapData.urlc;
			document.getElementById(objPrefix+"mapPopUP_appr").href=mapData.urlr;
		}
		
		if (document.getElementById(objPrefix+"match_data")) {
			document.getElementById(objPrefix+"ranking_data").innerHTML=PolyScore;
			document.getElementById(objPrefix+"match_data").innerHTML=mapData.val;
		} else {
			document.getElementById(objPrefix+"ranking_data").innerHTML=mapData.val;
		}
		
		if (mapData.zipurl=="") {
		  hideObj(objPrefix+"mapPopUP_zipdiv");
		}
		else {
		//this was temporarily being hidden for a test - #931
		  showObj(objPrefix+"mapPopUP_zipdiv");
		  document.getElementById(objPrefix+"mapPopUP_zip").href=mapData.zipurl;
		  document.getElementById(objPrefix+"mapPopUP_zip").target="_blank";
		}

		showPopup (mouseX,mouseY, "map", (objPrefix+"mapPopUP")); 
// ***** wasn't working?? **** showPopup (mouseX,mouseY, "map", "mapPopUP");
	}
};


// #############################################
// #############################################
// #############################################



// Main function to retrieve mouse x-y pos.s
function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft
    mouseY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX
    mouseY = e.pageY
  }
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0}
  if (mouseY < 0){mouseY = 0}

  return true
}

// #############################################
// #############################################
// #############################################

//for flash to interact with:

var zoomMapIn=function () {
	//hideObj("overlay");
	for (var i=1;i<=10;i++) {
		hideObj("labelText"+i);
	}
	map.zoomIn();
	return false;
};
var zoomMapOut=function () {
	//hideObj("overlay");
	for (var i=1;i<=10;i++) {
		hideObj("labelText"+i);
	}
	if(map.getZoom() > 2)
		map.zoomOut();
	return false;
};

var doZoom=function (zoomLevel) {
	//hideObj("overlay");
	for (var i=1;i<=10;i++) {
		hideObj("labelText"+i);
	}
	if(zoomLevel < 2) zoomLevel = 2;
	map.setZoom(zoomLevel);
	return false;
};

var doPan=function (ew,ns) {
	for (var i=1;i<=10;i++) {
		hideObj("labelText"+i);
	}
	map.panDirection(ew,  ns);
};
var resetMap=function () {
	//hideObj("overlay");
	for (var i=1;i<=10;i++) {
		hideObj("labelText"+i);
	}
	var zlevel = map.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(minY,minX),
				new GLatLng(maxY,maxX)))
	map.setCenter(new GLatLng(geopointY,geopointX), zlevel);
};

function setOpacity(op) {
	VGM.VGM_setOpacity(op);
}

var showOverlay=function () {
	//document.getElementById('overlay').style.display='inline';
	//VGM.VGM_setPolyLayer("true");
	if (mapfile == "") showLabels();
};

var showLabels=function () { //builds the circles  
	var textObjId=1;
	for (var i=highMapNumber;i>=lowMapNumber;i--) {
		if (document.getElementById("labelText"+textObjId)) {
		xmlDocument=xmlDoc;
		var mapData = buildMapData(i);	
		if (map.getBounds().contains(new GLatLng(mapData.n_lat, mapData.n_lon))) { // only show the label over the map window
			var objID = ("labelText"+textObjId);
			document.getElementById(objID).innerHTML=i;
			// set class based on number of chars in number
			switch ((""+i).length) {
				case 1: 
					document.getElementById(objID).className="mapNum one";
					break;
				case 2: 
					document.getElementById(objID).className="mapNum two";
					break;
				case 3: 
					document.getElementById(objID).className="mapNum three";
					break;
				case 4: 
					document.getElementById(objID).className="mapNum four";
					break;
				default:
					document.getElementById(objID).className="mapNum four";
					break;
			} 
			document.getElementById("labelText"+textObjId).onmouseover=
			function (e) {
				//alert("onmouseover "+this.innerHTML);
				if (popupMouseOver!=true) {
					getPolyData(this.innerHTML);
					popupMouseOver=true;
				}
			};
			document.getElementById("labelText"+textObjId).onmouseout=function () {
				//alert("onmouseout");
				if (popupMouseOver!=true) {
				    hideObj("namePopUP");
				}
				popupMouseOver=false;
			};
			document.getElementById("labelText"+textObjId).onclick=function () {
					xmlDocument=xmlDoc;
					var mapData = buildMapData(this.innerHTML);	
					document.getElementById("mapPopUP_nhood").innerHTML=mapData.nhoodname;
					document.getElementById("mapPopUP_citySt").innerHTML=mapData.cityst;
					if (document.getElementById("mapPopUP_page"))
					   document.getElementById("mapPopUP_page").href=mapData.url;
					document.getElementById("mapPopUP_buy").href=mapData.buyurl;

					if (document.getElementById("mapPopUP_school")) {
						document.getElementById("mapPopUP_overview").href=mapData.urlo;
						document.getElementById("mapPopUP_school").href=mapData.urls;
						document.getElementById("mapPopUP_crime").href=mapData.urlc;
						document.getElementById("mapPopUP_appr").href=mapData.urlr;
					}
					
					if (document.getElementById("match_data")) {
						document.getElementById("ranking_data").innerHTML=PolyScore;
						document.getElementById("match_data").innerHTML=mapData.val;
					} else {
						document.getElementById("ranking_data").innerHTML=mapData.val;
					}				
					if (mapData.zipurl=="") {
					  hideObj("mapPopUP_zipdiv");
					}
					else {
						//this was temporarily being hidden for a test - #931
					  showObj("mapPopUP_zipdiv");
					  document.getElementById("mapPopUP_zip").href=mapData.zipurl;
					  document.getElementById("mapPopUP_zip").target="_blank";
					}

					hidePopup("namePopUP");
					showPopup ((mapData.x),(mapData.y-51), "map", "mapPopUP"); 
			};
		
			//alert("labelText"+textObjId+"  ::  "+i);
			showPopup ((mapData.x),(mapData.y), "map", "labelText"+textObjId);
		}
		} // if object exists

		textObjId++;
	}
	hidePopup("namePopUP");
	hidePopup("mapPopUP");	
};


function showPopup (x, y, mapId, popupId) { //display div or something
	var obj = document.getElementById(popupId);
	var xOffset = document.body.offsetLeft;
	var yOffset = document.body.offsetTop;

	if (mapId!="pagebody") {
	    xOffset = document.getElementById(mapId).offsetLeft;
	    yOffset = document.getElementById(mapId).offsetTop;
	}

	obj.style.display="block";
	obj.style.top = y + yOffset + "px";
	obj.style.left = x + xOffset + "px";
	//alert("obj.style.left="+obj.style.left+"  obj.style.top="+obj.style.top);
}

var hidePopup = function (obj) { //moves off screen
	document.getElementById(obj).style.left = "-9999px";
}

var hideObj = function (obj) {
	if (document.getElementById(obj)) {
		document.getElementById(obj).style.display = "none";	
	}
}

var showObj = function (obj) {
	if (document.getElementById(obj)) {
		document.getElementById(obj).style.display = "inline";	
	}
}

function pausecomp(millis)
{
	//this whole function is lame and makes me sad that it's needed
	var date = new Date();
	var curDate = null;
	do { curDate = new Date(); }
	while(curDate-date < millis);
}


function zoom(x) { //flash intacts to zoom
        if (x == "IN")
                zoomMapIn();
        else if (x == "OUT")
                zoomMapOut();
        else if (x == 20)
                doZoom(20);
        else if (x == 19)
                doZoom(19);
        else if (x == 19)
                doZoom(18);
        else if (x == 18)
                doZoom(18);
        else if (x == 17)
                doZoom(17);
        else if (x == 17)
                doZoom(17);
        else if (x == 16)
                doZoom(16);
        else if (x == 15)
                doZoom(15);
        else if (x == 14)
                doZoom(14);
        else if (x == 13)
                doZoom(13);
        else if (x == 12)
                doZoom(12);
        else if (x == 11)
                doZoom(11);
        else if (x == 10)
                doZoom(10);
        else if (x == 9)
                doZoom(9);
        else if (x == 8)
                doZoom(8);
        else if (x == 7)
                doZoom(7);
        else if (x == 6)
                doZoom(6);
        else if (x == 5)
                doZoom(5);
		else if(x == 4)
				doZoom(4);
		else if(x == 3)
				doZoom(3);
		else if(x == 2)
				doZoom(2);
}


//http request function
function getXmlHttp() {
	var localXmlHttp;
	try {
		localXmlHttp = new XMLHttpRequest();
	} catch (error) {
		try { //check for IE 6 and lower:
			localXmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (error) {
			localXmlHttp = null;
		}
	}
	return localXmlHttp;
}



//function pausecomp(millis)
//{
//        var date = new Date();
//        var curDate = null;

//        do { curDate = new Date(); }
//        while(curDate-date < millis);
//}



// old ==================================================
/*
function loadXML(mapxmlfile) {
	var newxmlDoc;
	//load xml file
	// code for IE
	if (window.ActiveXObject)
	  {
	  newxmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	  {
	  newxmlDoc=document.implementation.createDocument("","",null);
	  }
	else
	  {
	  alert('Your browser cannot handle this script');
	  }
	newxmlDoc.async=false;
	
	newxmlDoc.load(mapxmlfile);
	
	return newxmlDoc;
}



//retreives xml file containing name, coordinates, etc

if (typeof xmlfile == "undefined") {
	xmlDoc = loadXML("mdata.xml"); //map info on results page and left have nav
}
else {
	xmlDoc = loadXML(xmlfile);
}


var nhoodxmlDoc;
if (typeof mapxmlfile  == "undefined") {
	nhoodxmlDoc = loadXML("mdata.xml"); //map info on comparisoin page
}
else {
	nhoodxmlDoc = loadXML(mapxmlfile);
}
*/


// ======================================================================================

var xmlDocument;
var xmlDoc;
var nhoodxmlDoc;
var zlevel;
//var gmapLoaded = false;
var mapXMLLoaded = false;
var pageLoaded = false;
//var activatedCount = 0;

//create google object
var map = new GMap(document.getElementById("map"));

// vgmap - create VGMap obj
var VGM = new VGMap(map, "map", "overlay", "/mapserver/vgmap/", "debug");
VGM.prep(); // ???


//GEvent.addListener(map, "load", function() {
	//is this needed with the onload event?
//	gmapLoaded = true;
//	activateInteractiveElements();
//	alert("gmap done loading");
//});

//activated by map.loaded and xml.loaded ==============================================================================

function activateInteractiveElements() {
//	activatedCount++;
//			alert("activate! " + activatedCount);
	if (mapXMLLoaded && pageLoaded) { 

	//this was to make sure we aren't firing these off before both XML files are loaded,
	//but unfortunitly with the current design model, we can sometimes have only one file, or sometimes two, so now this is set to 1 (well, true or false)

		//activate navigation (only activates if the functions below are included on the page):
		if(typeof initTop10Nav=='function') {
			initTop10Nav();
		}
		if(typeof top10Nav2Init=='function') {
			top10Nav2Init();
		}

		if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == 6) {
			//this is really, really, REALLY lame, but:
			//for an issue in IE 6 where the overlay will load and there won't be any map behind it
			pausecomp(1000);
		}

		//activate map when xml is done loading, 
		//side note: I think this is the root of many of our problems with IE 6:
		VGM.go(1, "/mapserver/map_loader.swf", "file="+mapfile);
		
		if (mapfile == "") showLabels();

		//if anchor is available, we select a tab automatically once everything is done loading
		
		//IE 7 has an issue with loading the flash overlay if we select a tab before it's loaded, this is to work around it
		//appears that IE 7 needs to wait until the overlay is completely loaded, so there's a
		//call the autoSelectTab in VGmaps.  We had to leave this code here for other browsers, 
		//becuase they will keep calling the autoSelectTab function over and over again if it's
		//placed in VGMaps (however IE 7 won't... *shrug*)
		if (BrowserDetect.browser == "Explorer" && BrowserDetect.version == 7) {
			//see VGMap.js for IE 7 code... ugh
		} else {
			autoSelectTab(); 
		}

	}

}
// load xml files and set up onreadystate event listeners ===============================================================================

//this IS NOT waiting for page to finish loading, can be run parallel to page loading

var xmlHttp;
xmlHttp = getXmlHttp();
if (xmlHttp) { //check if xmlHttp obj available
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) { //check that BOTH xml files are loaded
			if (xmlHttp.status == 200 || xmlHttp.status == 304) { //correct response
//						alert(xmlHttp.responseText);
				xmlDoc = xmlHttp.responseXML.documentElement;
				mapXMLLoaded = true;
				activateInteractiveElements();
//						alert("xml 1 active");
			} else {
				//something went wrong with page load
				//alert("We're sorry, there was an error loading a data file for this site.  Please refresh your browser and try again.");
				//this message is turned off because we don't know if there is going to be an xml file available or not in the current site design model
			}
		}
	}
	//a different map file may be passed in from the parent page (results.jsf etc):
	if (typeof xmlfile == "undefined") {
		xmlHttp.open("GET", "mdata.xml", true);
	}
	else {
		xmlHttp.open("GET", xmlfile, true); //map info on results page and left have nav
	}
	xmlHttp.send(null);
} else {
	//no xmlHttp available
//			alert("We're sorry, your browser is out of date and can not properly load certain functions of this web site.");
}

//this is a copy and paste copy from above with tweaks, should be reworked
var xmlHttp2;
xmlHttp2 = getXmlHttp();
if (xmlHttp2) { //check if xmlHttp obj available
	xmlHttp2.onreadystatechange = function() {
		if (xmlHttp2.readyState == 4) { //loaded
			if (xmlHttp2.status == 200 || xmlHttp2.status == 304) { //correct response
				//alert(xmlHttp2.responseText);
				nhoodxmlDoc = xmlHttp2.responseXML.documentElement;
				mapXMLLoaded = true;
				activateInteractiveElements();
//						alert("xml 2 active");
			} else {
				//something went wrong with page load
				//alert("We're sorry, there was an error loading a data file for this site.  Please refresh your browser and try again.");
				//this message is turned off because we don't know if there is going to be an xml file available or not in the current site design model
			}
		}
	}
	//a different map file may be passed in from the parent page (results.jsf etc):
	if (typeof mapxmlfile  == "undefined") {
	//	xmlHttp2.open("GET", "mdata.xml", true);//map info on comparison page

	}
	else {
		xmlHttp2.open("GET", mapxmlfile, true);
		xmlHttp2.send(null);
	}		
} else {
	//no xmlHttp available
	alert("We're sorry, your browser is out of date and can not properly load certain functions of this web site.");
}

// bringing the legacy Locinc Gmap constants uptodate with
// current Google Maps api.  This is safe to remove once all references to the old 
// constants are removed from the Generator, etc.
G_SATELLITE_TYPE = G_SATELLITE_MAP;
G_NORMAL_MAP = G_NORMAL_MAP;
G_HYBRID_MAP = G_HYBRID_MAP;
	
// initMaps, runs on page load ================================================================================================

function initMaps() { 
	//this is run on load
	
	//google maps setup
	zlevel = map.getBoundsZoomLevel(new GLatLngBounds(new GLatLng(minY,minX),
					new GLatLng(maxY,maxX)))
	if(zlevel < 2) zlevel = 2;
	map.setCenter(new GLatLng(geopointY,geopointX), zlevel);
    map.setMapType(eval(maptype));
	map.disableDragging();
	//google maps end
	
	//set up events on popups:
	if (document.getElementById("closePopUP")) {
		document.getElementById("closePopUP").onclick = function() { hidePopup("mapPopUP"); }
		document.getElementById("closePopUP").onmouseover = function() { document.getElementById("closePopUP").style.cursor="pointer"; }
		document.getElementById("closePopUP").onmouseout = function() { document.getElementById("closePopUP").style.cursor="default"; }
	}
	if (document.getElementById("nhoodclosePopUP")) {
		document.getElementById("nhoodclosePopUP").onclick = function() { hidePopup("nhoodmapPopUP"); }
		document.getElementById("nhoodclosePopUP").onmouseover = function() { document.getElementById("nhoodclosePopUP").style.cursor="pointer"; }
		document.getElementById("nhoodclosePopUP").onmouseout = function() { document.getElementById("nhoodclosePopUP").style.cursor="default"; }
	}

	pageLoaded = true;
	activateInteractiveElements();

}

// closeMaps, run on page unload ================================================================================================

function closeMaps() {
	//cleanup to prevent memory leaks 
	if (map) { GUnload(); } 
}
addEvent(window, "unload", closeMaps, false);



//moved this to bluemodule.js to have one central 'onload'
//addEvent(window, "load", initMaps, false);

