document.oncontextmenu = function() {return false;};
try {document.execCommand("BackgroundImageCache", false, true);}catch(err){};
var dragapproved=false;
var z,x,y;
var triggerMap;
var weAreDown = false;
if(!(default_map_type)) var default_map_type = "map";
if(!(default_drag_type)) var default_drag_type = "zoom";
if(!(mainKey)) var mainKey = "mjtd%7Clu6znua2n9%2C7l%3Do5-la70q";
if(!(miniKey)) var miniKey = "mjtd%7Clu6tn1u7n5%2C75%3Do5-lw2aq";
if(!(broker_rec)) var broker_rec = "";
if(!(zoomLevelLow)) var zoomLevelLow = 6;
if(!(zoomLevelHigh)) var zoomLevelHigh = 16;


Array.prototype.findIn = function(searchStr) {
	var returnArray = false;
	for (i=0; i<this.length; i++) {
		if (typeof(searchStr) == 'function') {
			if (searchStr.test(this[i])) {
				if (!returnArray) { returnArray = [] }
				returnArray.push(i);
			}
		} else {
			if (this[i]===searchStr) {
				if (!returnArray) { returnArray = [] }
				returnArray.push(i);
			}
		}
	}
	return returnArray;
}



/*	===========================================================================	*/
//	Start of custom Controls
/*	===========================================================================	*/
	/*	===============================================================	*/
	//	Begin Custom Click And Drag Control
	/*	===============================================================	*/
	function MQCADControl(dragtype)
	{
		this.drag_type = dragtype;
		browser = getBrowserInfo();
		this.map = null;
		this.position=new MQMapCornerPlacement(MQMapCorner.TOP_LEFT,new MQSize(-1,-1));
	
		this.elem=document.createElement("div");
		this.elem.id = "mqCADID";
		this.elem.style.position="absolute";
		this.elem.style.overflow="visible";
	
		temp=document.createElement("ul");
		temp.className="map-cad screen";
		this.elem.appendChild(temp);
	
		temp1=document.createElement("li");
		temp1.className="map-cad-cad";
		temp.appendChild(temp1);
		this.cadcad=document.createElement("img");
		this.cadcad.className="";
		this.cadcad.id="cadcadIMG";
		this.cadcad.border=0;
		this.cadcad.src=sharedImagePath + "viewControl/icon-btn-cad.gif";
		temp1.appendChild(this.cadcad);
	
		temp1=document.createElement("li");
		temp1.className="map-cad-zoom";
		temp.appendChild(temp1);
		this.ctoZoom=document.createElement("img");
		this.ctoZoom.className="";
		this.ctoZoom.border=0;
		this.ctoZoom.src=sharedImagePath + "viewControl/icon-btn-zoom.gif";
		this.ctoZoom.alt="Click and Drag to Zoom Map";
		this.ctoZoom.title="Click and Drag to Zoom Map";
		temp1.appendChild(this.ctoZoom);
	
		temp1=document.createElement("li");
		temp1.className="map-cad-move";
		temp.appendChild(temp1);
		this.ctoMove=document.createElement("img");
		this.ctoMove.className="";
		this.ctoMove.border=0;
		this.ctoMove.src=sharedImagePath + "viewControl/icon-btn-move.gif";
		this.ctoMove.alt="Click and Drag to Move Map";
		this.ctoMove.title="Click and Drag to Move Map";
		temp1.appendChild(this.ctoMove);
	
	}
	MQCADControl.prototype = new MQControl();
	MQCADControl.prototype.constructor = MQCADControl;
	
	MQCADControl.prototype.initialize = function(map)
	{
		this.map = map;
		this.type=CONTROL_TYPE;
	
		Event.observe(this.ctoZoom,'click',this.eventCallback("eventmonitor"));
		Event.observe(this.ctoZoom,'mouseover',this.eventCallback("eventmonitor"));
		Event.observe(this.ctoZoom,'mouseout',this.eventCallback("eventmonitor"));
		Event.observe(this.ctoMove,'click',this.eventCallback("eventmonitor"));
		Event.observe(this.ctoMove,'mouseover',this.eventCallback("eventmonitor"));
		Event.observe(this.ctoMove,'mouseout',this.eventCallback("eventmonitor"));

		if(this.drag_type == "zoom"){
			this.setZoom();
		}else if(this.drag_type == "move"){
			this.setMove();			
		}else if(this.drag_type == "pan"){
			this.setMove();			
		}
	}

	MQCADControl.prototype.eventmonitor = function(evt)
	{
		switch(evt.type)
		{
			case "click":
				if (Event.element(evt)==this.ctoMove){
					this.setMove();
				}
				if ((Event.element(evt)==this.ctoZoom) && (this.map.getDragEnabled())){
					this.setZoom();
				}
			break;
			case"mouseover":Event.element(evt).addClassName("o");
			break;
			case"mouseout":Event.element(evt).removeClassName("o");
			break;
		}
	}
	

	MQCADControl.prototype.getHeight = function()
	{
		return 20;
	}
	
	MQCADControl.prototype.getWidth = function()
	{
		return 150;
	}

	MQCADControl.prototype.setMove = function()
	{
		this.drag_type = "move";
		this.ctoZoom.removeClassName("a");
		this.ctoMove.addClassName("a");
		this.map.enableDragging(1);
		if($('blockDiv')){$('blockDiv').remove();}
		if($('coverDiv')){$('coverDiv').remove();}
	}
	MQCADControl.prototype.setZoom = function(){
		this.drag_type = "zoom";
		this.ctoMove.removeClassName("a");
		this.ctoZoom.addClassName("a");

		zoomOut = 0;
		zo = 0;
		startX = 0;
		startY = 0;
		endX = 0;
		endY = 0;
		
		w = this.map.getSize().width + 1;
		h = this.map.getSize().height + 1;
		
		coverOffX = parseInt($('mqtiledmap').style.left);
		coverOffY = parseInt($('mqtiledmap').style.top);
		
		this.map.enableDragging(0);
		tmpBlockDiv = document.createElement("div");
		tmpBlockDiv.id = "blockDiv";
		tmpBlockDiv.style.position = "absolute";
		tmpBlockDiv.style.border = "1px dotted black";
		tmpBlockDiv.style.top = "0px";
		tmpBlockDiv.style.left = "0px";
		tmpBlockDiv.style.width = "0px";
		tmpBlockDiv.style.height = "0px";
		tmpBlockDiv.style.display = "none";
		tmpBlockDiv.style.backgroundColor = "black";
		tmpBlockDiv.style.zIndex = "1001";
		tmpBlockDiv.style.opacity = 0.20;
		tmpBlockDiv.style.filter = "alpha(opacity=20)";
		tmpBlockDiv.style.innerHTML = "";
		tmpBlockDiv.style.fontFamily = "sans-serif";
		tmpBlockDiv.style.fontWeight = "bold";
		tmpBlockDiv.style.color = "white";
		$('mqtiledmap').appendChild(tmpBlockDiv);

		tmpCoverDiv = document.createElement("div");
		tmpCoverDiv.id = "coverDiv";
		tmpCoverDiv.style.zIndex = "0";
		tmpCoverDiv.style.cursor = "crosshair";
		tmpCoverDiv.style.position = "absolute";
		tmpCoverDiv.style.left = (0 - coverOffX) + "px";
		tmpCoverDiv.style.top = (0 - coverOffY) + "px";
		tmpCoverDiv.style.width = w + "px";
		tmpCoverDiv.style.height = h + "px";
		tmpCoverDiv.style.backgroundColor= "white";
		tmpCoverDiv.style.opacity = 0.00;
		tmpCoverDiv.style.filter = "alpha(opacity=0)";
		tmpCoverDiv.style.MozOpacity = "0.00";
		$('mqtiledmap').appendChild(tmpCoverDiv);

		Event.observe($('coverDiv'),"mousedown",zMouseDown);
		Event.observe($('coverDiv'),"mousemove",zMouseMove);
		Event.observe($('coverDiv'),"mouseup",zMouseUp);

	}
	
	function zMouseDown(evt){
		weAreDown = true;
		zoomOut = 0;
		$('blockDiv').innerHTML= "";
		if(evt.button == 2){
			zoomOut = 1;
			zo = 1;
		}else{
			zoomOut = 0;
			zo = 0;
		}
		$('coverDiv').style.zIndex = 1000; 
		$('blockDiv').style.zIndex = 999; 
		$('blockDiv').style.opacity = 0.40;
		$('blockDiv').style.MozOpacity = .40;
		$('blockDiv').style.filter = "alpha(opacity=40)";
	
		if(browser.name=="msie"){
			startY = evt.offsetY;
			startX = evt.offsetX;
			var layerStyle = $('blockDiv').style;
		} else {
			startY = evt.layerY;
			startX = evt.layerX;
			var layerStyle = $('blockDiv').style;
		}
	
		startX = startX - coverOffX;
		startY = startY - coverOffY;
		$('blockDiv').style.display = "";
		$('blockDiv').style.left = startX + "px";
		$('blockDiv').style.top = startY + "px";
		layerStyle.height = "1px";
		layerStyle.width = "1px";
	}
	function zMouseMove(evt){
		if (weAreDown){
			if(browser.name=="msie"){
				var y = evt.offsetY;
				var x = evt.offsetX;
				var layerStyle = $('blockDiv').style;
			} else {
				var y = evt.layerY;
				var x = evt.layerX;
				var layerStyle = $('blockDiv').style;
			}
		
			x = x - coverOffX;
			y = y - coverOffY;
			

			if(startX > x){
				if (x < 1){
					$('blockDiv').style.left = "1px";
					layerStyle.width = (startX-1) + "px";
				}else{
					$('blockDiv').style.left = x + "px";
					layerStyle.width = (startX-x) + "px";
				}
				var bw = startX-x;
			}else {
				$('blockDiv').style.left = startX + "px";
				layerStyle.width = (x-startX) + "px";
				var bw = x-startX;
			}
		
			if(startY > y){
				if (y < 0){
					$('blockDiv').style.top = "1px";
					layerStyle.height = (startY-1) + "px";
				}else{
					$('blockDiv').style.top = y + "px";
					layerStyle.height = (startY-y) + "px";
				}
				var bh = startY-y;
			}else {
				$('blockDiv').style.top = startY + "px";
				layerStyle.height = (y-startY) + "px";
				var bh = y-startY;
			}	
		
			if (zoomOut) {
				zo = Math.ceil(((Math.sqrt((bw * bw) + (bh * bh))) / (Math.sqrt((h * h) + (w * w)))*5));
				$('blockDiv').innerHTML='Zoom OUT * ' + zo;		
			}		
		}
	}
	
	function zMouseUp(evt){
		weAreDown = false;
		$('blockDiv').style.display = "none";
		if(browser.name=="msie"){
			var y = evt.offsetY;
			var x = evt.offsetX;
		} else {
			var y = evt.layerY;
			var x = evt.layerX;
		}
		startX += coverOffX;
		startY += coverOffY;
		endX = x;
		endY = y;
	
		if(zoomOut){
			myMap.setCenter(myMap.pixToLL(new MQPoint(Math.round(((startX - endX)/2)+ endX),Math.round(((startY - endY)/2)+ endY))),Math.max(zoomLevelLow,(myMap.getZoomLevel() - zo)));
		}else{
			if ((Math.abs(startX - endX) < 8) && (Math.abs(startY - endY) < 8)){
				myMap.setCenter(myMap.pixToLL(new MQPoint(Math.round(((startX - endX)/2)+ endX),Math.round(((startY - endY)/2)+ endY))),Math.min(zoomLevelHigh,(myMap.getZoomLevel() + 1)));
			}else{
				myMap.zoomToRect(new MQRectLL(myMap.pixToLL(new MQPoint(startX,startY)),myMap.pixToLL(new MQPoint(endX,endY))));
			}
		}
		resetCoverDiv(); 
		$('coverDiv').style.zIndex = 0; 
		$('blockDiv').style.top = "0px";
		$('blockDiv').style.left = "0px";
		$('blockDiv').style.width = "0px";
		$('blockDiv').style.height = "0px";
		$('blockDiv').style.zIndex = 1001;
		$('blockDiv').style.display = "none";

		if(myCADControl.drag_type == "zoom"){
			myCADControl.setMove();
			myCADControl.setZoom();
		}
	
	}
	
	function resetCoverDiv(){
		coverOffX = parseInt($('mqtiledmap').style.left);
		coverOffY = parseInt($('mqtiledmap').style.top);
		if($('coverDiv')){
			$('coverDiv').style.left = (0 - coverOffX) + "px"; 
			$('coverDiv').style.top = (0 - coverOffY) + "px"; 
		}
	}
	/*	===============================================================	*/
	//	End Custom Click And Drag Control
	/*	===============================================================	*/

	/*	===============================================================	*/
	//	Begin Custom View Control
	/*	===============================================================	*/
	function MTViewControl()
	{
		browser = getBrowserInfo();
		this.map = null;
		this.position=new MQMapCornerPlacement(MQMapCorner.TOP_RIGHT,new MQSize(-1,-1));
		this.elem = document.createElement("div");
		this.elem.style.position = "absolute";
		this.elem.style.overflow = "visible";
		
		temp=document.createElement("ul");
		temp.className="map-view screen";
		this.elem.appendChild(temp);
	
		temp1=document.createElement("li");
		temp1.className="map-view-street";
		temp.appendChild(temp1);
	
		this.streetview=document.createElement("img");
		this.streetview.className="";
		this.streetview.border=0;
		this.streetview.src= sharedImagePath + "viewControl/icon-btn-street-view.gif";
		this.streetview.alt="View Street Map";
		this.streetview.title="View Street Map";
		temp1.appendChild(this.streetview);
		temp1=document.createElement("li");
		temp1.className="map-view-hybrid";
		temp.appendChild(temp1);
		this.hybridview=document.createElement("img");
		this.hybridview.className="";
		this.hybridview.border=0;
		this.hybridview.src=sharedImagePath + "viewControl/icon-btn-hybrid-view.gif";
		this.hybridview.alt="View Hybrid Map";
		this.hybridview.title="View Hybrid Map";
		temp1.appendChild(this.hybridview);
		temp1=document.createElement("li");
		temp1.className="map-view-aerial";
		temp.appendChild(temp1);
		this.aerialview=document.createElement("img");
		this.aerialview.className="";
		this.aerialview.border=0;
		this.aerialview.src=sharedImagePath + "viewControl/icon-btn-aerial-view.gif";
		this.aerialview.alt="View Aerial Image";
		this.aerialview.title="View Aerial Image";
		temp1.appendChild(this.aerialview);
	}
	
	
	MTViewControl.prototype=new MQControl();
	MTViewControl.prototype.constructor=MTViewControl;
	MTViewControl.prototype.initialize=function(map){
		this.map=map;
		this.type=CONTROL_TYPE;
		Event.observe(this.streetview,'click',this.eventCallback("eventmonitor"));
		Event.observe(this.streetview,'mouseover',this.eventCallback("eventmonitor"));
		Event.observe(this.streetview,'mouseout',this.eventCallback("eventmonitor"));
		Event.observe(this.aerialview,'click',this.eventCallback("eventmonitor"));
		Event.observe(this.aerialview,'mouseover',this.eventCallback("eventmonitor"));
		Event.observe(this.aerialview,'mouseout',this.eventCallback("eventmonitor"));
		Event.observe(this.hybridview,'click',this.eventCallback("eventmonitor"));
		Event.observe(this.hybridview,'mouseover',this.eventCallback("eventmonitor"));
		Event.observe(this.hybridview,'mouseout',this.eventCallback("eventmonitor"));
		if(this.map.getMapType()=="map")this.streetview.addClassName("a");
		if(this.map.getMapType()=="sat")this.aerialview.addClassName("a");
		if(this.map.getMapType()=="hyb")this.hybridview.addClassName("a");
	}
	MTViewControl.prototype.eventmonitor=function(evt){
		switch(evt.type){
			case"click":
				if(Event.element(evt)==this.streetview)this.selectMode("street");
				if(Event.element(evt)==this.aerialview)this.selectMode("aerial");
				if(Event.element(evt)==this.hybridview)this.selectMode("hybrid");
			break;
			case"mouseover":Event.element(evt).addClassName("o");
			break;
			case"mouseout":Event.element(evt).removeClassName("o");
			break;
		}
	}
	MTViewControl.prototype.updateControl=function(mtype){
		switch(mtype){
			case"map":this.aerialview.removeClassName("a");
				this.hybridview.removeClassName("a");
				this.streetview.addClassName("a");
			break;
			case"sat":this.hybridview.removeClassName("a");
				this.streetview.removeClassName("a");
				this.aerialview.addClassName("a");
			break;
			case"hyb":this.aerialview.removeClassName("a");
				this.streetview.removeClassName("a");
				this.hybridview.addClassName("a");
			break;
		}
	}
	MTViewControl.prototype.selectMode=function(mode){
		var mtype=this.map.getMapType();
		var newMT="noChange";
		if(mode=="street"&&mtype!="map"){newMT="map";}
		if(mode=="aerial"&&mtype!="sat"){newMT="sat";}
		if(mode=="hybrid"&&mtype!="hyb"){newMT="hyb";}
		if(newMT!="noChange"){this.map.setMapType(newMT);dbTrack();}
	}
	MTViewControl.prototype.getHeight = function()
	{
		return 20;
	}
	MTViewControl.prototype.getWidth = function()
	{
		return 136;
	}
	/*	===============================================================	*/
	//	End Custom View Control
	/*	===============================================================	*/

	/*	===============================================================	*/
	//	Begin Custom MiniMap Control
	/*	===============================================================	*/
	function MQMiniMapControl(mm,xWidth,xHeight)
	{
		browser = getBrowserInfo();
		this.xWidth = xWidth;
		this.xHeight = xHeight;
		this.map = mm;
		this.position=new MQMapCornerPlacement(MQMapCorner.BOTTOM_RIGHT,new MQSize(0,0));
		this.elem = document.createElement("div");
		this.elem.style.zIndex = "500";
		this.elem.style.position = "absolute";
		this.elem.style.overflow = "visible";
		
		this.mapPad=document.createElement("div");
		this.mapPad.className = "miniMap-Pad";
		this.mapPad.id = "mapPad";
		this.elem.appendChild(this.mapPad);
		
		this.mapHold=document.createElement("div");
		this.mapHold.id = "mapHold";
		this.mapHold.className = "miniMap-Hold";
		this.mapHold.style.width = this.xWidth + "px";
		this.mapHold.style.height = this.xHeight + "px";
		this.mapPad.appendChild(this.mapHold);
		
		this.mapMinimizer=document.createElement("img");
		this.mapMinimizer.className = "miniDiv";
		this.mapMinimizer.src = sharedImagePath + "mapMin.gif";
		this.mapMinimizer.style.display="block";
		this.mapMinimizer.border=0;
		this.elem.appendChild(this.mapMinimizer);
	
		this.mapBlock=document.createElement("div");
		this.mapBlock.id = "mapBlock";
		this.mapBlock.className = "dragBlock";
		this.mapHold.appendChild(this.mapBlock);
	
	
		miniMap = new MQTileMap(this.mapHold,(Math.max(mm.getZoomLevel() - 3,1)), this.map.getCenter(),"map",miniKey);
		miniMap.setSize(new MQSize(this.xWidth,this.xHeight));
		miniMap.setLogoPlacement(MQMapLogo.SCALES,new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,5000)));
		miniMap.setLogoPlacement(MQMapLogo.MAPQUEST,new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,5000)));
		miniMap.setLogoPlacement(MQMapLogo.NAVTEQ_COPYRIGHT,new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,5000)));
		miniMap.setLogoPlacement(MQMapLogo.MAPQUEST_COPYRIGHT,new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,5000)));

		dbThumbTrack();
	
		this.mapHold.lastChild.firstChild.id = "miniMapMyst";
	
		Event.observe(this.mapBlock,"mousedown",function(){
															triggerMap = "block";
															if (startLL){clearTimeout(startLL);};
														});
		Event.observe(this.mapHold.lastChild.firstChild,"mousedown",function(){triggerMap = "miniMap"});
		Event.observe($('myMapMyst'),"mousedown",function(){triggerMap = "myMap"});
	
		MQEventManager.addListener(miniMap,"moveend",function(){
															if(!(triggerMap == "myMap")){
																startLL = setTimeout('myMap.panToLatLng(miniMap.getCenter())',750);
															}
															$('mapHold').appendChild($('mapBlock'));
															recenterBlock();
														}
													);
		MQEventManager.addListener(mm,"moveend",function(){
														if(!(triggerMap == "miniMap")){
															miniMap.setCenter(mm.getCenter());
														}
														dbThumbTrack();
													}
												);
		MQEventManager.addListener(mm,"zoomend",function(){
														miniMap.setZoomLevel(Math.max(mm.getZoomLevel() - 3,1));
														miniMap.setCenter(mm.getCenter());
														dbThumbTrack();
													}
												);
	
		/*
		tlPix = this.map.pixToLL(new MQPoint(0,0));
		brPix = this.map.pixToLL(new MQPoint(this.map.width,this.map.height));
		this.mapBlock.style.left = miniMap.llToPix(tlPix).x + "px";
		this.mapBlock.style.top = miniMap.llToPix(tlPix).y + "px";
		this.mapBlock.style.width = ((miniMap.llToPix(brPix).x) - (miniMap.llToPix(tlPix).x)) + "px";
		this.mapBlock.style.height = ((miniMap.llToPix(brPix).y) - (miniMap.llToPix(tlPix).y)) + "px";
		*/
		this.resetMiniBlock();
		Event.observe(this.mapBlock,"mousedown",bMouseDown);
		Event.observe(this.mapBlock,"mouseup",bMouseUp);
	
	}
	
	function delayMMPush(){
	}
	
	MQMiniMapControl.prototype = new MQControl();
	MQMiniMapControl.prototype.constructor = MQMiniMapControl;
	
	MQMiniMapControl.prototype.initialize = function(map)
	{
		this.map = map;
		this.type=CONTROL_TYPE;
		Event.observe(this.mapMinimizer, 'click', this.eventCallback("eventmonitor"));
	}
	
	MQMiniMapControl.prototype.eventmonitor = function(evt)
	{
		switch(evt.type){
			case "click":
				if(this.mapPad.style.display=="none"){
					this.mapPad.style.display="";
					this.mapMinimizer.src = sharedImagePath + "mapMin.gif";
					this.map.setLogoPlacement(MQMapLogo.NAVTEQ_COPYRIGHT,new MQMapCornerPlacement(MQMapCorner.BOTTOM_RIGHT, new MQSize(this.xWidth + 8,0)));
				}else{
					this.mapPad.style.display="none";
					this.mapMinimizer.src = sharedImagePath + "mapMax.gif";
					this.map.setLogoPlacement(MQMapLogo.NAVTEQ_COPYRIGHT,new MQMapCornerPlacement(MQMapCorner.BOTTOM_RIGHT, new MQSize(15,0)));
				}
			break;
		}
	}
	
	
	MQMiniMapControl.prototype.getHeight = function()
	{
		return this.xHeight + 6;
	}
	
	MQMiniMapControl.prototype.getWidth = function()
	{
		return  this.xWidth + 6;
	}

	MQMiniMapControl.prototype.resetMiniBlock = function(){
		tlPix = this.map.pixToLL(new MQPoint(0,0));
		brPix = this.map.pixToLL(new MQPoint(this.map.width,this.map.height));
		this.mapBlock.style.left = miniMap.llToPix(tlPix).x + "px";
		this.mapBlock.style.top = miniMap.llToPix(tlPix).y + "px";
		this.mapBlock.style.width = ((miniMap.llToPix(brPix).x) - (miniMap.llToPix(tlPix).x)) + "px";
		this.mapBlock.style.height = ((miniMap.llToPix(brPix).y) - (miniMap.llToPix(tlPix).y)) + "px";
		
	}

	
	function bMouseDown(e){
		mmWidth = miniMap.getSize().width - 4;
		mmHeight = miniMap.getSize().height - 4;
		mbWidth = parseInt($('mapBlock').style.width);
		mbHeight = parseInt($('mapBlock').style.height);
	
			dragapproved=true
			temp1=parseInt($('mapBlock').style.left)
			temp2=parseInt($('mapBlock').style.top)
			x = Event.pointerX(e);
			y = Event.pointerY(e);
			Event.observe($('mapBlock'),"mousemove",bMouseMove);
			return false
	}
	function bMouseMove(e){
		if (dragapproved){
			l = parseInt(temp1 + Event.pointerX(e) - x);
			t = parseInt(temp2 + Event.pointerY(e) - y);
	
			if(l< 0){
				l=0;
			}else if(l > mmWidth - mbWidth){
				l = mmWidth - mbWidth;
			}
			$('mapBlock').style.left=l + "px";
			if(t < 0){
				t = 0;
			}else if(t > mmHeight - mbHeight){
				t = mmHeight - mbHeight;
			}
			$('mapBlock').style.top = t + "px"; 
		return false
		}
	
	}
	function bMouseUp(e){
		dragapproved=false;
		$('miniMapMyst').appendChild($('mapBlock'));
		miniMap.panToLatLng(miniMap.pixToLL(new MQPoint((parseInt($('mapBlock').style.left) + Math.round(parseInt($('mapBlock').style.width)/2)),(parseInt($('mapBlock').style.top) + Math.round(parseInt($('mapBlock').style.height)/2)))));
	}
	
	function recenterBlock(){
		$('mapBlock').style.left = Math.round((parseInt($('mapHold').style.width)/2)- (parseInt($('mapBlock').style.width)/2)) + "px";
		$('mapBlock').style.top = Math.round((parseInt($('mapHold').style.height)/2)- (parseInt($('mapBlock').style.height)/2)) + "px";
	
	}
	function resetBlock(){
		tlPix = myMap.pixToLL(new MQPoint(0,0));
		brPix = myMap.pixToLL(new MQPoint(myMap.width,myMap.height));
		$('mapBlock').style.left = miniMap.llToPix(tlPix).x + "px";
		$('mapBlock').style.top = miniMap.llToPix(tlPix).y + "px";
		$('mapBlock').style.width = ((miniMap.llToPix(brPix).x) - (miniMap.llToPix(tlPix).x)) + "px";
		$('mapBlock').style.height = ((miniMap.llToPix(brPix).y) - (miniMap.llToPix(tlPix).y)) + "px";
	
	}
	/*	===============================================================	*/
	//	End Custom MiniMap Control
	/*	===============================================================	*/

	/*	===============================================================	*/
	//	Begin Custom Zoom Control
	/*	===============================================================	*/
	function MQCustomLargeZoomControl(){
		browser=getBrowserInfo();
		this.pan=new Array();
		this.zoombar=new Array();
		this.map=null;
		this.position=new MQMapCornerPlacement(MQMapCorner.TOP_LEFT,new MQSize(5,30));
		this.elem=document.createElement("div");
		this.elem.style.position="absolute";
		this.elem.style.overflow="visible";
		temp=document.createElement("div");
		temp.className="map-controls-bg screen";
		this.elem.appendChild(temp);
		temp1=document.createElement("div");
		temp1.className="map-compass-wrapper";
		temp.appendChild(temp1);
		temp1=document.createElement("div");
		temp1.className="map-zoom";
		temp.appendChild(temp1);
		temp1=document.createElement("div");
		temp1.className="map-revert";
		temp.appendChild(temp1);
		temp=document.createElement("ul");
		temp.className="map-controls screen";
		this.elem.appendChild(temp);
		temp1=document.createElement("li");
		temp1.className="map-compass-wrapper";
		temp.appendChild(temp1);
		temp2=document.createElement("div");
		temp2.className="map-compass";
		temp1.appendChild(temp2);
		temp3=document.createElement("img");
		temp3.border=0;
		if(browser.name=="msie"){
			temp3.src="http://img.mqcdn.com/a/a";
			temp3.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src= '"+sharedImagePath + "zoomShort/map-compassrose.png', sizingMethod='image')";
		}else{
			temp3.src= sharedImagePath + "zoomShort/map-compassrose.png";
		}
		temp3.alt="compass rose";
		temp3.className="";
		temp2.appendChild(temp3);
		this.compassrose=temp3;
		temp3=document.createElement("img");
		temp3.border=0;
		temp3.src="http://img.mqcdn.com/a/a";
		temp3.className="map-compass-links";
		temp3.alt="Pan or recenter the map";
		temp3.useMap="#mq-zoomcontrol-linkmap";
		temp3.title="Pan or recenter the map";
		temp2.appendChild(temp3);
		temp3=document.createElement("map");
		temp3.name="mq-zoomcontrol-linkmap";
		temp3.id="mq-zoomcontrol-linkmap";
		temp2.appendChild(temp3);
		temp4=document.createElement("area");
		temp4.shape="poly";
		temp4.coords="14,21,16,16,21,14,25,16,27,21,25,25,21,27,16,25,14,21,14,21";
		temp4.href="#center";
		temp4.title="Fit to Screen";
		temp4.alt="Fit to Screen";
		temp3.appendChild(temp4);
		temp4=document.createElement("area");
		temp4.shape="rect";
		temp4.coords="11,1,29,12";
		temp4.href="#north";
		temp4.title="Pan North";
		temp4.alt="Pan North";
		temp3.appendChild(temp4);
		this.pan[PAN_NORTH]=temp4;
		temp4=document.createElement("area");
		temp4.shape="rect";
		temp4.coords="27,13,40,28";
		temp4.href="#east";
		temp4.title="Pan East";
		temp4.alt="Pan East";
		temp3.appendChild(temp4);
		this.pan[PAN_EAST]=temp4;
		temp4=document.createElement("area");
		temp4.shape="rect";
		temp4.coords="1,13,14,28";
		temp4.href="#west";
		temp4.title="Pan West";
		temp4.alt="Pan West";
		temp3.appendChild(temp4);
		this.pan[PAN_WEST]=temp4;
		temp4=document.createElement("area");
		temp4.shape="rect";
		temp4.coords="11,29,29,40";
		temp4.href="#south";
		temp4.title="Pan South";
		temp4.alt="Pan South";
		temp3.appendChild(temp4);
		this.pan[PAN_SOUTH]=temp4;
		temp1=document.createElement("li");
		temp1.className="map-zoom";
		temp.appendChild(temp1);
		temp2=document.createElement("div");
		temp2.className="io map-zoom-in";
		temp1.appendChild(temp2);
		this.zoomin=document.createElement("img");
		this.zoomin.alt="Zoom In";
		this.zoomin.title="Zoom In";
		this.zoomin.border=0;
		if(browser.name=="msie"){
			this.zoomin.src="http://img.mqcdn.com/a/a";
			this.zoomin.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+sharedImagePath + "zoomShort/z-in.png', sizingMethod='image')";
		}else{
			this.zoomin.src= sharedImagePath + "zoomShort/z-in.png";
		}
		temp2.appendChild(this.zoomin);
	
		for(var i=zoomLevelHigh;i>=zoomLevelLow;i--){
			this.zoombar[i]=document.createElement("img");
			this.zoombar[i].alt="Zoom to level "+i;
			this.zoombar[i].title="Zoom to level "+i;
			this.zoombar[i].border=0;
			this.zoombar[i].style.display="block";
			if(browser.name=="msie"){
				this.zoombar[i].src="http://img.mqcdn.com/a/a";
				f=sharedImagePath+"zoomShort/z-"+i+".png";
				this.zoombar[i].style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+f+"', sizingMethod='image')";
			}else{
				this.zoombar[i].src=sharedImagePath+"zoomShort/z-"+i+".png";
			}
			temp1.appendChild(this.zoombar[i]);
		}
	
		temp2=document.createElement("div");
		temp2.className="io map-zoom-out";
		temp1.appendChild(temp2);
		this.zoomout=document.createElement("img");
		this.zoomout.alt="Zoom Out";
		this.zoomout.title="Zoom Out";
		this.zoomout.border=0;
		if(browser.name=="msie"){
			this.zoomout.src="http://img.mqcdn.com/a/a";
			this.zoomout.style.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + sharedImagePath + "zoomShort/z-out.png', sizingMethod='image')";
		}else{
			this.zoomout.src=sharedImagePath+"zoomShort/z-out.png";
		}
		temp2.appendChild(this.zoomout);
	}
	
	MQCustomLargeZoomControl.prototype=new MQControl();
	
	MQCustomLargeZoomControl.prototype.constructor=MQCustomLargeZoomControl;
	
	MQCustomLargeZoomControl.prototype.initialize=function(map){
		this.map=map;
		this.type=CONTROL_PANZOOM;
		this.selectZoom(this.map.GetZoomLevel());
		for(var i=0;i<4;i++){
			Event.observe(this.pan[i],'click',this.eventCallback("eventmonitor"));
			Event.observe(this.pan[i],'mouseover',this.eventCallback("eventmonitor"));
			Event.observe(this.pan[i],'mouseout',this.eventCallback("eventmonitor"));
		}
		Event.observe(this.zoomin,'click',this.eventCallback("eventmonitor"));
		Event.observe(this.zoomout,'click',this.eventCallback("eventmonitor"));
		Event.observe(this.zoomin,'mouseover',this.eventCallback("eventmonitor"));
		Event.observe(this.zoomout,'mouseover',this.eventCallback("eventmonitor"));
		Event.observe(this.zoomin,'mouseout',this.eventCallback("eventmonitor"));
		Event.observe(this.zoomout,'mouseout',this.eventCallback("eventmonitor"));
		for(var i=zoomLevelLow;i<=zoomLevelHigh;i++){
			Event.observe(this.zoombar[i],'click',this.eventCallback("eventmonitor"));
			Event.observe(this.zoombar[i],'mouseover',this.eventCallback("eventmonitor"));
			Event.observe(this.zoombar[i],'mouseout',this.eventCallback("eventmonitor"));
		}
	}
	
	MQCustomLargeZoomControl.prototype.eventmonitor=function(evt){
		if(Event.element(evt)==this.pan[PAN_NORTH])eventId="n";
		if(Event.element(evt)==this.pan[PAN_SOUTH])eventId="s";
		if(Event.element(evt)==this.pan[PAN_EAST])eventId="e";
		if(Event.element(evt)==this.pan[PAN_WEST])eventId="w";
		if(Event.element(evt)==this.zoomin)eventId="in";
		if(Event.element(evt)==this.zoomout)eventId="out";
		for(var i=zoomLevelLow;i<=zoomLevelHigh;i++){
			if(Event.element(evt)==this.zoombar[i])eventId=i;
		}
		switch(evt.type){
			case"click":
				switch(eventId){
					case"in":
						if(this.map.getZoomLevel()<zoomLevelHigh){
							this.map.zoomIn();
						}
					break;
					case"out":
						if(this.map.getZoomLevel()>zoomLevelLow){
							this.map.zoomOut();
						}
					break;
					case"n":
						this.map.PanNorth(50);
					break;
					case"s":
						this.map.PanSouth(50);
					break;
					case"e":
						this.map.PanEast(50);
					break;
					case"w":
						this.map.PanWest(50);
					break;
					default:
						this.map.setZoomLevel(eventId);
					break;
				}
			break;
	
			case"mouseover":
				switch(eventId){
					case"in":
					case"out":
						Event.element(evt).addClassName("o");
					break;
					case"n":
						this.compassrose.className="n";
					break;
					case"s":
						this.compassrose.className="s";
					break;
					case"e":
						this.compassrose.className="e";
					break;
					case"w":
						this.compassrose.className="w";
					break;
					default:
						this.selectZoom(eventId);
				}
			break;
	
			case"mouseout":
				switch(eventId){
					case"in":
					case"out":
						Event.element(evt).removeClassName("o");
					break;
					case"n":
					case"s":
					case"e":
					case"w":
						this.compassrose.className="";
					break;
	
					default:
						if(parseFloat(eventId)!=this.map.GetZoomLevel()){
							this.unselectZoom(eventId);
						}
					break;
				}
			break;
		}
	}
	
	MQCustomLargeZoomControl.prototype.selectZoom=function(level){
		this.zoombar[level].src=sharedImagePath+"zoomShort/z-on.png";
	}
	
	MQCustomLargeZoomControl.prototype.unselectZoom=function(level){
		this.zoombar[level].src=sharedImagePath+"zoomShort/z-"+level+".png";
	}
	
	MQCustomLargeZoomControl.prototype.getHeight=function(){
		return 304;
	}
	
	MQCustomLargeZoomControl.prototype.getWidth=function(){
		return 50;
	}
	/*	===============================================================	*/
	//	End Custom Zoom Control
	/*	===============================================================	*/
