function FeatureToolTip(divElement)
{
	var self = this;
	
	this.divElement = divElement;
	this.x;
	this.y;
	this.isFeatureToolTipRunning = false;
	this.isFeatureToolTipDisplaying = false;
	this.featureToolTipInterval;
	this.currentDateTime;
	this.lastMoveDateTime;
	this.XmlReqFeatureToolTip;
	
	this.showFeatureToolTip = showFeatureToolTip;
	this.processShowFeatureToolTip = processShowFeatureToolTip;
	this.updateFeatureToolTipStatus = updateFeatureToolTipStatus;
	this.hideToolTip = hideToolTip;
	this.showToolTip = showToolTip;

	function showFeatureToolTip()
	{
		if( self.isFeatureToolTipRunning && !self.isFeatureToolTipDisplaying && (self.lastMoveDateTime == self.currentDateTime) && mapLoaded )
		{
			if( self.x != null && self.y != null )
			{
				//alert("x: " + self.x + "\ny: " + self.y);
				var obj = document.getElementById(divElement);
				var x = self.x + 330;
				var y = self.y + 200;
				// figure out where to show the div
				// find left/right, then find up/down
				var isRight = true;
				var isDown = true;
				
				if( (parseInt(x) + parseInt(obj.style.width)) > parseInt(divMap.style.width) )
					isRight = false;
				
				if( (parseInt(y) + parseInt(obj.style.height)) > parseInt(divMap.style.height) )
					isDown = false;
				
				if( isRight )
					obj.style.right = parseInt(x);
				else if( !isRight )
					obj.style.left = parseInt(x) - parseInt(obj.style.width);
					
				if( isDown )
					obj.style.top = parseInt(y) + 75 + 60;
				else if( !isDown )
					obj.style.top = parseInt(y) - 75;
					
				// display feature tool tip div
				self.showToolTip();
				
				// find active layer
				var layerId;
				
				for( var i = 0; i < layerArray.length; i++ )
				{
					if( layerArray[i].LayerPosition == map.ActiveLayer )
					{
						layerId = layerArray[i].Name;
						break;
					}
				}
				
				// go get some data
				arrPt = map.toMapPoint(self.x, self.y);
				url = server + "FeatureService.asmx/GetFeatureToolTip?x=" + arrPt[0] + "&y=" + arrPt[1] + "&layerId=" + layerId + "&userGroupName=" + user.userGroupName;
				
				self.XmlReqFeatureToolTip = new TXmlHttp();
				
				if(self.XmlReqFeatureToolTip)
				{
					self.XmlReqFeatureToolTip.onreadystatechange = processShowFeatureToolTip;
					self.XmlReqFeatureToolTip.open("GET", url, true); //async call
					self.XmlReqFeatureToolTip.send(null);
				}
			}
		}
		else
		{
			self.currentDateTime = self.lastMoveDateTime;
		}
	}
	
	function processShowFeatureToolTip()
	{
		if(self.XmlReqFeatureToolTip.readyState == 4)
		{
			if(self.XmlReqFeatureToolTip.status == 200)
			{
				var response = self.XmlReqFeatureToolTip.responseXML.documentElement;				
				var features = response.getElementsByTagName('FEATURES');
				var className = "";
				var html = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\">";
				
				// get request specific top level values (layer, layerHyperlink, response feature count, hasMore features)
				var layer = features[0].attributes.getNamedItem('layer').value;
				var count = features[0].attributes.getNamedItem('count').value;
				
				if( count == '0' )
				{
					html += "<tr class=\"fieldPrimary\"><td>No Features Found</td></tr>";
				}
				else
				{
					// looks at FEATURES elements
					for( var i = 0; i < features.length; i++ )
					{
						// looks at FEATURE elements
						for( var x = 0; x < features[i].childNodes.length; x++ )
						{
							if( features[i].childNodes[x].nodeName == 'FEATURE' )
							{
								// get feature specific top level values (uniqueName, uniqueValue, primaryDisplay)
								var uniqueName = features[i].childNodes[x].attributes.getNamedItem('uniquename').value;
								var uniqueValue = features[i].childNodes[x].attributes.getNamedItem('uniquevalue').value;
								var pdisplay = features[i].childNodes[x].attributes.getNamedItem('pdisplay').value;
								
								// setup primary display field in HTML
								html += "<tr class=\"fieldPrimary\"><td colspan=\"2\">" + layer + "</td></tr>";
								
								// looks at FIELDGROUP elements
								// ** start at y = 1 because 0 index would be the ENVELOPE tag already discovered above
								for( var y = 1; y < features[i].childNodes[x].childNodes.length; y++ )
								{
									if( features[i].childNodes[x].childNodes[y].nodeName == 'FIELDGROUP' )
									{
										// looks at FIELD elements
										for( var z = 0; z < features[i].childNodes[x].childNodes[y].childNodes.length; z++ )
										{
											if( features[i].childNodes[x].childNodes[y].childNodes[z].nodeName == 'FIELD' )
											{
												var fieldAlias = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('alias').value;
												var fieldValue = features[i].childNodes[x].childNodes[y].childNodes[z].attributes.getNamedItem('value').value;
												
												// add each field to the HTML
												html += "<tr><td style=\"font-family: Arial; font-size: 8pt\"><b>" + fieldAlias + "</b></td>";
												
												// add field value
												if( fieldValue != null )
													html += "<td style=\"font-family: Arial; font-size: 8pt\">" + fieldValue + "</td></tr>";
												else
													html += "<td></td></tr>";
											}
										}
									}
								}
							}
						}
					}
				}
				
				html += "</table>";
				document.getElementById(divElement).innerHTML = html;
			}
		}
	}
	
	function updateFeatureToolTipStatus()
	{
		// check for chk status (chkFeatureToolTip)
		var chkFeatureToolTip = document.getElementById("chkFeatureToolTip");
		
		if( chkFeatureToolTip.checked )
			self.isFeatureToolTipRunning = true;
		else
			self.isFeatureToolTipRunning = false;
	}
	
	function hideToolTip()
	{
		document.getElementById(divElement).style.display = 'none';
		document.getElementById(divElement).style.zIndex = '0';
		self.isFeatureToolTipDisplaying = false;
	}
	
	function showToolTip()
	{
		// display div with "Loading..." message
		document.getElementById(divElement).innerHTML = "<table width=\"100%\" cellspacing=\"0\" cellpadding=\"2\"><tr class=\"fieldPrimary\"><td>Loading...</td></tr></table>";
			
		document.getElementById(divElement).style.display = 'block';
		document.getElementById(divElement).style.zIndex = '99';
		self.isFeatureToolTipDisplaying = true;
	}
}