//<![CDATA[
	
var baseIcon = new GIcon();
baseIcon.iconSize = new GSize(24, 30);
baseIcon.shadowSize = new GSize(35, 20);
baseIcon.iconAnchor = new GPoint(11, 20);
baseIcon.infoWindowAnchor = new GPoint(11, 20);
baseIcon.infoShadowAnchor = new GPoint(11, 20);
//baseIcon.shadow = "/images/gm_icons/google_shadow.png";

function createMarker(ixii, point, html_text, status) {
	if(status == 'ALL') {						
		baseIcon.image = "/images/gm_icons/google_all.png";
	}
	if(status == 'Sat') {						
		baseIcon.image = "/images/gm_icons/google_sat.png";
	}
	if(status == 'Sun') {
		baseIcon.image = "/images/gm_icons/google_sun.png";
	}
	if(status == 'Mon') {
		baseIcon.image = "/images/gm_icons/google_mon.png";
	}
	if(status == 'Tue') {
		baseIcon.image = "/images/gm_icons/google_tue.png";
	}
	if(status == 'Wed') {
		baseIcon.image = "/images/gm_icons/google_wed.png";
	}
	if(status == 'Thu') {
		baseIcon.image = "/images/gm_icons/google_thu.png";
	}
	if(status == 'Fri') {
		baseIcon.image = "/images/gm_icons/google_fri.png";
	}

	var icon = new GIcon(baseIcon);		
	var marker = new GMarker(point, icon);	
	GEvent.addListener(marker, "mouseover", function() {
				marker.openInfoWindowHtml(html_text);
	});	
	return marker;
}

function getPopupHtml(ixii, img_src, beds, address, price, baths, relocation_string) {
	var html = 	'<table width="220px" border="0"  cellpadding="2" cellspacing="0">' +
					'<tbody align="center">' +
						'<tr>' +
							'<td align="left"><img src="' + img_src + '" alt="" width="100" height="75" \/><\/td>' +
							'<td align="right">' +	price + '<br \/>' +	beds + '<br \/>' + baths + '<\/td>' +
						'<\/tr>' +
						'<tr>' +						
							'<td colspan="2" align="center">' +
							'<b><nobr>' +
								address	+				
							'<\/nobr><\/b>' +
							'<\/td>' +						
						'<\/tr>' +	
						'<tr>' +						
							'<td colspan="2" align="center">' +
							'<a href="' + relocation_string + '" ><b><nobr>' +
								'More Pictures and Full Listing' +
							'<\/nobr><\/b><\/a>' +
							'<\/td>' +
						'<\/tr>' +
					'<\/tbody>' +
				'<\/table>';
	return html;
}

var ixii = 0;
var first_time = 1;
var counter = 0;
function addMarkers() {
	if ( ixii < num_props ) {
		var max=Math.min(ixii+5, num_props);
		// Add properties
		while ( ixii < max) {
		//0: listingsdb_id, 1:lon, 2:lat, 3:beds, 4:baths, 5:price, 6:image_url, 7:sq_feet, 8:address 9:price_number 10:Open House Date
		var img_src = '';
		//image source for popup
		if (props[ixii][6].length>0){
			img_src = props[ixii][6];
		} 
		else {
			img_src = "/images/nophoto.gif";
		}
		//beds
		var beds = "";
		var baths = "";
		if(props[ixii][3] == 1)
			beds = props[ixii][3] + " bed";
		else
			beds = props[ixii][3] + " beds";
		if(props[ixii][3] == '')
			beds = '';
		if (props[ixii][4] == 1) {
			baths = props[ixii][4] + " bath";
		}
		else {
			baths = props[ixii][4] + " baths";
		}
		if(props[ixii][4] == '')
			baths = '';
		//address 
		var address = props[ixii][8];
		//price
		var price = props[ixii][5];
		if(props[ixii][5] == '$0')
			price = '';
		//preload all popup images so they load fast/correctly
		//problems with firefox if this is not done
		arImages[ixii] = new Image();
		arImages[ixii].src = img_src;
		var prop_id = props[ixii][0];	
		var relocation_string = "/index.php?action=listingview&amp;listingID=" + prop_id + "&PageID=97";
		//get different text for houses/condos, land, and commercial
		var html_text = "";
		html_text = getPopupHtml(ixii, img_src, beds, address, price, baths, relocation_string);
		map.addOverlay(createMarker(ixii, new GLatLng(props[ixii][1], props[ixii][2]), html_text, props[ixii][10]), ixii);	
		var currentNum = ixii + 1;
		counter++;
		ixii++;
		}//add all the properties that satisfy the tests
		//recursive call with delay
		window.setTimeout(addMarkers,150);
	}//if ixii < num_props
	else {
		ixii = 0;	
		first_time = 0;
		counter = 0;
	}
}//function addMarkers

function pois() {
	var request = GXmlHttp.create();
	request.open("GET", "poi_markers.xml", true);
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			var xmlDoc = GXml.parse(request.responseText);
			var markers = xmlDoc.documentElement.getElementsByTagName("marker");
			for (var ijj = 0; ijj < markers.length; ijj++) {
				var lat = parseFloat(markers[ijj].getAttribute("lat"));
				var lng = parseFloat(markers[ijj].getAttribute("lng"));
				var point = new GLatLng(lat,lng);
				var html = markers[ijj].getAttribute("desc");
				var label = markers[ijj].getAttribute("name");
//				var marker = createMarker(ijj, point, html, label, "ALL");
//				map.addOverlay(marker);
			}
		}
	}
}

function createMap(){
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
    map.setCenter(centrePoint, 15);
	addMarkers();
	pois();
}//end function createMap()

function loader(){
	createMap();
}
function unloader(){
	GUnload();	
}

window.onload = loader;
window.onunload = unloader;

//]]>