
// set image and caption - for non-lightbox pages
function SetBGImageAndCaption(ImageToShow, Caption) {
   
   $("#headerimg1").css({
                "background-image": "url(" + ImageToShow + ")",
                "display": "block",
                "z-index": "-1"
            });
   
   //turn off caption fade
   
   if (Caption=='empty'){
        $('#caption-outer').hide();
   }
   else
   {    $('#caption-outer').show();
        $('#captioninner').html(Caption);
   }         
}

//
// pull image and caption out of array for lightbox
// used to initialise lightbox page - without delay on caption
// headerimg1,z-index=-1 - used so first lightbox click fades slow
//
function SetBGImageAndCaptionFromArray(imgToShowIndex) {
   ImageToShow = RoomImages[imgToShowIndex - 1].image;
   Caption = RoomImages[imgToShowIndex - 1].firstline;
   $("#headerimg1").css({
                "background-image": "url(" + ImageToShow + ")",
                "display": "block",
                "z-index": "-1"
            });
   
   //turn off caption fade
 
   if (Caption=='empty'){
        $('#caption-outer').hide();
   }
   else
   {    $('#caption-outer').show();
        $('#captioninner').html(Caption);
   } 
   
   //$('#captioninner').html(Caption);
   
}


    //
    // SECTION 1
    //
  // *****************
  // 
  // iphone style menu
  //
  // *****************

    var bInitialMenuSet = false;
    
  function iMenu( sExtraParamHref ) {
      
      defaultWidth = 247; //pixels
      transition = 500; //millisecond
      
      if (isiPhone) {defaultWidth = 650;}
      
      //Initialise menu for section other than top level
      if (sExtraParamHref != '' && !(bInitialMenuSet) ) {
           transition = 0;
           $('#container').hide();
      } ;
      
      function resetMargin(width) {
          divLeftMargin = 0;
          $('.additional-block').each(function() {
              thisLeftMargin = divLeftMargin + 'px';
              $(this).css('margin-left', thisLeftMargin);
              divLeftMargin = divLeftMargin + width;
          });
      }

      resetMargin(defaultWidth);


        //possibly don't need this - if class for has-child is irrelevant 
      $('.menu a').each(function() {
          thisHref = $(this).attr('href');
          if ($(thisHref).length > 0) {
              $(this).addClass('has-child');
          }
      });

        //stop animation when hovering over menu
        $('.menu a').mouseover( function () {animating=true; } ).mouseout(function() {animating=false; });
            
      $('.menu a').click(function(event) {
          //event.preventDefault(); //don't include this line - in fact some of the links will require default action
          selectedHref = $(this).attr('href');
          selectedMargin = $(selectedHref).css('margin-left');
          selectedParent = $(this).parents('.additional-block');
          sliderMargin = $('.slider').css('margin-left');
          slidingMargin = (parseInt(sliderMargin) - defaultWidth) + 'px';

          //
          // for a normal hyperlink - there will ne no margin-left
          // so allow link to take user to next page
          // otherwise slide menu
          //
          if (selectedMargin != null) {

              event.preventDefault();

              if (selectedMargin.length > 0) {
                    
                    //set up back button - this did work but set up too big an area of the whole header div.
//                  $(selectedHref).children('.header').prepend('<span class="back"></span>').bind('click', function() {
//                      selectedParent = $(this).parents('.additional-block');
//                      sliderMargin = -(parseInt(selectedParent.css('margin-left')) - defaultWidth) + 'px';
//                      $('.slider').animate({ marginLeft: sliderMargin }, transition);
//                  });

                    //$(selectedHref).children('.header').prepend('<span class="back" id="backbutton"></span>');
                    $('.back').bind('click', function() {
                      selectedParent = $(this).parents('.additional-block');
                      sliderMargin = -(parseInt(selectedParent.css('margin-left')) - defaultWidth) + 'px';
                      $('.slider').animate({ marginLeft: sliderMargin }, transition);
                  });

                    //swap divs around if the next div to show is not in position                    
                  if ((parseInt(selectedMargin) - defaultWidth) >= defaultWidth) {
                      selectedParent.after($(selectedHref));
                      resetMargin(defaultWidth);
                      $('.slider').animate({ marginLeft: slidingMargin }, transition);
                  } else {
                      $('.slider').animate({ marginLeft: slidingMargin }, transition);
                  }
              }
          }

      });

        // if menu is at a lower level, then click through to it and reset transition to fade
      if (sExtraParamHref != '' && !(bInitialMenuSet) ) {
           $('a[href$="' + sExtraParamHref + '"]').click();
           transition = 500;
           bInitialMenuSet = true;
           $('#container').show();
      } ;

      
  }