/*	===========================================================================	*/
//	End of custom Controls
/*	===========================================================================	*/

Event.observe(window,"load",init);
var card;
var kill;
var slow;
var startLL;

var zoomOut = 0;
var zo = 0;
var startX = 0;
var startY = 0;
var endX = 0;
var endY = 0;
var coverOffX = 0;
var coverOffY = 0;
var h = 0;
var w = 0;
// mke Room for sessions.

if(!(map_zip_start)) {var map_zip_start = ""};
if(!(map_city_start)) {var map_city_start = ""};
if(!(map_state_start)) {var map_state_start = ""};
if(!(map_scale_start)) {var map_scale_start = ""};

// Create and Popup the Loading Graphic
function coverLoading(){
	tmp1 = document.createElement("div");
	tmp1.id = "loadingCover";
	tmp1.className = "loadingCover";
	tmp2 = document.createElement("img");
	tmp2.border=0;
	tmp2.align="left";
	tmp2.src=sharedImagePath + "aloader.gif";
	tmp1.appendChild(tmp2);
	tmp3 = document.createElement("p");
	tmp3.innerHTML = " loading...";
	tmp1.appendChild(tmp3);
	$('mapWindow').appendChild(tmp1);
	
}
// kill the popup
function killLoading(){
	if($('loadingCover')){
		$('loadingCover').remove();
	}
}

