    var map = null;
    var geocoder = null;
	var textoMapa = new Array() ;
	var direccionMapa = new Array() ;
	var localidadMapa = new Array() ;

var streetClient = new GStreetviewClient();
var streetBlock = null;
var panorama = new Array();
var currentYaw = new Array();
var currentPitch = new Array();
var timer = new Array();
var hasStreetView = new Array();

    function vermapa(n) {
      if (GBrowserIsCompatible()) {	
	document.getElementById("mapBlock_"+n).style.display="" ;
        map = new GMap2(document.getElementById("mapa_"+n));
	streetblock = "streetview_" + n;
        map.addControl(new GLargeMapControl());
        geocoder = new GClientGeocoder();
		texto = "<div style=\"font: normal 11px Arial; padding-top:6px\">"+textoMapa[n]+"</div>";
		showAddress(n, direccionMapa[n],localidadMapa[n],texto);
      }
    }

	function situarmapa(n, x, y) {
	if (GBrowserIsCompatible()) {
		document.getElementById("mapBlock_"+n).style.display="" ;
        map = new GMap2(document.getElementById("mapa_"+n));
        streetblock = "streetview_" + n;
        map.addControl(new GLargeMapControl());
		point  = new GLatLng(x, y) ;
		map.setCenter(point, 16);
		marker = new GMarker(point);
        map.addOverlay(marker);
		texto = "<div style=\"font: normal 11px Arial; padding-top:6px\">"+textoMapa[n]+"</div>";
		marker.openInfoWindowHtml(texto);
	
	point  = new GLatLng(x, y) ;			
	streetClient.getNearestPanorama(point, OnGetNearStreetResponse);
      }
	}

    function showAddress(n, address, localidad, texto) {
      if (geocoder) {
        geocoder.getLatLng(
          address+" "+localidad,
          function(point) {
			rdigito = /[0-9]/ ;
            if (!point) {
				if (address!="") {
					if (address.search(/[0-9]/) < 0)
						if (address.indexOf(" ")<0) {
							showAddress("", localidad, texto) ;
						}
						else {
							showAddress(address.substr(address.indexOf(" ")+1, address.length), localidad, texto) ;
						}
					else
						showAddress(address.substr(0, address.lastIndexOf(" ")), localidad, texto) ;
				}
				else {
					  map.setCenter(point, 16);
					  var marker = new GMarker(point);
					  map.addOverlay(marker);
					  marker.openInfoWindowHtml(texto);
							  		
					  streetClient.getNearestPanorama(point, OnGetNearStreetResponse);
				}
            } 
			else {
				if (address=="") {
					map.setCenter(point, 14);
				}
				else {
					map.setCenter(point, 16);
				}
				var marker = new GMarker(point);
				map.addOverlay(marker);
				marker.openInfoWindowHtml(texto);
						
				streetClient.getNearestPanorama(point, OnGetNearStreetResponse);
            }
          }
        );
      }
    }

function OnGetNearStreetResponse(response){
	if (response.code == 200){
		hasStreetView[streetblock] = true;
		$("#block_" + streetblock).show();
		var latlng = new GLatLng(response.Location.lat, response.Location.lng);
		
		panoramaOptions = { latlng:latlng, pov:0};
		panorama[streetblock] = new GStreetviewPanorama(document.getElementById(streetblock), panoramaOptions);

		// Rotacion individual
		//startRotating(streetblock);
	}else{
	    $("#block_" + streetblock).css("width", "1%").hide();
	    window.setTimeout("map.checkResize()", 5);
	}
}

function spiral() {
  if(!currentYaw[streetblock]) currentYaw[streetblock] = 0;

  if (currentYaw[streetblock] > 360){    
    currentYaw[streetblock] = 0;
  } else {    
    gpovData = panorama[streetblock].getPOV();    
    if(gpovData.pitch == 5 || !gpovData.pitch){
      currentYaw[streetblock] += 0.25;	
      panorama[streetblock].panTo({yaw:currentYaw[streetblock], pitch:0});
    }else{      
      stopRotating();
    }
  }
}

function stopRotating(streetblock) {

if (timer[streetblock]){
 clearInterval(timer[streetblock]);
 timer[streetblock] = false;
 }
} 

function startRotating(streetblock) {
 if (hasStreetView[streetblock]){
  timer[streetblock] = window.setInterval(spiral, 5);
 }
} 