/*
 *  background jquery image slider   Marco Kuiper (http://www.marcofolio.net/)
 */

    //
    // SECTION 2
    //
    // **********************************
  // 
  // background menu slideshow for home
  //
  // **********************************



// Speed of the automatic slideshow
var slideshowSpeed = 5000;
var animating = false;


//use less deep images for smaller screen sizes...
var use768images = false;
if (issmallscreen()) 
{
    use768images = true;
}

  function bgSlideshow() {
      var activeContainer = 1;
      var currentImg = 0;
      //var animating = false; //now global var - so that menu hover pauses animation

      var navigate = function(direction) {
          // Check if no animation is running. If it is, prevent the action
          if (animating) {
              return;
          }

          // Check which current image we need to show
          if (direction == "next") {
              currentImg++;
              if (currentImg == photos.length + 1) {
                  currentImg = 1;
              }
          } else {
              currentImg--;
              if (currentImg == 0) {
                  currentImg = photos.length;
              }
          }

          // Check which container we need to use
          var currentContainer = activeContainer;
          if (activeContainer == 1) {
              activeContainer = 2;
          } else {
              activeContainer = 1;
          }
          
          if (use768images) {
              showImage(photos768[currentImg - 1], currentContainer, activeContainer);
          }
          else
          { 
              showImage(photos[currentImg - 1], currentContainer, activeContainer);
          }
      };

      var currentZindex = -1;
      var showImage = function(photoObject, currentContainer, activeContainer) {
          animating = true;

          // Make sure the new container is always on the background
          currentZindex--;

          // Set the background image of the new active container
          $("#headerimg" + activeContainer).css({
              "background-image": "url(" + photoObject.image + ")",
              //"height": "1500px",
              //"background-color": "aqua",
              //"background-size" : "100%",
              "display": "block",
              "z-index": currentZindex
          });

          // Fade out the current container
          // and display the header text when animation is complete
          $("#headerimg" + currentContainer).fadeOut(3000,function() {
              setTimeout(function() {
                 // $("#headertxt").css({"display" : "block"});
                  animating = false;
              });
          });
      };

      var stopAnimation = function() {
          // Change the background image to "play"
          $("#control").css({ "background-image": "url(images/btn_play.png)" });

          // Clear the interval
          clearInterval(interval);
      };

      // We should statically set the first image
      navigate("next");

      // Start playing the animation
      interval = setInterval(function() {
          navigate("next");
      }, slideshowSpeed ); 
  }
    
    
    //
    // SECTION 3
    //
    // **********************************
  // 
  //  slideshow for innerpages
  //
  // **********************************

  var BGLightGallery_activeContainer=1
  var BGLightGallery_currentZindex = -2
  

  function bgLightGallery(imageclicked) {
            
      var currentImg = 0;
        var LGanimating = false;
        
        var imageindex=1;
        imageindex = imageclicked.replace("#image","");

        
      var navigateLG = function(imageindex) {
          // Check if no animation is running. If it is, prevent the action
          if (LGanimating) {
                return;
          }
           
          currentImg = imageindex;

          // Check which container we need to use
          var currentContainer = BGLightGallery_activeContainer;
          
          if (BGLightGallery_activeContainer == 4) {
              BGLightGallery_activeContainer = 1;
          } else  {
              BGLightGallery_activeContainer++;
          }
          
          showImageLG(RoomImages[currentImg - 1], currentContainer, BGLightGallery_activeContainer);
            
      };
      

      var showImageLG = function(photoObject, currentContainer, activeContainer) {

             LGanimating = true;

          // Make sure the new container is always on the background
          var currentZindex = BGLightGallery_currentZindex--;
          
          // Set the background image of the new active container
          $("#headerimg" + activeContainer).css({
              "background-image": "url(" + photoObject.image + ")",
              "display": "none",
              "z-index": currentZindex
          });
            //turn on slowly for portrait -> landscape transition
            $("#headerimg" + activeContainer).fadeIn(300);

            //turn off caption fade
            if (photoObject.firstline=='empty'){
                $('#caption-outer').hide();
            }
            else
            {         
              $('#caption-outer').show();
              $("#captioninner").css({"display" : "none"});
            $("#captioninner").html(photoObject.firstline);
            } 


          // Fade out the current container
          // and display the header text when animation is complete
          $("#headerimg" + currentContainer).fadeOut(1000,function() {
              setTimeout(function() {
                   $("#captioninner").css({"display" : "block"});
              LGanimating = false;
                  
              });
          });
      };

      // navigate to correct image
      navigateLG(imageindex);
       
  }
  
  function issmallscreen() {
      var bReturnvalue = false;
      if ($(window).height() < 685) {

          if (!(isiPad())) {
              bReturnvalue = true;
          }
      }
      return bReturnvalue;
  }
  
  function isiPad() {
      return (navigator.platform.indexOf("iPad") != -1);
  }

  function isiPhone() {
      return (
        (navigator.platform.indexOf("iPhone") != -1) ||
        (navigator.platform.indexOf("iPod") != -1)
    );
  }
  
  // booking widget
