﻿//Variable Declarations
var tempValue = "";
var MySearchTag = "";
var MyParagraph1Height = 0;
var MyParagraph2Height = 0;
var MyTotalPar = 0;
var TheImageSrc = "";
var TheHrefSrc = "";
//Variables for Random News
var TotalNewsNum;
var MyFirstId = 0;
var MySecondId;
var TheNewHTML;
 
// Swap Images Roll over Roll Out 
function ChangeImage(imgID, imgSrc) {
 $("#MenuImg" + imgID).attr({'src':imgSrc});
}

$(window).resize(function(){ CalcToCall(); });
$(window).scroll(function(){ CalcToCall(); });
function CalcToCall() {
/* Click To Call Function */
  var $scrollingDiv = $("#clickToCall");
  var DwMain = parseInt($("#DWMain").outerWidth(true));
  var WrapDiv = $("#DWMain").parent().outerWidth(true);
  var Dividor = (WrapDiv - DwMain);
  Dividor = Math.round(Dividor/2);
  var marginLeft = (DwMain + Dividor);	
  $scrollingDiv
  .stop()
  if ($(window).scrollTop() >= 426) {
    $scrollingDiv.css({
      "position" : "fixed",
      "top" : "0px",
      "left" : (parseInt(marginLeft)+1) + "px"
    });console.log("\nDwMain: " + DwMain + "\nmarginLeft: " + marginLeft);
    if (marginLeft < DwMain) { 
      $("#DWMain").css("margin-left" , "100px"); 
    }
  }
  else { 
    $scrollingDiv.css({
      "top": "",
      "left": "",
      "position": ""
    });
  }
}
// OnLoadActions
$(function(){
  CalcToCall();
  var temp;
  $("#LanguageMenu a img").hover(
    function() { temp = $(this).attr("src"); $(this).attr("src", $(this).attr("usemap")); },
    function() { $(this).attr("src", temp);
  });
  // Top Menu
  try {
    $('#MainMenu .M0 .L1, #MainMenu .M0 .L1_Active').hover(function(e) {
        var menu = $('ul',$(this));
        menu.css('width',menu.width());
        if(menu.width() < menu.parent().width()) {
          menu.width(menu.parent().width());
        }
      $(this).children('ul').hoverFlow(e.type, {
        'height': 'show',
        'marginTop': 'show',
        'marginBottom': 'show',
        'paddingTop': 'show',
        'paddingBottom': 'show' 
      });
    }, function(e) {
      $(this).children('ul').hoverFlow(e.type, {
        'height': 'hide',
        'marginTop': 'hide',
        'marginBottom': 'hide',
        'paddingTop': 'hide',
        'paddingBottom': 'hide' 
      });
    });
  }
  catch(err) { }
      
  // Left Menu
//  $('#LeftMenu ul li').not('#LeftMenu ul li ul li').bind('mouseenter',function(e) {
  $('#topLeft ul li ul').parent().not('.L2_Active, .L3_Active, .L4_Active').bind('mouseenter',function(e) {
    var ulToSlide = $(this).children('ul.M4');    //gets the sibling ul of the parent clicked
    ulToSlide.stop(true, true).slideDown("slow");
  }).bind('mouseleave', function (){
    //var ulToSlide = $(this).siblings('ul');    //gets the sibling ul of the parent clicked
    //$('#LeftMenu ul li ul').not('#LeftMenu .L2_Active ul, #LeftMenu .L3_Active ul, #LeftMenu .L4_Active ul').stop(true, true).slideUp("slow");
    $(this).children("ul.M4").stop(true, true).slideUp("slow");
  });
  
  if($('#LeftMenu_LowerLevelsContentor').is(':empty')) {
    $('#LeftMenuContentor').css({display: "block" });
  }
  
  // Language Menu
  $('#LanguageSelector .M0 .L2').hover(function(e) {
    $(this).children('ul').hoverFlow(e.type, {
      'height': 'show',
      'marginTop': 'show',
      'marginBottom': 'show',
      'paddingTop': 'show',
      'paddingBottom': 'show' 
    });
  }, function(e) {
    $(this).children('ul').hoverFlow(e.type, {
      'height': 'hide',
      'marginTop': 'hide',
      'marginBottom': 'hide',
      'paddingTop': 'hide',
      'paddingBottom': 'hide' 
    });
  });
  
  // Accordions
  $('.ExpPacksAccordion ul li').bind('mouseenter',function(e) {
	var containerToSlide = $(this).find('.ShowHideContentor');	
	$('.ExpPacksAccordion ul li .ShowHideContentor').not(containerToSlide).animate({
	  'height': '1px'
	},{ queue:false, duration:900 });
	containerToSlide.animate({
	  'height': '96px'
	},{ queue:false, duration:900 });
  }).bind('mouseleave', function () {
	var containerToSlide = $(this).find('.ShowHideContentor');	
	containerToSlide.animate({
	  'height': '1px'
	},{ queue:false, duration:900 });
  });
  $('.ExpPacksAccordion ul li:first').trigger('mouseenter').trigger('mouseleave');
  $('.TExperienceAccordion ul li').bind('mouseenter',function(e) {
          //Mouse Over Images
          TheImageSrc = $(this).children('a').children('div').children('img').attr('src');
          $(this).children('a').children('div').children('img').attr({'src': TheImageSrc.slice(0,(TheImageSrc.length - 4)) + "_over" + TheImageSrc.slice((TheImageSrc.length - 4),TheImageSrc.length) });
	var containerToSlide = $(this).find('.ShowHideContentor');	
	$('.TExperienceAccordion ul li .ShowHideContentor').not(containerToSlide).animate({
	  'height': 0
	},{ queue:false, duration:1000 });
	containerToSlide.animate({
	  'height': '125px'
	},{ queue:false, duration:1000 });
  }).bind('mouseleave', function () {
          //Mouse Over Images
          $(this).children('a').children('div').children('img').attr({'src': TheImageSrc});
	var containerToSlide = $(this).find('.ShowHideContentor');	
	containerToSlide.animate({
	  'height': 0
	},{ queue:false, duration:1000 });
  });
  $(".h2 img").parent().css({'background-image':'none','padding':'0px','margin':'0px'});
  $(".Paragraph .NoNewsMsg").parent().parent().css({ 'display': 'none' });
  $('#GreyContentorCell .TExperienceAccordion img').each(function(e) {
    TheImageSrc = $(this).attr('src');
    $(this).attr({'src': TheImageSrc.slice(0,(TheImageSrc.length - 4)) + "2" + TheImageSrc.slice((TheImageSrc.length - 4),TheImageSrc.length) });
  });
  // News Paging
  $(".NewsPaging a b").parent().addClass("active");
  $(".Paragraph #SmallMapHolder").parent().parent().addClass("relative");
  //for table row
  $(".Table_WhiteGrey tbody").each(function(i) {
    $(this).children("tr:even").addClass("even");
    $(this).children("tr:odd").addClass("odd");
  });
  $(".table_eventos tbody tr:even").addClass("even");
  $(".table_eventos tbody tr:odd").addClass("odd");
  $(".table_eventos tbody tr td:nth-child(1)").css('text-align', 'left');
  $(".HotelDetails tbody").each(function(i) {
    $(this).children("tr:last").addClass("LastRow");
  });
  $(".Hotel_Reservations tbody tr").each(function(i) {
    $(this).children("td:last").addClass("right_bkg");
  });
//  $(".Hotel_Reservations img").each(function(i) {
//    TheImageSrc = $(this).attr('src');
//    $(this).attr({'src': '/admin/public/getimage.aspx?&Image=' + TheImageSrc + '&Resolution=75&Compression=80&Width=122&Height=100&Crop=0' });
//  });
  $(".Contacts_Table td:nth-child(2)").addClass("left_dotted_separator");
  //check if has content
  $(".table_links tbody tr td:nth-child(2)").each(function(i) {
    if($(this).html() != "&nbsp;") {
      $(this).addClass("right_bkg");
    }
    else {
      $(this).css({'background-color' : 'transparent'});
    }
  });
  
  //Hotel Details
  if ($.browser.msie) {
  $(".HotelDetails img").each(function(i) {
    TheImageSrc = $(this).attr('src');
    if(($(this).attr('width')) > 100) {
      $(this).wrap('<div class="DetailsImageList" orgSrc="' + TheImageSrc + '" orgWidth="' + $(this).attr('width') + '" style="background-image: URL(/admin/public/getimage.aspx?&Image=' + TheImageSrc + '&Resolution=75&Compression=80&Width=92&Height=74&Crop=0);"><div class="DetailsImage" id="HotelDetailsImage' + i + '" ><a href="#" onmouseout="HideDetailsImage(' + i + ')" orgSrc="' + TheImageSrc + '" /></div><a href="#" onmouseover="ShowDetailsImage(' + i + ')"><img src="/Files/System/TivoliHotels/Layout/mask_f8+.png" /></a></div>');
    }
    else {
      $(this).wrap('<div class="DetailsImageList" orgSrc="' + TheImageSrc + '" orgWidth="' + $(this).attr('width') + '" style="background-image: URL(/admin/public/getimage.aspx?&Image=' + TheImageSrc + '&Resolution=75&Compression=80&Width=92&Height=74&Crop=0);"><div style="display:none;" /><img src="/Files/System/TivoliHotels/Layout/mask_grey.png" /></div>');
    }
  });
  $(".HotelDetails .ImageContainer").css("visibility", "visible");
  }
  
  // Airports Table
  $(".AirportTable td:nth-child(1) img").each(function(i) {
    TheImageSrc = $(this).attr('src');
    $(this).wrap('<div class="DetailsImageList" style="background-image: URL(/admin/public/getimage.aspx?&Image=' + TheImageSrc + '&Resolution=75&Compression=80&Width=92&Height=74&Crop=0);"><div style="display:none;" /><img src="/Files/System/TivoliHotels/Layout/mask_grey.png" /></div>');
  });
  
  // Image Bank
  $("table.ImageBank td a").parent().addClass("ImageBankLink");
  $("table.ImageBank td img").parent().parent().addClass("ImageBankImg");
  $("table.ImageBank td img").parent().parent().removeClass("ImageBankLink");
  $("table.ImageBank td img").css({'width':'122px','height':'100px'});
  $("table.ImageBank tr").find(".ImageBankLink:last").addClass("right_bkg");
    
  if($('.PS_Hotel #GreyContentor').height() < 100) {
    $('.PS_Hotel #GreyContentor').css({display: "none"});
  }
  
  //For Table Absolute Images
  $(".table_eventos a").each(function(i) {
    TheHrefSrc = $(this).attr('href');
    if (TheHrefSrc.search(/.jpg/) > 0) {
      $(this).after('<div class="ImageEventsHolder"><div id="ImageEvents' + i + '" class="ImageEvents"><a href="#" onmouseout="HideImageEvents(' + i + ')"><img src="' + TheHrefSrc + '" /></a></div></div>');
      $(this).after('&nbsp;&nbsp;<span class="lupa">&nbsp;</span>');
      $(this).mouseover(function(t) { ShowImageEvents(i); });
    }
  });
  
  // Two columns separated by dotts strcture
  //Horizontal dotted separator
  /*$("#PS_2Column .Paragraph").after('<div class="Separator" style="text-align: center;"><div class="BottomSeparator"></div></div>');
  $("#PS_2Column #LeftColumn .Separator:last").css({'display':'none'});
  $("#PS_2Column #RightColumn .Separator:last").css({'display':'none'});*/
  
  
  //MyTotalPar = $("#LeftColumn .T11-B11, #LeftColumn .B11-T11, #LeftColumn .Tx-Bx, #LeftColumn .Bx-Tx").size();
  MyTotalPar = $("#LeftColumn .Paragraph").size();
  for ( i=0 ; i < MyTotalPar ; i++) {
    MyParagraph1Height = parseInt($("#PS_2Column #LeftColumn .Paragraph:eq(" + i + ")").height());
    MyParagraph2Height = parseInt($("#PS_2Column #RightColumn .Paragraph:eq(" + i + ")").height());
    if(MyParagraph1Height > MyParagraph2Height) {
      $("#PS_2Column #RightColumn .Paragraph:eq(" + i + ")").css({minHeight: MyParagraph1Height});
    } 
    else {
      $("#PS_2Column #LeftColumn .Paragraph:eq(" + i + ")").css({minHeight: MyParagraph2Height });
    }
  }
  
  //Grey Bkg Spacing and margins correction
  $("#PS_Grey #CenterColumn .Paragraph img").not("#PS_Grey #CenterColumn .T11-B11_image img, #PS_Grey #CenterColumn .B11-T11_image img, #PS_Grey #CenterColumn a img").each(function(i) {
    if($(this).width() == "404") {
      $(this).wrap('<div style="position: relative; height:' + $(this).height() + 'px;"><div style="position: absolute; left: -6px;" /></div>');
    }
  });
  $("#PS_Grey #CenterColumn .Paragraph a img").each(function(i) {
    if($(this).width() == "404") {
      $(this).parent().wrap('<div style="position: relative; height:' + $(this).height() + 'px;"><div style="position: absolute; left: -6px;" /></div>');
    }
  });
  
  //Set iframe background transparent
  $('.T11-B11_MiniPapers iframe').attr('allowTransparency', 'true');
  
  $("#PS_Grey #CenterColumn .Paragraph h1").wrap('<div class="TitleHolder" />');
  $("#PS_Grey #CenterColumn .Paragraph:nth-child(1) h2").not('.NewsItem_Title h2').wrap('<div class="TitleHolder" />');
  $("#PS_Grey #CenterColumn .Paragraph:nth-child(2) h1, #PS_Grey #CenterColumn .Paragraph:nth-child(2) h2").each(function(i) {
    $("#PS_Grey #CenterColumn .Paragraph:nth-child(1)").wrap('<div class="TitleImgContentorHotel" />');
  });
  
  // News Random
  $(".NewsListContentorRandom").each(function(i) {
    $(this).children('ul').children('li').each(function(e) {
      if($(this).hasClass("NewsFixTrue")) {
        MyFirstId = e+1;
      }
    });
    
    TotalNewsNum = $(this).children('ul').children('li').size();
  
    if(MyFirstId == 0) {
      MyFirstId = (Math.floor(Math.random()*TotalNewsNum))+1;
      $(this).children('ul').children('.Item' + MyFirstId).css({'display':'block'});
    }
    else {
      $(this).children('ul').prepend('<li class="NewsFixFalse" style="display: block; border: 0px;">' + $(this).children('ul').children('.NewsFixTrue').html() + '</li>');
    }
    MySecondId = (Math.floor(Math.random()*TotalNewsNum))+1;
    if (MySecondId == MyFirstId) {
      if(MySecondId == TotalNewsNum) {
        MySecondId = Math.floor(MySecondId) - 1;
      }
      else {
        MySecondId = Math.floor(MySecondId) + 1;
      }
    }
  
    if($("#PS_2Column_tkids .NewsListContentorRandom").html() == null) {
      $(this).children('ul').children('.Item' + MySecondId).css({'display':'block'});
    }
  
    MyFirstId = 0;
  
    //$(this).children('ul').children('li').css({'display':'block'});
  });
  
  // News Random Homepage 2 Columns
  $(".NewsListContentor2Col").each(function(i) {
    TotalNewsNum = $(this).children('ul').children('li').size()-1;
    if(MyFirstId == 0) {
      MyFirstId = (Math.floor(Math.random()*TotalNewsNum))+1;
      $(this).children('ul').children('.Item' + MyFirstId).css({'display':'block', 'float':'left'});
    }
    else {
      $(this).children('ul').prepend('<li class="NewsListItem" style="display: block; float: left;">' + $(this).children('ul').children('.NewsFix').html() + '</li>');
    }
    MySecondId = (Math.floor(Math.random()*TotalNewsNum))+1;
    if (MySecondId == MyFirstId) {
      if(MySecondId == TotalNewsNum) {
        MySecondId = Math.floor(MySecondId) - 1;
      }
      else {
        MySecondId = Math.floor(MySecondId) + 1;
      }
    }
    $(this).children('ul').children('.Item' + MySecondId).css({'display':'block', 'float':'right'});
 //   if($(this).children('ul').children('.Item' + MyFirstId).children('.ResizeContentor').height() > $(this).children('ul').children('.Item' + MySecondId).children('.ResizeContentor').height()) {
 //     $(this).children('ul').children('.Item' + MySecondId).children('.ResizeContentor').height() = $(this).children('ul').children('.Item' + MyFirstId).children('.ResizeContentor').height();
 //   }
 //   else {
 //     $(this).children('ul').children('.Item' + MyFirstId).children('.ResizeContentor').height() = $(this).children('ul').children('.Item' + MySecondId).children('.ResizeContentor').height();
 //   }
    MyParagraph1Height = parseInt($(this).children('ul').children('.Item' + MyFirstId).children('div').children('div').children('div').children('.ResizeContentor').height());
    MyParagraph2Height = parseInt($(this).children('ul').children('.Item' + MySecondId).children('div').children('div').children('div').children('.ResizeContentor').height());
    if(MyParagraph1Height > MyParagraph2Height) {
//alert('1');
      $(".ResizeContentor").css({minHeight: MyParagraph1Height});
      //$(".ResizeContentor:eq(" + MySecondId + ")").css({minHeight: MyParagraph1Height});
    } 
    else {
      $(".ResizeContentor").css({minHeight: MyParagraph2Height});
//alert('2');
      //$(".ResizeContentor:eq(" + MyFirstId + ")").css({minHeight: MyParagraph2Height });
    }
    MyFirstId = 0;
  });
  
  //Date Validation
  $("#dia_44079, #mes_44079, #ano_44079").keyup(function() {
    this.value = this.value.replace(/[^0-9\.]/g,'');
  });
    
  /*
  if($('.tkids-columns').length > 0) {
	var form = $('.Newsletter form');
	
	form.submit(function (e) {
		e.preventDefault();
		email = $(this).find('#AccessUserEmail').val();
		
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email) == false) {
			alert('E-mail inválido.');
			return false;
		}
		
		if($('.overlay').length == 0) {
			$('body').prepend($('<div />').addClass('overlay'));
		}
		var overlay = $('.overlay');
		
		//prepara o formulário
		overlay.html($('.Newsletter .customfields').html());
		
		submit = $('<div />').addClass('tkids-newsletter-submit')
							 .bind('click',function () {
								//validates
								var inputs = $('.overlay input');
								inputs.each (function () {
									if($(this).val() == '')
										return false;
									else
										$('.Newsletter .customfields input[name='+$(this).attr('name')+']').val($(this).val());
								});
								//copies values
								//close overlay
								overlay.overlay().close();
								//submits newsletter form
								form.unbind('submit');
								//form.submit();
							 });
							 
		overlay.append(submit);
		
		//cria o overlay		
		overlay.overlay({
			expose: {
				color: '#297B30',
				loadSpeed: 200,
				opacity: 0.5
			}
		});
		overlay.overlay().load();
	});	
  }  
  */
});
 
