// Constructor for propertyRecord class:
//
function propertyRecord( latitude, longitude, psZoom, psName, town, psHtml, psPlace ) {

	var theIcon;
	var xOffset, yOffset;
	var theTitle;
	var theLabelText;

	gMarkerCount++;
	
	theTitle = getTitle(latitude, longitude, psZoom, psName, town, psHtml, psPlace);

	theLabelText = getLabelText(latitude, longitude, psZoom, psName, town, psHtml, psPlace);
				
	theIcon = new GIcon(G_DEFAULT_ICON, kMarkerOffURL);
	theIcon.printImage = kMarkerPrintURL;
	theIcon.mozPrintImage = kMarkerMozPrintURL;
	
	theIcon.shadow = "";
	theIcon.printShadow = "";

	if ( gMarkerCount < 10 ) {

		xOffset = -2;
		yOffset = -31;
		
	} else {
	
		xOffset = -6;
		yOffset = -31;	
	}

	this.theMarker = new LabeledMarker(new GLatLng(latitude, longitude), {icon: theIcon, title: theTitle, labelText: theLabelText, labelOffset: new GSize(xOffset, yOffset)});

	this.thePSlat = latitude;
	this.thePSlon = longitude;
	this.thePSzoom = psZoom;
	this.thepsName = psName;
	this.theTown = town;
	this.thepsHtml = psHtml;
	this.thepsPlace = psPlace;
	this.markerID = gMarkerCount;
	
	return this;
}


// Add markers (and listeners) to a map.
//
function addMarkers( theMap ) {

	var i;
	var marker;
	
	theMap.clearOverlays();
	
	applyFilters();
		
	for ( i = 1; i <= kProStaffCount; i++ ) {
	
			marker = psData[i].theMarker;

			GEvent.addListener( marker, "mouseover", function() {				
				var i;
				
				this.setImage(kMarkerOnURL);
				
				for ( i = 1; i <= kProStaffCount; i++ ) {

					if ( this == psData[i].theMarker ) {
					
						document.getElementById("list" + psData[i].markerID).style.backgroundColor=kListOnColor;
						break;
					}
				}
			} );
		
			GEvent.addListener( marker, "mouseout", function() {				
				var i;
				
				this.setImage(kMarkerOffURL);
				
				for ( i = 1; i <= kProStaffCount; i++ ) {

					if ( this == psData[i].theMarker ) {
					
						document.getElementById("list" + psData[i].markerID).style.backgroundColor=kListOffColor;
						break;
					}
				}
			} );
		
			GEvent.addListener( marker, "click", function() {
				var i;
				var theLoc;
				var currentZoom;
														
				for ( i = 1; i <= kProStaffCount; i++ ) {
				
					if ( this == psData[i].theMarker ) {

						currentLat = psData[i].thePSlat;
						currentLon = psData[i].thePSlon;
						currentZoom = psData[i].thePSzoom;
												
						gMap.setZoom(Math.abs(currentZoom));
						
						gMap.panTo(new GLatLng(currentLat, currentLon));
						
						refToInfoBox = getRefToDiv('infobox');
						
						refToInfoBox.innerHTML = psData[i].thepsHtml;
						
						break;
					}
				}
			} );
			
			theMap.addOverlay(marker);
	}
	showFoundSetList();	
}


// Add listener for maptypechanged event.
//
function addMapTypeChangedListener(theMap) {

	GEvent.addListener( theMap, "maptypechanged", function() { } );
}


// Show the property in the map
//
function showPropertyInMap( i ) {

	GEvent.trigger(psData[i].theMarker, "click");
	window.location = "#" + kMapAnchorID;
}


// Show selected items.
//
function showFoundSetList() {
	
	var i;
	var h, r;
	var iString;

	
	r = "";

	for ( i = 1; i <= kProStaffCount; i++ ) {
	
			if ( i < 10 ) {
			
				iString = "&nbsp;" + i + "&nbsp;";	
				
			} else {
			
				iString = "" + i + "";
			}

			r += "<tr>";
			
			r += "<td align=center valign=top>" + "<a href='#' onclick='showPropertyInMap(" + i + "); return false;' onmouseover='GEvent.trigger(psData[" + i + "].theMarker, \"mouseover\"); return false;' onmouseout='GEvent.trigger(psData[" + i + "].theMarker, \"mouseout\"); return false;' class=numbers>" + iString + "</a>" + "</td>";
			
			r += "<td valign=top id='list" + i + "' style='font-size: 9pt; background-color: " + kListOffColor + ";''><span><a href='#' onclick='showPropertyInMap(" + i + "); return false;' onmouseover='GEvent.trigger(psData[" + i + "].theMarker, \"mouseover\"); return false;' onmouseout='GEvent.trigger(psData[" + i + "].theMarker, \"mouseout\"); return false;'><b>" + psData[i].thepsName + "</b></a></span>";
			
			r += "<br>";
			r += psData[i].thepsPlace;
			r += "</td>";
			
			r += "</tr>";

	}
	
	h  = "";	
	h += "<table>";
	h += "<tr align=center><td colspan=2>";
	h += "<b>";
	h += kListTitle;
	h += "</b>";
	h += "</td></tr>";
	h += r;
	h += "</table>";
		
	document.getElementById(kHotID).innerHTML = h;


}


// Filter out unwanted markers.

function applyFilters() {

	var i;
	
	for ( i = 1; i <= kProStaffCount; i++ ) {

		psData[i].inFoundSet = true;	// Assume it's a keeper
	}
}

// This returns the tool tip to be used.
//
function getTitle(latitude, longitude, psZoom, psName, town, psHtml, psPlace) {

	return psName;
}

// This returns the text to be shown inside the marker.
//
function getLabelText(latitude, longitude, psZoom, psName, town, psHtml, psPlace) {

	return gMarkerCount;
}

