function addFabMap(divID, latID, lngID, centerLat, centerLng, zoomLevel, propertyPoints)
{
        if (GBrowserIsCompatible())
        {
                // Instantiate the map, centre on coords and add a zoom control
                var map = new GMap2(document.getElementById(divID));
                var centerPoint = new GLatLng(centerLat, centerLng);
                map.setCenter(centerPoint, zoomLevel);

		window.mapControls = {};
		window.mapControls['largeC'] = new GLargeMapControl();
		window.mapControls['menuC'] = new GMenuMapTypeControl();

		map.addControl(window.mapControls['largeC']);
		map.addControl(window.mapControls['menuC']);

                // if we haven't centered on 0,0 place a marker on the map and update hidden inputs
                if (centerLat != 0 && centerLng != 0)
                {
                        var cityIcon = new GIcon();
                        cityIcon.iconAnchor = new GPoint(9, 25);
                        cityIcon.infoWindowAnchor = new GPoint(10, 2);
                        cityIcon.imageMap = [1,1, 1,18, 6,18, 6,21, 10,18, 20,18, 20,1, 1,1];
                        cityIcon.iconSize = new GSize(20, 26);
                        cityIcon.image = '/images/city-pin.png';

                        var marker = new GMarker(centerPoint, {icon: cityIcon, draggable: false});
                        map.addOverlay(marker);
                }

                // When the map is clicked, the map should center on the mouse point
                GEvent.addListener(map, 'click', function(marker, point)
                {
                        if (marker)
                        {
                                //map.removeOverlay(marker);
                                return;
                        }
                        else
                        {
                                window.setTimeout(function() {map.panTo(point);}, 500);
                        }
                });

		if (JSONcount > 0)
		{
			for (i=0; i<JSONcount; i++)
			{
				if (PropCoords.results[i].PropertyNumber == "EOF") { break; }

	                        var point = new GLatLng(PropCoords.results[i].Lat, PropCoords.results[i].Lon);

	                        var propIcon = new GIcon();
	                        propIcon.iconAnchor = new GPoint(9, 25);
                        	propIcon.infoWindowAnchor = new GPoint(10, 2);
                	        propIcon.imageMap = [1,1, 1,18, 6,18, 6,21, 10,18, 20,18, 20,1, 1,1];
        	                propIcon.iconSize = new GSize(20, 26);
	                        propIcon.image = '/images/property-pin.png';

	                        var propertyMarker = new GMarker(point, {"title": PropCoords.results[i].Name, "icon": propIcon});
	                        map.addOverlay(propertyMarker);
	                        GEvent.addListener(propertyMarker, "click", MochiKit.Base.partial(this.FabMapPropClick, propertyMarker, PropCoords.results[i].PropertyNumber)); 
			}
		}	

                return map;
        }
}

function FabMapPropClick(marker, PropertyNumber)
{
	if (JSONcount > 0)
	{
		for (i=0; i<JSONcount; i++)
		{
			if (PropCoords.results[i].PropertyNumber == "EOF") { break; }

			if (PropCoords.results[i].PropertyNumber == PropertyNumber) 
			{
				marker.openInfoWindowHtml(createMarkerContent(PropertyNumber));
				MochiKit.Signal.signal(this, "markerClicked", PropertyNumber);
			}
		}
	}
}