$(window).load(
  function() {
  
  if (!$.browser.msie) {
    //Hotel Details
    $(".HotelDetails img").each(function(i) {
      TheImageSrc = $(this).attr('src');
      if(parseInt($(this).width()) > 100) {
        $(this).wrap('<div class="DetailsImageList" style="background-image: URL(/admin/public/getimage.aspx?&Image=' + TheImageSrc + '&Resolution=75&Compression=80&Width=92&Height=74&Crop=0);"><div class="DetailsImage" id="HotelDetailsImage' + i + '" style="z-index:5000"><a href="#" onmouseout="HideDetailsImage(' + i + ')" orgSrc="' + TheImageSrc + '" /></div><a href="#" onmouseover="ShowDetailsImage(' + i + ')" style="z-index:2000"><img src="/Files/System/TivoliHotels/Layout/mask_f8+.png" /></a></div>');
      }
      else {
        $(this).wrap('<div class="DetailsImageList" style="background-image: URL(/admin/public/getimage.aspx?&Image=' + TheImageSrc + '&Resolution=75&Compression=80&Width=92&Height=74&Crop=0);"><div style="display:none;" /><img src="/Files/System/TivoliHotels/Layout/mask_grey.png" /></div>');
      }
    });
    $(".HotelDetails .ImageContainer").css("visibility", "visible");
    $(".HotelDetails .ImageContainer > div").css("height", "74px");
  }
  }
); 
 
   
function ShowDetailsImage(TheImage) {
  $('#HotelDetailsImage' + TheImage).css({display: 'block'});
}
function HideDetailsImage(TheImage) {
  $('#HotelDetailsImage' + TheImage).css({display: 'none'});
}
function ShowImageEvents(TheImage) {
  $('#ImageEvents' + TheImage).css({display: 'block'});
}
function HideImageEvents(TheImage) {
  $('#ImageEvents' + TheImage).css({display: 'none'});
}
 
