// Preloader para as imagens

function MM_preloadImages() { //v3.0´
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
// Swapper para fotos
function nfoto (i){
document.fotoG.src = i;
}
infor = 0;
function info (){
        if (infor == 1){
                document.getElementById("info").style.display = 'none';
                document.getElementById("info").style.visibility = 'hidden';
                document.getElementById("info2").style.display = 'none';
                document.getElementById("info2").style.visibility = 'hidden';
                infor = 0;
        }else{
                document.getElementById("info").style.display = 'block';
                document.getElementById("info").style.visibility = 'visible';
                document.getElementById("info2").style.display = 'block';
                document.getElementById("info2").style.visibility = 'visible';
                infor = 1;
        }
}

// show/hide do mapa
mapaz=0;
var mapDiv;
var map = null;
var nome2 = '';
var angulo2 = null;
var botao2 = null;
var myPano = null;
var point;


// 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 markerIcon = new GIcon(G_DEFAULT_ICON);
		markerIcon.image = "/images/maps/marker.png";
		var marker = new GMarker(point, {icon:markerIcon});
		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);
		}
	}
}
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 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) {
		  $("#mapON").html(botao2);
		  if (errorCode == 'FLASH_UNAVAILABLE') {
			alert("Error: Flash doesn't appear to be supported by your browser");
			return;
		  }
		  if (errorCode == 600) {
			return;
			}
		} 
}
function resizeMapas(){
		document.getElementById("map").style.width="600px";
  		$("#mapON").html(botao2 + " / Street View");
}
function inicio() {
		mapDiv = document.getElementById("map");
}


/* BOOKING */

function bookResult() { 
	_gaq.push(['_trackEvent', 'Unit - Booking', 'Search for availability', document.title]);
	$('#hotelBook').show();
	$('#hotelInfo').hide();
	$('#result').show();
}
function closeResult() { 
	$('#hotelInfo').show();
	$('#hotelBook').hide();
}

function autoIframe(frameId){
	try{
		frame = document.getElementById(result);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		objToResize = (frame.style) ? frame.style : frame;
		objToResize.height = innerDoc.body.scrollHeight + 10;
	}
	catch(err){
		window.status = err.message;
	}
}
function hideBook() { 
	$('#bookingForm1').hide();
	$('#bookingTitle').hide();
	$('#bookingForm2').hide();
}
function hideBookTitle() { 
	$('#bookingTitle').hide();
}


$(document).ready(function(){ 


	$("#mapON").attr('onclick','').click(function (e) {
		_gaq.push(['_trackEvent', 'Unit - Maps', 'Show Map', document.title]);
		$("#Gmap").show();
		$("#mapON").hide("slow");
		mountMap();
	});
	$("#mapOFF").attr('onclick','').click(function (e) {
		$("#Gmap").hide("slow");
		$("#mapON").show("slow");
	});

	/*GALERIA*/
	$("#photos_thumb a").click(function (e) {
		  $("#photos #photos_big li").hide();
		  var photoNew= $(this).attr('href');
		  $(photoNew).fadeIn(500);
		  e.preventDefault(); 
	});
	$("#fotoG").click(function (e) {
		_gaq.push(['_trackEvent', 'Unit - Photos', 'Show Slideshow', document.title]);
		var bigURL = $(this).attr("src");
		bigURL=bigURL.substring(0, bigURL.indexOf('.jpg'))+'b.jpg';
		$.fn.colorbox({href:bigURL})
	});
	$('#photos_big li a').append("<span class='magnify'>+</span>");
	$('#photos_big li a').colorbox({slideshow:true, slideshowSpeed:5000});
	$('.phg_form').colorbox({'width':638, 'height':368, iframe:true, onOpen:function(){
		_gaq.push(['_trackEvent', 'Unit - Contact Form', 'Open contact form', document.title]);
	}});
	
	if ( document.referrer.indexOf("vip=1") > 0 ) {  // mark booking iframe with &label=ESC when referer is Recomended List
		var bookingSrc = $('#bookingForm1').attr('src').replace("aid=319489","aid=319489&label=ESC");
		$('#bookingForm1').attr('src',bookingSrc);
	}
	
	$(".social_youtube").each(function(){
		$(this).attr('href',$(this).attr('href').replace('watch?v=','v/'));
	});
	$(".social_youtube").colorbox({iframe:true, innerWidth:853, innerHeight:505, title:" "});
});