function createMarkerContent(PropertyNumber)
{
	var markerContent = "Error: Property undefined";
                
	if (JSONcount)
	{
		for (i=0; i<JSONcount; i++)
		{
			if (PropCoords.results[i].PropertyNumber == PropertyNumber)
			{
				ratingTxt = '';
				if(PropCoords.results[i].AvgRating > 0){
					ratingTxt = "<br/>Avg. Rating: " + PropCoords.results[i].AvgRating + "%";
				}

				if (PropCoords.results[i].Featured == "1")
				{
					markerContent = "	<div class='mapPopup'>\n";
					markerContent += "	 <table cellpadding='0' cellspacing='0' border='0'>\n";
					markerContent += "	  <tr valign='top'>\n";
					markerContent += "	   <td>\n";
					markerContent += "		<div class='imageCol'>\n";
					markerContent += "		  <div class='propImgSurroundMap'><img src='http://images.hostelworld.com" + PropCoords.results[i].Image + "' border='0' alt='' /></div>\n";
					markerContent += "		  <div class='mapPopupFromPriceFeat'>from<strong>" + PropCoords.results[i].Price + "</strong></div>\n";
					markerContent += "		 </div>\n";
					markerContent += "		</td>\n";
					markerContent += "		<td><span><a href='" + PropCoords.results[i].URL + "'>" + PropCoords.results[i].Name + "</a>" + PropCoords.results[i].Address + ", " + PropCoords.results[i].City + ", " + PropCoords.results[i].Country + ", Avg. Rating:" + PropCoords.results[i].AvgRating + "%</span>\n";
					markerContent += "		<div class='mapDesc'>" + PropCoords.results[i].Description + "</div>\n";
					markerContent += "		<div class='moreButton'><a href=\"" + PropCoords.results[i].URL + "\"><img src='/images/more_button.gif'></a></div>\n";
					markerContent += "		</td>\n";
					markerContent += "	   </tr>\n";
					markerContent += "	  </table>\n";
					markerContent += "	</div>\n";
				}
				else
				{
					markerContent = "	<div class='mapPopup'>\n";
					markerContent += "	 <table cellpadding='0' cellspacing='0' border='0'>\n";
					markerContent += "	  <tr valign='middle'>\n";
					markerContent += "	   <td>\n";
					markerContent += "	    <div class='imageCol'>\n";
					markerContent += "		  <div class='mapPopupFromPriceReg'>from<strong>" + PropCoords.results[i].Price + "</strong></div>\n";
					markerContent += "		 </div>\n";
					markerContent += "		</td>\n";
					markerContent += "		<td><span><a href='" + PropCoords.results[i].URL + "'>" + PropCoords.results[i].Name + "</a>" + PropCoords.results[i].Address + ",<br />" + PropCoords.results[i].City + ", " + PropCoords.results[i].Country + ratingTxt + "</span>\n";
					markerContent += "		<div class='moreButton'><a href=\"" + PropCoords.results[i].URL + "\"><img src='/images/more_button.gif'></a></div>\n";
					markerContent += "		</td>\n";
					markerContent += "	   </tr>\n";
					markerContent += "	  </table>\n";
					markerContent += "	</div>\n";
				}
                                       
				break;
			}
		}
	}

	return markerContent;
}

function addPlotMap(divID, latID, lngID, centerLat, centerLng, zoomLevel)
{
        if (GBrowserIsCompatible())
        {
                // Instantiate the map, centre on coords and add a zoom control
                var map = new GMap2(document.getElementById(divID));
                var centerPoint = new GLatLng(centerLat, centerLng);
                map.setCenter(centerPoint, zoomLevel);
                map.addControl(new GSmallZoomControl());

                // if we haven't centered on 0,0 place a marker on the map and update hidden inputs
                if (centerLat != 0 && centerLng != 0)
                {
			var propIcon = new GIcon();
			propIcon.iconAnchor = new GPoint(9, 25);
			propIcon.infoWindowAnchor = new GPoint(10, 2);
			propIcon.imageMap = [1,1, 1,18, 6,18, 6,21, 10,18, 20,18, 20,1, 1,1];
			propIcon.iconSize = new GSize(20, 26);
			propIcon.image = '/images/property-pin.png';

                        var marker = new GMarker(centerPoint, {icon: propIcon, draggable: false});
                        map.addOverlay(marker);
                }

                // When the map is clicked, the map should center on the mouse point
                GEvent.addListener(map, 'click', function(marker, point)
                {
                        if (marker)
                        {
                                //map.removeOverlay(marker);
                                return;
                        }
                        else
                        {
                                window.setTimeout(function() {map.panTo(point);}, 500);
                        }
                });

                return map;
        }
}