// Search Module Validations
function CheckField (FieldID, FieldValue, TheString) {
 tempValue = document.getElementById(FieldID).value;
  
 if (tempValue == FieldValue) {
   document.getElementById(FieldID).value = "";
 }
 if (tempValue == "") {
   document.getElementById(FieldID).value = TheString;
 }
}
function GetSearchTag(errorMessage,TheBoxMessage,ThePageId) {
 MySearchTag = document.getElementById("q").value;
 if(MySearchTag != "" && MySearchTag != TheBoxMessage){
 window.location = "/Default.aspx?ID=" + ThePageId + "&q=" + MySearchTag;
 }else {
 alert(errorMessage);
 }
}
 
function getPageLanguage(pageId, destinationArea) {
  $.ajax({
    url: location.protocol + "//" + location.hostname + "/admin/public/getnavigationxml.aspx?Expand=1&ID=" + pageId,
    success: function(data){
      var xml;
      if ($.browser.msie && typeof data == "string") {
        xml = new ActiveXObject("Microsoft.XMLDOM");
        xml.async = false;
        xml.loadXML(data);                
      } else {
         xml = data;
      }
      
      var pathToPage = [];
      $(xml).find("Page[InPath='True']").each(function() {
        pathToPage.push($(this).attr("Sort"));
      });
      getDestinationHref(destinationArea, pathToPage);
    }
  });
}
 
