
function getElementById(id) {
	if (document.all) {
		return document.all[id];
	
	} else if (document.layers) {
		return document.layers[id];
	
	} else if (document.getElementById) {
		return document.getElementById(id);
		
	}
}

function unloadMaps() {
	GUnload();
}

// EXPAND AND MINIMIZE MAP
var first = true;
function expandMap() {
	if (first) {
		getElementById("propertyMapWide").style.display = "block";
		getElementById("propertyMapWide").style.width = "624px";
		getElementById("propertyMapWide").style.height = "300px";
		loadPropertyMap("propertyMapWide");
		first = false;
	} else {
		getElementById("propertyMapWide").style.display = "block";
	}
	
	getElementById("expandLink").href = "javascript: minimizeMap()";
	getElementById("expandLink").innerHTML = "Minimize Map";		
}


function minimizeMap() {
	getElementById("propertyMapWide").style.display = "none";
	getElementById("expandLink").href = "javascript: expandMap()";
	getElementById("expandLink").innerHTML = "Expand Map";
}

function unHighlight (lstElm) {
	if (lstElm) {
		lstElm.style.background = '#FFFFFF'
	}
}

var goBackElm = false;
var t;
var firstHL = true;
var lastElm;

function seeInList (propElm) {
	if (firstHL) {
		firstHL = false;
	} else {
		unHighlight (lastElm);
	}
	
	getElementById(propElm).style.background = "#99CCFF";	
	goBackElm = getElementById(propElm); 
	t = 0;
	t = setTimeout("unHighlight(goBackElm)", 5000);
	
	lastElm = goBackElm;
}

// POINTS AND MARKERS

function createMarker(point,html, icon, propId) { 
	var marker = new GMarker(point, icon);
	
	if (propId != '' && propId != undefined) {
		var propElm = 'prop_' + propId;
		html += "<br><a href=\"javascript:seeInList('" + propElm + "')\">Click to highlight property in list</a>"; 
		
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml(html);
		});
		
		// The new marker "mouseover" listener        
		GEvent.addListener(marker,"mouseover", function() {
			marker.openInfoWindowHtml(html);									
		});  
		
/*		GEvent.addListener(marker, "mouseout", function() {
			getElementById(propElm).style.background = "#ffffff";
		});
*/		
	}      
	
	return marker;
}

function createMarkerFromLongLat(icon, lon, lat, html, propId) {
	var point = new GPoint(lon,lat);
	var marker = createMarker(point,html, icon, propId);
	
	return marker;
}

function createMarkeFromPoint(icon, point) {
	var marker = new GMarker(point, icon);
	
	return marker;
}

function createMarkerFromAddress(icon, address, map, html, propId) {
	var geocoder = new GClientGeocoder();

	geocoder.getLatLng(
	    address,
	    function(point) {
	      if (!point) {
	        // do nothing
	      } else {
	      	var marker = createMarker(point,html, icon, propId);      
	        map.addOverlay(marker);
	      }
	    }
	  );
}

function createCenterFromAddress (address, map) {
	var geocoder = new GClientGeocoder();
	
	geocoder.getLatLng(
		address,
		function (point) {
			if (!point) {
			 	document.getElementById('googleMap').style.display = 'none';
			} else {
				map.setCenter(point, 10);
			} 
		}
	);	

}

// LOAD MAP
function loadFirstMap (loadMap) {
		loadPropertyMap('propertyMap');
}