// once the page loads..  run this to get the maps on the page.
function init(){
	if ((map_zip_start != "") || (map_city_start != "") || (map_state_start != "")){
		//Proxy server variables
		var proxyServerName = "";
		var proxyServerPort = "";
		var ProxyServerPath = "jsreqhandler.cfm";
		
		//set up the connection to the geocode server
		var geoServerName = "geocode.access.mapquest.com";
		var geoServerPort = "80";
		var geoServerPath = "mq";
		var geoExec = new MQExec(geoServerName, geoServerPath, geoServerPort, proxyServerName,ProxyServerPath, proxyServerPort );
		
		//set up the connection to the Spatial search server
		var spatServerName = "spatial.access.mapquest.com";
		var spatServerPort = "80";
		var spatServerPath = "mq";
		var searchExec = new MQExec(spatServerName, spatServerPath, spatServerPort, proxyServerName,ProxyServerPath, proxyServerPort );

		var myAddress = new MQAddress();
		var myLocColl = new MQLocationCollection("MQGeoAddress");
		myAddress.setCity(map_city_start);
		myAddress.setState(map_state_start);
		myAddress.setPostalCode(map_zip_start);
		geoExec.geocode(myAddress, myLocColl);
		myRetAddr = myLocColl.get(0);
		$('clat').value = myRetAddr.getMQLatLng().getLatitude();
		$('clng').value = myRetAddr.getMQLatLng().getLongitude();
		if(map_scale_start != ""){
			$('mapscale').value = map_scale_start;
		}
	}

	myMap = new MQTileMap(document.getElementById('mapWindow'),$('mapscale').value, new MQLatLng($('clat').value,$('clng').value),default_map_type,mainKey);
	$('mapWindow').childNodes[1].id = "myMapMyst"

	if ($('map_tl_lat').value != ""){
		myMap.zoomToRect(new MQRectLL(new MQLatLng($('map_tl_lat').value,$('map_tl_lng').value),new MQLatLng($('map_br_lat').value,$('map_br_lng').value)));
	}
	document.searchForm.property_id.value = "";

	/*
	if(myMap.getZoomLevel() >= 4){
		addMiniMap();
	}
	*/
	myZoomControl = new MQCustomLargeZoomControl(myMap);
	myMap.addControl(myZoomControl);
	myCADControl = new MQCADControl(default_drag_type);
	myMap.addControl(myCADControl);
	myViewControl = new MTViewControl(myMap);
	myMap.addControl(myViewControl);

	myMQLogo = new MQMapCornerPlacement(MQMapCorner.TOP_LEFT,new MQSize(0,20));
	myMap.setLogoPlacement(MQMapLogo.MAPQUEST,myMQLogo);
	myScales = new MQMapCornerPlacement(MQMapCorner.TOP_RIGHT,new MQSize(0,20));
	myMap.setLogoPlacement(MQMapLogo.SCALES,myScales);
	myMap.setLogoPlacement(MQMapLogo.NAVTEQ_COPYRIGHT,new MQMapCornerPlacement(MQMapCorner.BOTTOM_RIGHT, new MQSize(200 + 8,0)));


	MQEventManager.addListener(myMap,"moveend",function(){prePushLL()});
	MQEventManager.addListener(myMap,"zoomend",function(){prePushLL()});
	MQEventManager.addListener(myMap,"move",function(){killPushLL()});
	MQEventManager.addListener(myMap,"moveend",function(){resetCoverDiv();});
	MQEventManager.addListener(myMap,"zoomend",function(){resetCoverDiv();});
	MQEventManager.addListener(myMap,"moveend",dbTrack);
	MQEventManager.addListener(myMap,"zoomend",dbTrack);
	
	MQEventManager.addListener(myMap,"zoomend",evalMiniMap);

	evalMiniMap();
	dbTrack();
	pushLL();
}
function evalMiniMap(){
	if((myMap.getZoomLevel() >= 4) && (typeof(myLZControl)== "undefined" || myLZControl == "")){
		addMiniMap();
	}else if(myMap.getZoomLevel() < 4){
		removeMiniMap();
	}
}
function addMiniMap(){
	myLZControl = new MQMiniMapControl(myMap,200,110);
	myMap.addControl(myLZControl);
	
}
function removeMiniMap(){
	if(typeof(myLZControl)!= "undefined"){
		myMap.removeControl(myLZControl);
		myLZControl = "";
	}
}
// track the map draw
function dbTrack(){
	var pars = "page_type=search&map_type=" + myMap.getMapType();
	pars = pars + '&default_map_type=' + myMap.getMapType();
	pars = pars + '&default_drag_type=' + myCADControl.drag_type;
	var myAjax = new Ajax.Request("jsdbtrack.cfm", {method:"post", postBody:pars});
}
// track the minimap draw
function dbThumbTrack(){
	var pars = "page_type=searchthumb";
	var myAjax = new Ajax.Request("jsdbtrack.cfm", {method:"post", postBody:pars});
}

