$(document).ready(function () {

  myPano = new GStreetviewPanorama(document.getElementById("pano"));
  GEvent.addListener(myPano, "error", handleError);

  $(".streetView").live("click", function() {

    $('#street_view_dialog').dialog('option', 'height', 500);
    $('#pano').show();
    $('#street_view_error').hide();

    street_latlng = $(this).attr('rel');
    street_lat = street_latlng.split('_')[0];
    street_lng = street_latlng.split('_')[1];
    street_title = $(this).attr('title');
    street_loc = new GLatLng(street_lat, street_lng);
    myPano.setLocationAndPOV(street_loc);
 
    $("#street_view_dialog").dialog({
      autoOpen: false,
      bgiframe: true,
      width:580,
      height:500,
      open: function() {
        $(this).dialog('option', 'title', street_title);
      },
      buttons: {
        'Close': function() {
          $(this).dialog('close');
        }
      },
      close: function() { myPano.remove();} 
    });

    $('#street_view_dialog').dialog('open');
    return false;
  });
});



function handleError(errorCode) {
  if (errorCode == 600) {
    var errorMsg = "<strong>Not Available</strong> Street View not available in this location.";
  }

  if (errorCode == 603) {
    var errorMsg = "The flash player is requires to view Google street view images.";
  }
  $('#street_view_dialog').dialog('option', 'height', 150);
  $('#pano').hide();
  $('#street_view_error_message').html(errorMsg);
  $('#street_view_error').show();

  return;
}

