var map = null;
var geocoder = null;
var baseIcon = null;
var zoom = 11;

function addAddress(latitude, longitude, date1, time1, date2, time2, address, city, desc, price, agent, office, myindex) {
	// Create a lettered icon for this point using our icon class	
	var point = new GLatLng(latitude,longitude);
	
	/*
	var iconOptions = {};

	iconOptions.primaryColor = "#990000";
	iconOptions.strokeColor = "#000000";
	iconOptions.label = "" + myindex + "";
	iconOptions.labelColor = "#FFFFFF";
	iconOptions.addStar = false;
	iconOptions.labelSize = 15;
	var newIcon = MapIconMaker.createLabeledMarkerIcon(iconOptions);
	*/
	
	baseIcon = new GIcon();
	baseIcon.image = "/images/markers/marker" + myindex + ".png";	
	baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
	baseIcon.iconSize = new GSize(20, 34);
	baseIcon.shadowSize = new GSize(37, 34);
	baseIcon.iconAnchor = new GPoint(9, 34);
	baseIcon.infoWindowAnchor = new GPoint(9, 2);

	
	var marker = new GMarker(point, {icon: baseIcon});
	map.addOverlay(marker);
	
	GEvent.addListener(marker, "click", function() {									 	
		showInfoWindow(latitude, longitude, date1, time1, date2, time2, address, city, desc, price, agent, office);
	});	
	
}

function showInfoWindow(latitude, longitude, date1, time1, date2, time2, address, city, desc, price, agent, office){
	var point = new GLatLng(latitude,longitude);
	var myHtml = "<div class=\"openHouseInfoWindow\">" + getDirectionsLink(address, city) + "<br /><br /><b>" + address + ", " + city + "</b><br/>" + desc + "<br>" + price + "<br /><br /><div class=\"openHouseInfoWindowDate\"><strong>Date:</strong> " + date1
	
	if(time1.length > 0){
		myHtml = myHtml + "<br /><strong>Time:</strong> " + time1 + "<br />";
	}
	
	if(date2.length > 0){
		myHtml = myHtml + "<br /><strong>Date:</strong> " + date2 + "<br />";
	}		
	if(time2.length > 0){
		myHtml = myHtml + "<strong>Time:</strong> " + time2 + "<br />";
	}	
	
	myHtml = myHtml + "</div></div>";
	map.openInfoWindowHtml(point, myHtml);
}

function getDirectionsLink(address, city){
	
	var url = "http://maps.google.com/maps?q=" + address + "+" + city + "&daddr=" + address + "+" + city;
	var str = '<a href="' + url + '" target="_blank" class="openHouseDirections externalLink">Directions to here</a>'
	return str;

}

function getCity(theField){
	window.location = "?c=" + theField.value;
}

function doMapScroll(){
	$.scrollTo("div#openHouseSearchOptions", 1000);
}