// clear the prop count displays
function cleanPageCounts(){
	$('showMatch').style.display = "block";
	$('showText').innerHTML = "";
	$('showCount').innerHTML = "";
	$('matchText').innerHTML = "";
	$('matchCount').innerHTML = "loading...";
	// ::useKWMap:: this will not be in the KW pages so check for it
	if($('showMatchKW')){
		$('showMatchKW').style.display = "block";
		$('showTextKW').innerHTML = "";
		$('showCountKW').innerHTML = "";
		$('matchTextKW').innerHTML = "";
		$('matchCountKW').innerHTML = "loading...";
	}
	// ::useKWMap:: this will not be in the KW pages so check for it
	if ($('resultsMatchCount')){
		$('resultsMatchCount').innerHTML = "loading...";
		$('resultsMatchText').innerHTML = "";
	}
	return true;
}
// time out function to delay new query between map dragging
function prePushLL(){
	if (startLL){clearTimeout(startLL);};
	startLL = setTimeout('pushLL()',750);
}
// drop the query if a new map drag has started
function killPushLL(){
	if (myMap.getDragEnabled()){
		if (startLL){clearTimeout(startLL);};
	}
}
// get the Lat Lng bounds and push the Query
function pushLL(){
	cleanPageCounts();
	tlPix = myMap.pixToLL(new MQPoint(0,0));
	brPix = myMap.pixToLL(new MQPoint((myMap.width-1),(myMap.height-1)));
	$('map_br_lat').value = brPix.lat;
	$('map_br_lng').value = brPix.lng;
	$('map_tl_lat').value = tlPix.lat;
	$('map_tl_lng').value = tlPix.lng;
	$('clat').value = myMap.getCenter().lat;
	$('clng').value = myMap.getCenter().lng;
	$('mapscale').value = myMap.getZoomLevel();
	coverLoading();
	pushQ();
}

