// show/hide do mapa
mapaz=0;
var mapDiv;
var map = null;
//var LH1=39.399872;
//var LH2=-8.224454;
//var LHZ = 5;
var nome2 = '';
var angulo2 = null;
var botao2 = null;
var myPano = null;
var point;

function showMapa(){
	//mapDiv = document.getElementById("Gmap");
	//mapDiv.style.display = 'block';
	$("#Gmap").show();
	$("#mapON").hide("slow");
	if(myPano != null){
		//resizeMapas();
	}
	//if (map === null) {
		mountMap();
	//} 
}
function hideMapa(){
	//mapDiv.style.display = 'none';
	$("#Gmap").hide("slow");
	$("#mapON").show("slow");
	return true;
}

// criação do mapa
function mountMap() {
	  if (GBrowserIsCompatible()) {
		var map = new GMap2(document.getElementById("map"));
		map.setCenter(new GLatLng(LH1, LH2), LHZ);
		map.setUIToDefault();
		point = new GLatLng(LH1, LH2)
		var marker = new GMarker(point);
		GEvent.addListener(marker, "click", function() {
			marker.openInfoWindowHtml("<div style='width:150px'>"+nome2+"</div>");
		});
		map.addOverlay(marker);
		if($("#pano object:first").height()>200){
			$("#map").width(600);
		}
		// alert ($("#pano object:first").height());
	}
}
function mountStreet(L1,L2,angulo,nome) {
	if (!L1 ){
			L1=LH1;L2=LH2;LZ=LHZ;nome='Portugal';
		} else {
			LZ=13;
		}
	nome2 = nome;
	LH1=L1;LH2=L2;LHZ=LZ;// memoriza a posição
	angulo2 = angulo;
	  if (GBrowserIsCompatible()) {
		//var myPano;
		  var cordenadas = new GLatLng(LH1,LH2);
		  panoramaOptions = { latlng:cordenadas };
		  myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);
		  myPOV = {yaw:angulo2,pitch:-20};
		  myPano.setLocationAndPOV(cordenadas, myPOV)
	  	  GEvent.addListener(myPano, "error", handleNoFlash);
		  GEvent.addListener(myPano, "initialized", resizeMapas);
	      botao2 = $("#mapON").html();
		$("#mapON").html(botao2 + " / Street View");


	}
		function handleNoFlash(errorCode) {
		  //document.getElementById("map").style.width="100%";
		 // alert(errorCode);
		  $("#mapON").html(botao2);
		  if (errorCode == 'FLASH_UNAVAILABLE') {
			alert("Error: Flash doesn't appear to be supported by your browser");
			return;
		  }
		  if (errorCode == 600) {
			//$("#pano").html("Street View Not Available For This Location");
			return;
			}
		} 
}
function resizeMapas(){
				document.getElementById("map").style.width="600px";
		  		$("#mapON").html(botao2 + " / Street View");
	
	}
function inicio() {
		mapDiv = document.getElementById("map");
	}
