// show an  array or xml file of property markers
var map;
var bounds;
var baseIcon = new GIcon();
var mainIcon = new GIcon();

function load_map(arr)
{
	show_markers(arr);
}
function show_markers(arr)
{
		// Create the map
		// if arr is defined then arr.lat and arr.lng must exist

	zoom = 3;
	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	if (arr)
	{
		if (typeof(arr.zoom) != 'undefined')
			zoom = arr.zoom;
		map.setCenter(new GLatLng(arr.lat, arr.lng), zoom);
	}
	else
		map.setCenter(new GLatLng(27.74166457713348, -81.5), zoom);
	bounds = new GLatLngBounds();


		
		// Create the "tiny" marker base icon
	baseIcon.image = "http://labs.google.com/ridefinder/images/mm_20_red.png";
	baseIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	baseIcon.iconSize = new GSize(12, 20);
	baseIcon.shadowSize = new GSize(22, 20);
	baseIcon.iconAnchor = new GPoint(6, 20);
	baseIcon.infoWindowAnchor = new GPoint(5, 1);
		// Create the "tiny" major area  icon
	mainIcon.image = "http://labs.google.com/ridefinder/images/mm_20_blue.png";
	mainIcon.shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png";
	mainIcon.iconSize = new GSize(12, 20);
	mainIcon.shadowSize = new GSize(22, 20);
	mainIcon.iconAnchor = new GPoint(6, 20);
	mainIcon.infoWindowAnchor = new GPoint(5, 1);
}		
function set_bounds()
{
	//map.setCenter(mid_marker.getPoint());
	//point = map.getCenter();
	map.setCenter(bounds.getCenter());
//var	zoom;
	var zoom = map.getBoundsZoomLevel(bounds);
	if (zoom > 10) zoom = 10;
	if (zoom > 5)
		zoom = zoom -1;
	map.setZoom(zoom);
} 
function makemar(mar)
{
	var point = new GLatLng(mar.lat,mar.lng);
	var marker = createMarker(point,mar);
	map.addOverlay(marker,mar.caption);
	bounds.extend(point);
}
function createMarker(point,mar)
{
	if (mar.small == 'Y')
		var marker = new GMarker(point,{ icon:baseIcon, title:mar.caption });
	else
		var marker = new GMarker(point,{ icon:mainIcon, title:mar.caption });

	
	//  open the tabbed info window when clicking the sidebar links
	// A function to create a tabbed marker and setup the event window
	GEvent.addListener(marker, "click", function()
	{
		html = '<table width="220px" height="100px"><tr><td>' + mar.html + '</td></table>';
		marker.openInfoWindowHtml(html);
	});

	bounds.extend(point);
	return marker;
}