// AJAX call to the query page.
function pushQ(){
	var pars = Form.serialize('searchForm');
	pars = pars + '&default_map_type=' + myMap.getMapType();
	pars = pars + '&default_drag_type=' + myCADControl.drag_type;
	var url = "jspropsearch.cfm";
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'post', 
			parameters: pars, 
			onSuccess: fastProps,
			onFailure: function(t) {alert('Error ' + t.status + ' -- ' + t.statusText);}
		});
}

// on a succesful query, process the JSON structure
function fastProps(t){
	card = eval('(' + t.responseText + ')');
	var fullOpenCount = card.O;
	var fullCount = card.F;
	var pCount = card.P;
	var uniCount = card.G.length;
	if (fullOpenCount > 0){
		if (fullCount > map_display_max){
			$('showText').innerHTML = "<br>Showing top&nbsp;" + map_display_max + "&nbsp;Listings";
			$('showCount').innerHTML = "";
			if($('showMatchKW')){
				$('showTextKW').innerHTML = "<br>Showing top&nbsp;" + map_display_max + "&nbsp;Listings";
				$('showCountKW').innerHTML = "";
			}
		}else{
			$('showText').innerHTML = "";
			$('showCount').innerHTML = "";
			if($('showMatchKW')){
				$('showTextKW').innerHTML = "";
				$('showCountKW').innerHTML = "";
			}
		}

		if (fullOpenCount == 1){
			var superMatchText = '&nbsp;Open House';
		}else{
			var superMatchText = '&nbsp;Open Houses';
		}
		if (pCount == 1){
			var superMatchTextOpen = '&nbsp;Listing';
		}else{
			var superMatchTextOpen = '&nbsp;Listings';
		}
	
		// ::useKWMap:: this will not be in the KW pages so check for it
		if ($('resultsMatchCount')){
			$('resultsMatchCount').style.fontSize = "15";
			$('resultsMatchText').style.fontSize = "12";
			$('resultsMatchText').style.fontWeight = "";
			$('resultsMatchCount').innerHTML = fullOpenCount + superMatchText + '<br/>';
			$('resultsMatchText').innerHTML = 'for&nbsp;' + fullCount + superMatchTextOpen;
		}
		$('matchCount').innerHTML = fullOpenCount + superMatchText;
		$('matchText').innerHTML =  'for&nbsp;' + fullCount + superMatchTextOpen;
		if($('showMatchKW')){
			$('matchCountKW').innerHTML = fullOpenCount + superMatchText;
			$('matchTextKW').innerHTML =  'for&nbsp;' + fullCount + superMatchTextOpen;
		}
	}else{
		if (fullCount > map_display_max){
			$('showText').innerHTML = "&nbsp;-&nbsp;Showing top&nbsp;";
			$('showCount').innerHTML = map_display_max;
			if($('showMatchKW')){
				$('showTextKW').innerHTML = "&nbsp;-&nbsp;Showing top&nbsp;";
				$('showCountKW').innerHTML = map_display_max;
			}
		}else{
			$('showText').innerHTML = "";
			$('showCount').innerHTML = "";
			if($('showMatchKW')){
				$('showTextKW').innerHTML = "";
				$('showCountKW').innerHTML = "";
			}
		}
		if (pCount == 1){
			var superMatchText = '&nbsp;Match';
		}else{
			var superMatchText = '&nbsp;Matches';
		}
	
		$('matchCount').innerHTML = fullCount;
		$('matchText').innerHTML = superMatchText;
		if($('showMatchKW')){
			$('matchCountKW').innerHTML = fullCount;
			$('matchTextKW').innerHTML = superMatchText;
		}
		// ::useKWMap:: this will not be in the KW pages so check for it
		if ($('resultsMatchCount')){
			$('resultsMatchCount').innerHTML = fullCount;
			$('resultsMatchText').innerHTML = superMatchText;
		}
	}




	if($('mqwntdiv')){
		$('mqwntdiv').innerHTML = null;
	}else{
		tmp1 = document.createElement("div");
		tmp1.id = "mqwntdiv";
		tmp1.style.position = "absolute";
		tmp1.style.top = "0px";
		tmp1.style.left = "0px";
		tmp1.style.cursor = "auto";
		tmp1.style.zIndex = "9";
		$('mqtiledmap').appendChild(tmp1);
	}

	for (i=0 ; i < uniCount ; i++){
		tmp2LL = new MQLatLng(card.G[i].L[0].N,card.G[i].L[0].O);
		tmp2 =document.createElement("div");
		tmp2.id = i + "hd";
		if (card.G[i].L.length > 1){
			tmp2.className="houseIcon " + card.G[i].L[0].Q + "_p";
		}else{
			tmp2.className="houseIcon " + card.G[i].L[0].Q;
		}

		tmp2.style.left = (myMap.llToPix(tmp2LL).x - parseInt($('mqtiledmap').style.left)) + "px";
		tmp2.style.top = (myMap.llToPix(tmp2LL).y - parseInt($('mqtiledmap').style.top)) + "px";
		Event.observe(tmp2,"mouseover",function(){popOverTimer(this.id)});
		Event.observe(tmp2,"mouseout",function(){hideMe(this.id)});
		Event.observe(tmp2,"click",function(){exitPage(this.id)});

		Event.observe(tmp2,"mouseover",function(){popIcon(this.id,10)});
		Event.observe(tmp2,"mouseout",function(){popIcon(this.id,9)});

		$('mqwntdiv').appendChild(tmp2);

	}
	killLoading();
}