function getDestinationHref(destinationArea, pathToPage) {
  $.ajax({
    url: location.protocol + "//" + location.hostname + "/admin/public/getnavigationxml.aspx?AreaId=" + destinationArea,
    success: function(data){
      var xml;
      if ($.browser.msie && typeof data == "string") {
        xml = new ActiveXObject("Microsoft.XMLDOM");
        xml.async = false;
        xml.loadXML(data);                
      } else {
         xml = data;
      }
      
      jQuerySelector = "";
      for(i=0;i<pathToPage.length;i++) {
        jQuerySelector+="Page[AbsoluteLevel='" + (i+1) + "'][Sort='" + pathToPage[i] + "'] ";
      }
      if ($(xml).find(jQuerySelector).length) {
        $(xml).find(jQuerySelector).each(function() {
          window.location = $(this).attr("FriendlyHref");
        });
      }
      else {
        window.location = "/Default.aspx?AreaId=" + destinationArea;
      }
    }
  });
}
 
function PreSelectHotel(pageId, lang) {
  var HotelValue = "-1";
       //         PT               EN                ES                FR                DE                BR
       if (pageId == 60  || pageId == 5162 || pageId == 5968 || pageId == 6774 || pageId == 7580 || pageId == 9919)  HotelValue = "27500"; // TIVOLI VICTORIA - VILAMOURA
  else if (pageId == 297 || pageId == 5199 || pageId == 6005 || pageId == 6811 || pageId == 7617 || pageId == 9957)  HotelValue = "27497"; // TIVOLI MARINA VILAMOURA
  else if (pageId == 324 || pageId == 5238 || pageId == 6044 || pageId == 6850 || pageId == 7656 || pageId == 9998)  HotelValue = "27511"; // TIVOLI MARINA PORTIMAO
  else if (pageId == 350 || pageId == 5268 || pageId == 6074 || pageId == 6880 || pageId == 7686 || pageId == 10030) HotelValue = "27512"; // TIVOLI CARVOEIRO
  else if (pageId == 64  || pageId == 5116 || pageId == 5922 || pageId == 6728 || pageId == 7534 || pageId == 9872)  HotelValue = "27510"; // TIVOLI LAGOS
  else if (pageId == 65  || pageId == 5148 || pageId == 5954 || pageId == 6760 || pageId == 7566 || pageId == 9905)  HotelValue = "27499"; // THE RESIDENCES AT VICTORIA
  else if (pageId == 67  || pageId == 5299 || pageId == 6105 || pageId == 6911 || pageId == 7717 || pageId == 10062) HotelValue = "27504"; // TIVOLI COIMBRA
  else if (pageId == 69  || pageId == 5329 || pageId == 6135 || pageId == 6941 || pageId == 7747 || pageId == 10093) HotelValue = "27509"; // TIVOLI LISBOA
  else if (pageId == 434 || pageId == 5396 || pageId == 6202 || pageId == 7008 || pageId == 7814 || pageId == 10162) HotelValue = "27508"; // TIVOLI JARDIM
  else if (pageId == 458 || pageId == 5364 || pageId == 6170 || pageId == 6976 || pageId == 7782 || pageId == 10129) HotelValue = "27507"; // TIVOLI ORIENTE
  else if (pageId == 481 || pageId == 5428 || pageId == 6234 || pageId == 7040 || pageId == 7846 || pageId == 10195) HotelValue = "27503"; // TIVOLI MADEIRA
  else if (pageId == 75  || pageId == 5463 || pageId == 6269 || pageId == 7075 || pageId == 7881 || pageId == 10231) HotelValue = "27505"; // TIVOLI PALÁCIO DE SETEAIS
  else if (pageId == 526 || pageId == 5494 || pageId == 6300 || pageId == 7106 || pageId == 7912 || pageId == 10263) HotelValue = "27506"; // TIVOLI SINTRA
  else if (pageId == 546 || pageId == 5076 || pageId == 5882 || pageId == 6688 || pageId == 7494 || pageId == 9831)  HotelValue = "27501"; // TIVOLI ECORESORT PRAIA DO FORTE
  else if (pageId == 81  || pageId == 5527 || pageId == 6333 || pageId == 7139 || pageId == 7945 || pageId == 10297) HotelValue = "27498"; // TIVOLI SÃO PAULO - MOFARREJ
  
  if ($('#hotel').length > 0 && HotelValue != "-1") {
    $('#hotel').getSetSSValue(HotelValue);
  }
  
  var PageIds = new Array();
  var TemplateIds = new Array();
  PageIds = [297, 5199, 6005, 6811, 7617, 9957,   // TIVOLI MARINA VILAMOURA
             324, 5238, 6044, 6850, 7656, 9998,   // TIVOLI MARINA PORTIMAO
             350, 5268, 6074, 6880, 7686, 10030,  // TIVOLI CARVOEIRO
             64,  5116, 5922, 6728, 7534, 9872,   // TIVOLI LAGOS
             69,  5329, 6135, 6941, 7747, 10093,  // TIVOLI LISBOA
             434, 5396, 6202, 7008, 7814, 10162,  // TIVOLI JARDIM
             458, 5364, 6170, 6976, 7782, 10129,  // TIVOLI ORIENTE
             526, 5494, 6300, 7106, 7912, 10263]; // TIVOLI SINTRA
  TemplateIds = [282223, 282233, 282253, 689123, 282243, 282223,  // TIVOLI MARINA VILAMOURA
                 310883, 310843, 310903, 689063, 310863, 310883,  // TIVOLI MARINA PORTIMAO
                 348565, 348555, 348575, 689073, 348585, 348565,  // TIVOLI CARVOEIRO
                 310873, 310833, 310893, 689103, 310853, 310873,  // TIVOLI LAGOS
                 282143, 282153, 282173, 689052, 282163, 282143,  // TIVOLI LISBOA
                 348355, 348345, 348365, 689093, 348375, 348355,  // TIVOLI JARDIM
                 282183, 282193, 282213, 689062, 282203, 282183,  // TIVOLI ORIENTE
                 348425, 348405, 348435, 689133, 348445, 348425]; // TIVOLI SINTRA
  
  for(i=0;i<PageIds.length;i++) {
    if (pageId == PageIds[i]) {
      sufix = "";
//           if ((i+1)%5 == 0) sufix = "_de";
//      else if ((i+1)%4 == 0) sufix = "_fr";
//      else if ((i+1)%3 == 0) sufix = "_es";
//      else if ((i+1)%2 == 0) sufix = "_en";
      if (lang != "pt") sufix = "_"+lang;
      TemplateVar = "Template=" + TemplateIds[i];
      $("#topLeft").append('<div class="ClickToCall"><a href="javascript:void(0);" onclick="webVoicePop(TemplateVar)"><img src="/Files/Billeder/bot_clicktocall' + sufix + '.gif" title="ClickToCall" alt="ClickToCall" /></a></div>');
      break;
    }
  }
}
 
