//<![CDATA[

var geocoder;
var map;
var myPano;


// error codes 
var NO_NEARBY_PANO = 600;       // No panorama data was found
var FLASH_UNAVAILABLE = 603;    // Flash unavailable 

   // On page load, call this function

   function load()
   {
   // Create new geocoding object
      geocoder = new GClientGeocoder();

      // Retrieve location information, pass it to addToMap()
      geocoder.getLocations(address, addToMap);

   }

   // This function adds the point to the map

   function addToMap(response)
   {
      // Retrieve the object
      place = response.Placemark[0];

      // Retrieve the latitude and longitude
      point = new GLatLng(place.Point.coordinates[1],
                          place.Point.coordinates[0]);
   
// Load Pano

var NAME = point;
var NAMEPOV = {yaw:180,pitch:0};
   
   panoClient = new GStreetviewClient();      
   myPano = new GStreetviewPanorama(document.getElementById("pano"));
   myPano.setLocationAndPOV(NAME, NAMEPOV);
   GEvent.addListener(myPano, "error", handlePanoError); 
   panoClient.getNearestPanorama(NAME, showPanoData);

   }

function handlePanoError(errorCode) { 
      if (errorCode == FLASH_UNAVAILABLE) { 
        //alert("Error: Flash doesn't appear to be supported by your browser"); 
        document.getElementById("pano").innerHTML = "<br /><b>Error: Flash doesn't appear to be supported by your browser</b>"; 
        return; 
      } 
      else if (errorCode == NO_NEARBY_PANO ) { 


        document.getElementById("pano").innerHTML = "<br /><b>Street View is not available for this property</b>"; 
        return; 
      } 
    } 

    //]]>

function showPanoData(panoData) 
{
if (panoData.code != 200) {

//     GLog.write('showPanoData: Server rejected with code: ' + panoData.code);
//   return;
 }else{
   
  myPano.setLocationAndPOV(panoData.location.latlng);

}
}

function setPanorama( lat, lon ) 
{
    panoClient.getNearestPanorama(new GLatLng(lat, lon), showPanoData);
}