// move the icon to the front when mousing over it.
function popIcon(id,x){
	if (document.all) {
		robbie = $(event.srcElement);
	} else {
		robbie = $(id);
	}
	robbie.style.zIndex = x;
}
// fill in the form element with the current PropID's and submit the form
function exitPage(id){
	if (document.all) {
		robbie = $(event.srcElement);
	} else {
		robbie = $(id);
	}
	var xid = parseInt(robbie.id);
	var xitID = "";
	for (xloop=0 ; xloop < card.G[xid].L.length ; xloop++){
			xitID = listAppend(xitID,card.G[xid].L[xloop].D);
	}
	document.searchForm.property_id.value = xitID;
	$('searchForm').submit();

}

// Click on a single houseover
function exitHouseOver(id){
	document.searchForm.property_id.value = id;
	$('searchForm').submit();
}

// delay the pop over a little when moving the mouse over the map
function popOverTimer(id){
	if (document.all) {
		robbie = $(event.srcElement);
	} else {
		robbie = $(id);
	}
	if (kill){clearTimeout(kill);};
	slow = setTimeout('popOver(\''+robbie.id+'\',\''+robbie.style.left+'\',\''+robbie.style.top+'\')',150);
}

// delay hiding the mouse over
function hideMe(bar){
		if (slow){clearTimeout(slow);};
		kill = setTimeout('killOver(\'oneHouseOver\')',300);	
}