//jquery tools overlay
(function(c){c.tools=c.tools||{};c.tools.overlay={version:"1.1.2",addEffect:function(e,f,g){b[e]=[f,g]},conf:{top:"10%",left:"center",absolute:false,speed:"normal",closeSpeed:"fast",effect:"default",close:null,oneInstance:true,closeOnClick:true,closeOnEsc:true,api:false,expose:null,target:null}};var b={};c.tools.overlay.addEffect("default",function(e){this.getOverlay().fadeIn(this.getConf().speed,e)},function(e){this.getOverlay().fadeOut(this.getConf().closeSpeed,e)});var d=[];function a(g,k){var o=this,m=c(this),n=c(window),j,i,h,e=k.expose&&c.tools.expose.version;var f=k.target||g.attr("rel");i=f?c(f):null||g;if(!i.length){throw"Could not find Overlay: "+f}if(g&&g.index(i)==-1){g.click(function(p){o.load(p);return p.preventDefault()})}c.each(k,function(p,q){if(c.isFunction(q)){m.bind(p,q)}});c.extend(o,{load:function(u){if(o.isOpened()){return o}var r=b[k.effect];if(!r){throw'Overlay: cannot find effect : "'+k.effect+'"'}if(k.oneInstance){c.each(d,function(){this.close(u)})}u=u||c.Event();u.type="onBeforeLoad";m.trigger(u);if(u.isDefaultPrevented()){return o}h=true;if(e){i.expose().load(u)}var t=k.top;var s=k.left;var p=i.outerWidth({margin:true});var q=i.outerHeight({margin:true});if(typeof t=="string"){t=t=="center"?Math.max((n.height()-q)/2,0):parseInt(t,10)/100*n.height()}if(s=="center"){s=Math.max((n.width()-p)/2,0)}if(!k.absolute){t+=n.scrollTop();s+=n.scrollLeft()}i.css({top:t,left:s,position:"absolute"});u.type="onStart";m.trigger(u);r[0].call(o,function(){if(h){u.type="onLoad";m.trigger(u)}});if(k.closeOnClick){c(document).bind("click.overlay",function(w){if(!o.isOpened()){return}var v=c(w.target);if(v.parents(i).length>1){return}c.each(d,function(){this.close(w)})})}if(k.closeOnEsc){c(document).unbind("keydown.overlay").bind("keydown.overlay",function(v){if(v.keyCode==27){c.each(d,function(){this.close(v)})}})}return o},close:function(q){if(!o.isOpened()){return o}q=q||c.Event();q.type="onBeforeClose";m.trigger(q);if(q.isDefaultPrevented()){return}h=false;b[k.effect][1].call(o,function(){q.type="onClose";m.trigger(q)});var p=true;c.each(d,function(){if(this.isOpened()){p=false}});if(p){c(document).unbind("click.overlay").unbind("keydown.overlay")}return o},getContent:function(){return i},getOverlay:function(){return i},getTrigger:function(){return g},getClosers:function(){return j},isOpened:function(){return h},getConf:function(){return k},bind:function(p,q){m.bind(p,q);return o},unbind:function(p){m.unbind(p);return o}});c.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","),function(p,q){o[q]=function(r){return o.bind(q,r)}});if(e){if(typeof k.expose=="string"){k.expose={color:k.expose}}c.extend(k.expose,{api:true,closeOnClick:k.closeOnClick,closeOnEsc:false});var l=i.expose(k.expose);l.onBeforeClose(function(p){o.close(p)});o.onClose(function(p){l.close(p)})}j=i.find(k.close||".close");if(!j.length&&!k.close){j=c('<div class="close"></div>');i.prepend(j)}j.click(function(p){o.close(p)})}c.fn.overlay=function(e){var f=this.eq(typeof e=="number"?e:0).data("overlay");if(f){return f}if(c.isFunction(e)){e={onBeforeLoad:e}}var g=c.extend({},c.tools.overlay.conf);e=c.extend(true,g,e);this.each(function(){f=new a(c(this),e);d.push(f);c(this).data("overlay",f)});return e.api?f:this}})(jQuery);
(function(b){b.tools=b.tools||{};b.tools.expose={version:"1.0.5",conf:{maskId:null,loadSpeed:"slow",closeSpeed:"fast",closeOnClick:true,closeOnEsc:true,zIndex:9998,opacity:0.8,color:"#456",api:false}};function a(){if(b.browser.msie){var f=b(document).height(),e=b(window).height();return[window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,f-e<20?e:f]}return[b(window).width(),b(document).height()]}function c(h,g){var e=this,j=b(this),d=null,f=false,i=0;b.each(g,function(k,l){if(b.isFunction(l)){j.bind(k,l)}});b(window).resize(function(){e.fit()});b.extend(this,{getMask:function(){return d},getExposed:function(){return h},getConf:function(){return g},isLoaded:function(){return f},load:function(n){if(f){return e}i=h.eq(0).css("zIndex");if(g.maskId){d=b("#"+g.maskId)}if(!d||!d.length){var l=a();d=b("<div/>").css({position:"absolute",top:0,left:0,width:l[0],height:l[1],display:"none",opacity:0,zIndex:g.zIndex});if(g.maskId){d.attr("id",g.maskId)}b("body").append(d);var k=d.css("backgroundColor");if(!k||k=="transparent"||k=="rgba(0, 0, 0, 0)"){d.css("backgroundColor",g.color)}if(g.closeOnEsc){b(document).bind("keydown.unexpose",function(o){if(o.keyCode==27){e.close()}})}if(g.closeOnClick){d.bind("click.unexpose",function(o){e.close(o)})}}n=n||b.Event();n.type="onBeforeLoad";j.trigger(n);if(n.isDefaultPrevented()){return e}b.each(h,function(){var o=b(this);if(!/relative|absolute|fixed/i.test(o.css("position"))){o.css("position","relative")}});h.css({zIndex:Math.max(g.zIndex+1,i=="auto"?0:i)});var m=d.height();if(!this.isLoaded()){d.css({opacity:0,display:"block"}).fadeTo(g.loadSpeed,g.opacity,function(){if(d.height()!=m){d.css("height",m)}n.type="onLoad";j.trigger(n)})}f=true;return e},close:function(k){if(!f){return e}k=k||b.Event();k.type="onBeforeClose";j.trigger(k);if(k.isDefaultPrevented()){return e}d.fadeOut(g.closeSpeed,function(){k.type="onClose";j.trigger(k);h.css({zIndex:b.browser.msie?i:null})});f=false;return e},fit:function(){if(d){var k=a();d.css({width:k[0],height:k[1]})}},bind:function(k,l){j.bind(k,l);return e},unbind:function(k){j.unbind(k);return e}});b.each("onBeforeLoad,onLoad,onBeforeClose,onClose".split(","),function(k,l){e[l]=function(m){return e.bind(l,m)}})}b.fn.expose=function(d){var e=this.eq(typeof d=="number"?d:0).data("expose");if(e){return e}if(typeof d=="string"){d={color:d}}var f=b.extend({},b.tools.expose.conf);d=b.extend(f,d);this.each(function(){e=new c(b(this),d);b(this).data("expose",e)});return d.api?e:this}})(jQuery);
