$(document).ready(function () {
	$("#listingDetails > ul").tabs();
});

var map;
var directions;

function locationInitialize(strId,strName,strAddress)
{
	if (google.maps.BrowserIsCompatible()) 
	{
		if(directions)
			directions.clear();
		
		map = new google.maps.Map2(document.getElementById(strId));
		var geocoder = new google.maps.ClientGeocoder();
		
		geocoder.getLatLng(strAddress, function(point)
		{
			if (point) 
			{
				map.setCenter(point, 15);
				map.setUIToDefault();
				
				geocoder.getLocations(strAddress, function(response)
				{
					if (!response || response.Status.code != 200) 
					{
						alert("\"" + strAddress + "\" not found");
					}
					else 
					{
						var place = response.Placemark[0];
						var marker = new GMarker(point);
						map.addOverlay(marker);
						marker.openInfoWindowHtml("<p><strong>"+strName+"</strong></p><p>"+place.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName+"<br />"+place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName+" "+place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName+"</p>");
						google.maps.Event.addListener(marker,"click",function()
						{
							marker.openInfoWindowHtml("<p><strong>" + strName + "</strong></p><p>" + place.AddressDetails.Country.AdministrativeArea.Locality.Thoroughfare.ThoroughfareName + "<br />" + place.AddressDetails.Country.AdministrativeArea.Locality.LocalityName + " " + place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName + "</p>")
						});
					}
				});
			}
		});
		
		if (window.onunload = null) 
			window.onunload = google.maps.Unload();
	}
	else 
	{
		if (document.getElementById(strId)) 
			document.getElementById(strId).innerHTML = "Sorry, Google Maps cannot be displayed on your browser.";
	}
}

function locationGetDirections(strId,strFrom,strTo)
{
	if (google.maps.BrowserIsCompatible()) 
	{
		if(directions)
			directions.clear();
		
		directions=new google.maps.Directions(map,document.getElementById(strId));
		directions.load("from:"+strFrom+" to: "+strTo);
	}
	return false;
}