// kill the mouseover
function killOver(bar){
	if (kill){clearTimeout(kill);};
	if($('oneHouseOver')){$('oneHouseOver').remove();}
	if(!($('coverDiv'))){myMap.enableDragging(1);}
}


// create the mouseover and display it
function popOver(foo,x,y){
	myMap.enableDragging(0);
	var rollHeight = 104;
	var buildDIVString = "";
	var xid = parseInt(foo);
	if($('oneHouseOver')){$('oneHouseOver').remove();}
	xxx =document.createElement("div");
	xxx.id = "oneHouseOver";
	xxx.style.position = "absolute";
	xxx.style.zIndex = 100;
	xxx.style.width = "315px";
	currX = parseInt(x);
	currY = parseInt(y);

	if (card.G[xid].L.length > 2){
		xxx.style.height = "208px";
		xxx.style.overflowY = "scroll";
		xxx.style.overflowX = "hidden";
	}
	if (card.G[xid].L.length > 1){
		var rollHeight = 208;
	}
	switch(whatQ(myMap.getSize().getWidth(),myMap.getSize().getHeight(),(parseInt(x) + parseInt($('mqtiledmap').style.left)),(parseInt(y) + parseInt($('mqtiledmap').style.top)))){
	case 0 :
		currX = currX + 20;
		currY = currY;
		break;
	case 1 :
		currX = currX - 152;
		currY = currY + 20;
		break;
	case 2 :
		currX = currX - 307;
		currY = currY;
		break;
	case 3 :
		currX = currX + 20;
		currY = currY -(rollHeight -20);
		break;
	case 4 :
		currX = currX - 152;
		currY = currY -(rollHeight);
		break;
	case 5 :
		currX = currX - 307;
		currY = currY -(rollHeight -20);
		break;
	}

	xxx.style.top = currY + "px";
	xxx.style.left = currX + "px";

	for (xloop=0 ; xloop < card.G[xid].L.length ; xloop++){
		buildDIVString += theHouseOver(
								card.G[xid].L[xloop].D,
								formatCurrency(card.G[xid].L[xloop].F),
								card.G[xid].L[xloop].I,
								card.G[xid].L[xloop].J,
								card.G[xid].L[xloop].M,
								card.G[xid].L[xloop].G,
								card.G[xid].L[xloop].H,
								card.G[xid].L[xloop].L,
								card.G[xid].L[xloop].K,
								card.G[xid].L[xloop].R,
								card.G[xid].L[xloop].S,
								card.G[xid].L[xloop].T,
								card.G[xid].L[xloop].U,
								card.G[xid].L[xloop].A,
								card.G[xid].L[xloop].B,
								card.G[xid].L[xloop].V,
								card.G[xid].L[xloop].W,
								card.G[xid].L[xloop].X,
								card.G[xid].L[xloop].Y,
								card.G[xid].L[xloop].CTAT,
								card.G[xid].L[xloop].CTAV
							);
	}


	xxx.innerHTML = buildDIVString;
	Event.observe(xxx,"mouseout",function(){hideMe('oneHouseOver')});
	Event.observe(xxx,"mouseover",function(){if(kill){clearTimeout(kill);}});

	$('mqwntdiv').appendChild(xxx);
	if(xxx.childElementCount > 2){
		xxx.style.height = (xxx.children[0].clientHeight + xxx.children[1].clientHeight + "px");
	}
	xxx.show();
}