var wired = false;
var loading = false;
var checkTimer;

$(document).ready(function() {
    initWidget();
});

function initWidget() {
    // load the jquery ui date picker script if it is not already loaded
    $("#synxislink").mouseenter(function(e) {
        // wire in the date picker if it is not already set
        bookNowInit();

    });
    // function to show/hide widget on click of reservations link
    $("#synxislink").click(function(e) {
        e.preventDefault();
        // wire in the date picker if it is not already set
        $("#synxiswidget").slideToggle("slow");
        // bookNowInit();

    });


}

//booking panel functions
function bookNowInit() {
    if (!loading) {
    if (typeof ($.datepicker) === "undefined") {
        $("head").append('<script src="/BallyFinJS/jquery-datepicker.js" type="text/javascript"></script>');
        $("head").append('<link href="/BallyFinCSS/jquery-ui.css" rel="stylesheet" type="text/css" />');
            loading = true;
        setTimeout(bookWire, 60000);
        checkTimer = setInterval(checkForPicker, 50);

    }
    else {

        bookWire();
        }
    }
}

function checkForPicker() {
        var checkDatepicker = (typeof ($.datepicker) === "undefined");
        if ((wired == false) && (checkDatepicker == false)) {
            clearInterval(checkTimer);
            bookWire();
        }
}

function bookWire() {
    if (!wired) {
        wired = true;
        $(function() {
            $("#startdate").datepicker({ minDate: 0, showOn: 'both', buttonImage: '/images/booking_calendar.png', buttonImageOnly: true, altField: '#startdate', altFormat: 'mm/dd/yy', prevText: '&laquo;&laquo;', nextText: '&raquo;&raquo;' });
            $('#ui-datepicker-div').css('clip', 'auto !important'); 
            $('.ui-helper-hidden-accessible').css( { "position": "absolute !important", "top": "-99999999px" });
            $('#ui-datepicker-div').removeClass('ui-helper-hidden-accessible'); 
            $("A#widgetavailability").click(function(e) {
                e.preventDefault();
                var linkSrc = $(this).attr("href");
                var arriveDate = $("#startdate").val();
                var tmpDate = new Date($.datepicker.parseDate("mm/dd/yy", arriveDate));
                tmpDate.setDate(tmpDate.getDate() + parseInt($("#nights").val(), 10));
                var tmpMon = tmpDate.getMonth() + 1; if (tmpMon < 10) { tmpMon = "0" + tmpMon; }
                var tmpDay = tmpDate.getDate(); if (tmpDay < 10) { tmpDay = "0" + tmpDay; }
                var departDate = tmpMon + "/" + tmpDay + "/" + tmpDate.getFullYear();
                var adults = $("#adults").val();
                //build redirect string
                var redirectString = "";
                var offerCode = "";
                redirectString = linkSrc + "&arrive=" + arriveDate + "&depart=" + departDate + "&adult=" + adults + offerCode + "&start=availresults"; // "&promo=" +
                // alert(redirectString);
                window.open(redirectString);
                // return false;
            });

        });
    }

}


// RezTrack begins
 var ref = escape(document.referrer);
 var Qstring = '?cid=53633&ref='+ ref;
 var roiTrack = '<img src="https://reztrack.com/roi/' + Qstring;
 var roiGo =  roiTrack+ '"  height="0" width="0">';
 document.write(roiGo);

// RezTrack ends
