var geocoder = null;
var mymypano=null;
var myaw = 0;
var mpith = 0;
var mzoompano = 0;
var arrowIcon = new GIcon();
      arrowIcon.iconSize = new GSize(24,24);
      arrowIcon.shadowSize = new GSize(1,1);
      arrowIcon.iconAnchor = new GPoint(12,12);
      arrowIcon.infoWindowAnchor = new GPoint(0,0);
      arrowIcon.image = "http://www.google.com/intl/en_ALL/mapfiles/dir_0.png";
	var iconpanoramio = new GIcon();
	iconpanoramio.image = "http://www.panoramio.com/img/panoramio-marker.png";
	iconpanoramio.shadow = "http://www.panoramio.com/img/panoramio-shadow.png";
	iconpanoramio.iconSize = new GSize(18, 18);
	iconpanoramio.shadowSize = new GSize(22, 22);
	iconpanoramio.iconAnchor = new GPoint(9, 9);
	iconpanoramio.infoWindowAnchor = new GPoint(9, 0);
	
	var iconmarca = new GIcon();
	iconmarca.image = "images/myicon.png";
	iconmarca.shadow = "";
	iconmarca.iconSize = new GSize(32, 32);
	iconmarca.shadowSize = new GSize(32, 32);
	iconmarca.iconAnchor = new GPoint(0,16);
	iconmarca.infoWindowAnchor = new GPoint(16, 0);
	
	
	var iconmarca2 = new GIcon();
	iconmarca2.image = "images/icon.png";
	iconmarca2.shadow = "";
	iconmarca2.iconSize = new GSize(32, 32);
	iconmarca2.shadowSize = new GSize(32, 32);
	iconmarca2.iconAnchor = new GPoint(-16,0);
	iconmarca2.infoWindowAnchor = new GPoint(16, 0);
	
	function showPanoData(panoData) {
	      if (panoData.code != 200) {
	        var haypano="no";
			
			return;	   		
	      }
		else
		  var haypano="yes";
			document.getElementById("panoramica").style.position='relative';
			document.getElementById("panoramica").style.display='block';
			return;	   		
			   
	    }
	
	function handleNoFlash(errorCode) {
	  /*if (errorCode == FLASH_UNAVAILABLE) {
	    alert("Error: Flash doesn't appear to be supported by your browser");
	    return;
	  }*/
	}
	function createMarker(input) {
		var icono=iconmarca2;
		if (iduser==input.iduser)
			icono=iconmarca;
			var marker = new GMarker(input.point,icono);
			GEvent.addListener(marker, "click", function() {
				marker.openInfoWindowHtml('<div class="globo"><h3>'+input.nameeng+'</h3>'+input.descriptioneng +'</div>');
			    myPOV = {yaw:input.jawxxx,pitch:input.pitch,zoom:input.zzoom};
			    mymypano.setLocationAndPOV(input.point, myPOV);
		});
	return marker;
	}
function addpano(){
	var msgerror='';
	if (document.formpano.titulo.value=='') 
		msgerror = '* Place tittle\n';
	if (document.formpano.descripcion.value=='') 
		msgerror = msgerror +'* Place description\n';
	if (document.formpano.tags.value=='') 
			msgerror = msgerror +'* Place Tags\n';
	if (msgerror!=''){
		alert('Please:\n\n'+msgerror);
		return false;
		}
	else
		{
		document.form1.panotitulo.value = document.formpano.titulo.value;
		document.form1.panodescripcion.value = document.formpano.descripcion.value;
		document.form1.panotags.value = document.formpano.tags.value;
		document.form1.action.value = 'saveplace';
		document.form1.submit();
		return false;
		}
}
function initialize2(lat,lng) {
	panoClient = new GStreetviewClient();  
  	var fenwayPark = new GLatLng(lat,lng);
  	panoramaOptions = { latlng:fenwayPark };
  	myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);
    GEvent.addListener(myPano, "error", handleNoFlash);
	panoClient.getNearestPanorama(fenwayPark, showPanoData);
}

function initialize(lat,lng,yawx,pitchx) {
  if (GBrowserIsCompatible()) {
  		map = new GMap2(document.getElementById('map_canvas'));
		map.addControl(new GMapTypeControl());
        map.addControl(new GLargeMapControl());
		map.setCenter(new GLatLng(lat,lng), 17);
		geocoder = new GClientGeocoder();
		svOverlay = new GStreetviewOverlay();
        map.addOverlay(svOverlay);
		var arrow = new GMarker(new GLatLng(lat,lng,0,0),{icon:arrowIcon});
		map.addOverlay(arrow) ;
		var lastPoint;
		var dir = Math.round(yawx/3) * 3;
		while (dir >= 120) {dir -= 120;}
		arrow.setImage("http://www.google.com/intl/en_ALL/mapfiles/dir_"+dir+".png");
		GEvent.addListener(map,"click", function(overlay,latlng) {
			if (!overlay) {
          		mymypano.remove();
				mymypano.setLocationAndPOV(latlng);
				arrow.setLatLng(latlng);
				lastPoint = latlng;
				map.setCenter(lastPoint);
				//mostrarcentro();
			}
			else
			{
				//alert('Wooop, google no tiene vista de calle en este punto');
			}
        });
	/*	GEvent.addListener(map,"moveend", function() {
			//map2.setCenter(map.getCenter);
			document.getElementById('panoramio').innerHTML='';
			mostrarfotos();
			mostrarsitios();
        });*/
		mymypano = new GStreetviewPanorama(document.getElementById("mypano"));
	    fenwayPark = new GLatLng(lat,lng);
	    myPOV = {yaw:yawx,pitch:pitchx,zoom:0};
	    mymypano.setLocationAndPOV(fenwayPark, myPOV);
		
	    /*GEvent.addListener(mymypano, "error", handleNoFlash);
		
		GEvent.addListener(mymypano,"initialized",function(a) {
		    	arrow.setLatLng(a.latlng);
				map.addOverlay(new GPolyline([lastPoint,a.latlng]));
				lastPoint = a.latlng;
				map.setCenter(a.latlng);
				/*mostrarcentro();
				document.form1.latitud.value=lastPoint.lat();
				document.form1.longitud.value=lastPoint.lng();
		      });

		GEvent.addListener(mymypano,"yawchanged",function(yaw) {
		       	var dir = Math.round(yaw/3) * 3;
				myaw = yaw;
				document.form1.yaw.value=yaw;
			    while (dir >= 120) {dir -= 120;}
			    arrow.setImage("http://www.google.com/intl/en_ALL/mapfiles/dir_"+dir+".png");
				//mostrarcentro()
		      });
		GEvent.addListener(mymypano,"pitchchanged",function(pitch) {
			mpith = pitch;
		        //document.form1.pitch.value=pitch;
				//mostrarcentro()
		      });
			GEvent.addListener(mymypano,"zoomchanged",function(zoom) {
				mzoompano = zoom;
			        document.form1.zoommypano.value=zoom;
			mostrarcentro()
			      });
			
	mostrarcentro();
	mostrarfotos();
	mostrarsitios();*/
		
   }

}