// create the HTML for the mouse over
function theHouseOver(pid,price,addone,addtwo,style,bed,bath,built,feet,thumbpath,ohCount,ohDetail,status,agent_name,office_name,hideaddress,market_name,hide_bedbath,officePhone,call_to_action_text,call_to_action_value){
	//
	// Configuration of a few parameters.  Markets in forceBold will have their agent/office names displayed
	// in bold text regardless of the default.  Entries in logoExt control which markets use a logo extension
	// other than .jpg
	//
	var marketConfig = {
		forceBold: ["ME_MREIS", "VA_REIN"],
		logoExt: {
			VA_REIN: ".gif"
		}
	};
	//
	// Calculate some pseudo-constants
	//
	var normalizedMarketName = market_name.toUpperCase();
	var normalizedBrokerRec = broker_rec.toUpperCase();
	//
	// Generate booleans for commonly used config options
	var showBrokerRec = ( broker_rec != "" ) && ( market_name == "" || normalizedMarketName == normalizedBrokerRec );
	//
	//
	// If marketConfig.logoExt contains a property with the same name as this market,
	// use its value as the logo extension.  Otherwise default to '.jpg'.
	//
	if(marketConfig.logoExt[normalizedMarketName]) {
		var logoExt = marketConfig.logoExt[normalizedMarketName];
	} else {
		var logoExt = ".jpg";
	}
	//
	// Any markets in marketConfig.forceBold will use the bold form of agent/office name.
	//
	var forceBold = marketConfig.forceBold.findIn(normalizedMarketName);
	if(forceBold) {
		var brandingCss = 'class="detBoldText"';
	} else {
		var brandingCss = 'class="detTextLight"';
	}
	//
	// Calculate thumbnail path
	//
	var tPath;
	if(thumbpath.length == 0){
		tPath = mls_photopath+splitPID(pid)+pid+'-1.jpg';
	}else{
		tPath = thumbpath;
	}
	var strDiv = '<DIV style="CURSOR: pointer;" onClick="exitHouseOver(\'' + pid +'\');">';
	strDiv +='			<table cellpadding="0" cellspacing="1" class="houseOver" onclick="" id="hdTable">';
	strDiv +='			  <tr>';
	strDiv +='			    <td width="100" align="left">';
	strDiv +='				<img src="'+ tPath+'" width="100" height="78" id="tNail" name="tNail"  onError="this.src=\'http://www.mlsfinder.com/mlsfinderart/photo_not_available_thmb.jpg\';"></td>';
	strDiv +='			    <td>&nbsp;</td>';
	strDiv +='			    <td align="left" valign="top"><table width="190"  border="0" cellpadding="0" cellspacing="0" class="detText" ID="Table1">';
	strDiv +='			        <tr>';
	if (status.toUpperCase() == "SOLD" || status.toUpperCase() == "COMP SOLD"){
		strDiv +='			          <td nowrap><span class="red">Sold Price: </span><span class="detBoldText" id="hdPrice">' + price + '</span></td>';
	}else{
		strDiv +='			          <td nowrap><span class="detBoldText" id="hdPrice">' + price + '</span></td>';
	}
	if(showPropID) {
		strDiv +='					  <td nowrap>MLS#: <span class="detBoldText">' + pid + '</span></td>';
	} else {
		strDiv +='					  <td nowrap>&nbsp;</td>';
	}
	strDiv +='			        </tr>';
	if(displayVowLabel == 'true'){
		strDiv +='				        <tr>';
		if(idx_authenticated == "Yes"){
			if(call_to_action_text.toUpperCase() == "ORIGINAL LIST PRICE") {
				// Need to format as currency
				strDiv +='				          <td colspan="2" id="vow_field" nowrap" class="detBoldText">'+ call_to_action_text +': ' + formatCurrency(call_to_action_value) + '</td>';
			} else {
				strDiv +='				          <td colspan="2" id="vow_field" nowrap" class="detBoldText">'+ call_to_action_text +': ' + call_to_action_value + '</td>';
			}
		}else{
			strDiv +='				          <td colspan="2" id="vow_field" nowrap" class="detBoldText">'+ call_to_action_text +': <a href="' + cgiScriptName + '?action=userlogin" target="_top" id="loginLinkRef" style="">Click Here</a><br></td>';
		}
		strDiv +='				        </tr>';
	}
	if ((display_address == "I" || hideaddress == "Y") && display_address != "B") { //hideaddress is for property by property hiding of the address for certain markets.
		strDiv +='';
	}
	else if (display_address == "L"){
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" id="login_req" nowrap" style="font-size:9px;">Please <a href="' + cgiScriptName + '?action=userlogin" target="_top" id="loginLinkRef">LOGIN AND AUTHENTICATE EMAIL</a><br>  to View Address</td>';
		strDiv +='				        </tr>';
	}
	else if (display_address == "A"){
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" id="login_req" nowrap style="font-size:9px;">Please <a href="' + cgiScriptName + '?action=userhome" target="_top" id="loginLinkRef">AUTHENTICATE EMAIL</a> to View Address</td>';
		strDiv +='				        </tr>';
	}		
	else if (display_address == "N"){
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" id="login_req" nowrap>Please <a href="' + cgiScriptName + '?action=userlogin" target="_top" id="loginLinkRef">Login</a> to View Address</td>';
		strDiv +='				        </tr>';
	}
	else if (display_address == "B")
	{
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" id="login_req" nowrap>Please <a href="' + cgiScriptName + '?action=userlogin" target="_top" id="loginLinkRef">Login</a> to View Address</td>';
		strDiv +='				        </tr>';
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" ><span class="detBoldText" id="hdAddTwo">' + addtwo + '</span></td>';
		strDiv +='				        </tr>';
	}
	else if (display_address == "P")
	{
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" ><span class="detBoldText" id="hdAddOne"></span></td>';
		strDiv +='				        </tr>';
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" ><span class="detBoldText" id="hdAddTwo">' + addtwo + '</span></td>';
		strDiv +='				        </tr>';
	}
	else{
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" ><span class="detBoldText" id="hdAddOne">' + addone +  '</span></td>';
		strDiv +='				        </tr>';
		strDiv +='				        <tr>';
		strDiv +='				          <td colspan="2" ><span class="detBoldText" id="hdAddTwo">' + addtwo + '</span></td>';
		strDiv +='				        </tr>';
	}

	strDiv +='			        <tr>';
	strDiv +='			          <td colspan="2" nowrap><span class="detBoldText" id="hdStyle">' + style + '</span></td>';
	strDiv +='			        </tr>';
	if (!hide_bedbath) {
		var tmpDiv ='			        <tr>';
		var blank = 0;
		if(bed != "n/a" && bed != 0) {
			tmpDiv +='			          <td nowrap>Bedrooms: <span class="detBoldText" id="hdBed">'+ bed +'</span> </td>';
		} else { blank++; }
		if(bath != "n/a" && bath != 0) {
			tmpDiv +='			          <td nowrap>Bathrooms: <span class="detBoldText" id="hdBath">'+ bath +'</span></td>';
		} else { blank++; }
		if(blank == 1) { 
			tmpDiv += '			          <td>&nbsp;</td>';
		}
		tmpDiv +='			        </tr>';
		if(blank == 0 || blank == 1) {
			strDiv += tmpDiv;
		} // If blank == 2, do not output row.
	}
	strDiv +='			        <tr>';
	if (status.toUpperCase() == "SOLD" || status.toUpperCase() == "COMP SOLD"){
		strDiv +='			          <td nowrap colspan="2">Year Built: <span class="detBoldText" id="hdYear">'+ built +'</span> </td>';
	}else{
		var blank = 0;
		if(feet.length != 0) {
			if(market_name.toUpperCase() == "CO_METROLIST") {
				var sqFtLabel = 'Total Square Feet: ';
			} else {
				var sqFtLabel = 'Sq Ft: ';
			}
			strDiv +='			          <td nowrap>' + sqFtLabel + '<span class="detBoldText" id="hdSqFt">'+ feet +'</span> </td>';
		} else { blank++; }
		if(built.length != 0) {
			strDiv +='			          <td nowrap>Year Built: <span class="detBoldText" id="hdYear">'+ built +'</span> </td>';
		} else { blank++; }
		if(blank == 1) { 
			strDiv += '			          <td>&nbsp;</td>'; 
		}
		else if(blank == 2) { 
			strDiv += '			          <td>&nbsp;</td><td>&nbsp;</td>'; 
		}
	}
	strDiv +='			        </tr>';
	strDiv +='			    </table></td>';
	strDiv +='			  </tr>';
	//
	// Calculate the branding text and save it, so that we can in the future control it separately from
	// the broker reciprocity logo.
	//
	var officeAgentArray = [];
	if(display_office_name) { officeAgentArray.push(office_name) }
	if(display_agent_name) { officeAgentArray.push(agent_name) }
	var officeAgentText = officeAgentArray.join('-');
	//
	if(officeAgentText != "") {
		var officeAgentSpan = '<span ' + brandingCss + ' id="hdOffice">'+ officeAgentText + '</span>';
	} else {
		var officeAgentSpan = '';
	}
	if (showOfficePhone && officePhone != '') {
		var officePhoneSpan = '<span ' + brandingCss + ' id="hdOffice">'+ officePhone +'</span>';;
	} else {
		var officePhoneSpan = '';
	}
	//
	var brandingSpans = [ officeAgentSpan, officePhoneSpan].join('<br>');
	//
	// Show the broker reciprocity logo along with the branding.
	//
	strDiv += '<tr>';
	strDiv += '<td colspan=3 align="left">';
	if(showBrokerRec) {
		var logoFileName = 'br_logo_' + market_name.toLowerCase() + logoExt;
		strDiv +=
			'<IMG SRC="http://www.mlsfinder.com/mlsfinderart/'
			+
			logoFileName
			+
			'" BORDER="0" ALT="Broker Reciprocity" hspace="0" vspace="0" style="vertical-align: middle">';
	}
	strDiv += brandingSpans;
	strDiv += '</td>'
	strDiv += '</tr>';
	//
	// Show the appropriate open house logos.
	//
	if (ohCount > 1){
		strDiv +='			  <tr>';
		strDiv +='			    <td colspan="3" align="center" class="detLinkText"><img src="http://www.mlsfinder.com/mlsfinderart/mq5/ho_oh_icon.gif" width="13" height="13" hspace="3" vspace="1" align="absbottom">Open House: Multiple Dates and Times</td>';
		strDiv +='			  </tr>';
	}
	if (ohCount == 1){
		strDiv +='			  <tr>';
		strDiv +='			    <td colspan="3" align="center" class="detLinkText"><img src="http://www.mlsfinder.com/mlsfinderart/mq5/ho_oh_icon.gif" width="13" height="13" hspace="3" vspace="1" align="absbottom">Open House: '+ ohDetail +'</td>';
		strDiv +='			  </tr>';
	}
	strDiv +='			  <tr>';
	strDiv +='			    <td colspan="3" align="center" class="detLinkText">&gt;&gt;&nbsp;click for more info&nbsp;&lt;&lt;</td>';
	strDiv +='			  </tr>';
	strDiv +='			</table>';
	strDiv +='		</DIV>';
	
	return strDiv;
}
// basic list function
function listAppend(thelist, newval, delim){
	if (newval == ""){
		newval = " ";
	}
	if (! delim){
		delim = ",";
	}

	if (thelist == ""){
		newstring = newval;
	}else{
		newstring = thelist + delim + newval;
	}
	return newstring;
}

// determine where to draw the house over (away from the edges)
function whatQ(w,h,x,y){
	qx = 0;
	if (x > (w/3)){qx = 1};
	if (x > ((w/3)*2)){qx = 2};
	if (y > (h/2)){qx = (qx + 3)};
	return(qx);
}

// split the property id for photoserver paths
function splitPID(pid){
	pid += "";
	splid = new String;
	for(x=0;x < pid.length; x++){
		splid = splid + pid.substr(x,1) + '/';
	}
	return(splid);
}

// format currency
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num);
}
