﻿/**
 * Description: general javascript actions and functions that should be present at all times
 * User: António Ramos
 * Date: 14/July/2011
 **/

var bol_animateRestaurantImages = false,
    int_actualMainContentDivWidth = 0,
    int_paragraphWidth = 0,
    bol_animateToVisitClose = false;

$( function() {

  $.supersized( {

    // Functionality
    start_slide:      1,      // Start slide (0 is random)
    new_window:       1,      // Image links open in new window/tab
    image_protect:    1,      // Disables image dragging and right click with Javascript
    slide_links: "name",
    slideshow:        1,
    slide_interval:   6000,    // Length between transitions
    transition:       1,       // 0-None, 1-Fade, 2-Slide Top, 3-Slide Right, 4-Slide Bottom, 5-Slide Left, 6-Carousel Right, 7-Carousel Left
    transition_speed: 1000,    // Speed of transition
    keyboard_nav            :   1,      // Keyboard navigation on/off


    // Size & Position
    min_width:         0,      // Min width allowed (in pixels)
    min_height:        0,      // Min height allowed (in pixels)
    vertical_center:   1,      // Vertically center background
    horizontal_center: 1,      // Horizontally center background
    fit_always:        0,      // Image will never exceed browser width or height (Ignores min. dimensions)
    fit_portrait:      1,      // Portrait images will not exceed browser height
    fit_landscape:     0,      // Landscape images will not exceed browser width

    // Components
    slides:            arr_imgPath    // Slideshow Images

  } );

  /* Supersized Fix for pages with only 2 background images with vertical align */
  setTimeout( function() {
    if ( $( "ul#supersized li" ).length == 2 ) {
      $( "ul#supersized" ).find( "li:last>a:first-child" ).remove();
    }
  } , 4000 )


  $( "#controls-wrapper" ).appendTo( "#mainContentDiv" );

  selectLanguage( str_inputLang );
  onLoadCreateDatePicker();
  onLoadCreateSubMenus();
  onLoadAnimateHighlightBar();
  changeGalleryImageThumb();

  $( ".highlightPromotion img, .designHotels a, ul.scroll-content li" ).hover(
      function() {
        $( this ).stop().animate( {"opacity": "0.5"} , "slow" );
      } ,
      function() {
        $( this ).stop().animate( {"opacity": "1"} , "slow" );
      } );

  /* anchor on li of News List */
  $( "ul.promotionsList li" ).each( function() {
    $( this ).click( function() {
      var str_urlNews = $( this ).find( "a" ).attr( "href" );
      window.location = str_urlNews;
    } )
  } )

  $( "#galleryDiv" ).parents( ".paragraph" ).css( "margin" , "0" );
  $( "#galleryDiv" ).parents( ".paragraph" ).css( "width" , "100%" );
  $( "#galleryDiv" ).parents( "#bottomContent" ).css( "padding" , "0" );
  $( "#galleryDiv" ).parents( "#bottomContent" ).find( "#bottomContentDiv" ).css( "display" , "block" );

  if (getBrowserUserAgentsInfo('platformName') != 'iPad' && getBrowserUserAgentsInfo('platformName') != 'iPhone' && getBrowserUserAgentsInfo('platformName') != 'iPod') {
    showHideGalleryHover();
  }else{
    hoverScrollGallery();
  }

  onLoadAnimationBottomContent();
  onLoadAnimationMainContent();
  onLoadToVisitBox();
  onLoadIpadFixPosition();
} );

/* function that change background image of the page when clicked on thumbnail. It calls the api of supersized */
function changeGalleryImageThumb() {
  $( "ul#gallery li img" ).click( function() {

    int_index = $( this ).parent().index();
    int_targetSlide = int_index + 1;
    api.goTo( int_targetSlide );
  } );
}

/* function to copy Email value of input on form submit */
function copyEmailToNameNewsletter(parId) {
  $( "#AccessUserName_" + parId ).val( $( "#AccessUserEmail_" + parId ).val() );
}

/* function that create and update clock of the weather section (this function is executed every second) */
function dayAndHourWeatherSection() {
  var dat_currentTime = new Date(),
      dat_currentHours = dat_currentTime.getHours(),
      dat_currentMinutes = dat_currentTime.getMinutes(),
      dat_currentSeconds = dat_currentTime.getSeconds();

  dat_currentMinutes = ( dat_currentMinutes < 10 ? "0" : "" ) + dat_currentMinutes; // add a 0 on minutes < 10
  dat_currentHours = ( dat_currentHours < 10 ? "0" : "" ) + dat_currentHours; // add a 0 on hours < 10
  dat_currentSeconds = ( dat_currentSeconds < 10 ? "0" : "" ) + dat_currentSeconds; // add a 0 on seconds < 10

  var dat_currentTimeString = dat_currentHours + ":" + dat_currentMinutes + ":" + dat_currentSeconds;

  $( "#clock" ).html( dat_currentTimeString );
}

/* check if date is valid, return true or false */
function isValidDate(string) {
  var arr_partsDate = string.split( '/' ),
      str_year = arr_partsDate[2], str_month = arr_partsDate[1], str_day = arr_partsDate[0],
    // Assume not leap year by default (note zero index for Jan)
      arr_daysInMonth = [31,28,31,30,31,30,31,31,30,31,30,31];

  // If evenly divisible by 4 and not evenly divisible by 100,
  // or is evenly divisible by 400, then a leap year
  if ( (!(str_year % 4) && str_year % 100) || !(str_year % 400) ) {
    arr_daysInMonth[1] = 29;
  }
  return str_day <= arr_daysInMonth[--str_month]
}

/* Hover Scroll Function called in showHideGalleryHover() */
function hoverScrollGallery() {

  var $obj_div = $( 'div#galleryDiv' ),
      $obj_ul = $( 'ul#gallery' ),
    // unordered list's left margin
      int_ulPadding = 0,
      int_divWidth = $obj_div.width(), //Get menu width
      $obj_lastLi = $obj_ul.find( 'li:last-child' ); //Find last image container

  //Remove scrollbars
  $obj_div.css( {overflow: 'hidden'} );

  //alert(getBrowserUserAgentsInfo('platformName')) // osName // platformName // platformOrientation // browserName // browserVersion

  if(getBrowserUserAgentsInfo('platformName') != 'iPad' && getBrowserUserAgentsInfo('platformName') != 'iPhone' && getBrowserUserAgentsInfo('platformName') != 'iPod'){

    //When user move mouse over menu
    $obj_div.mousemove( function(e) {

      //as images are loaded ul width increases,
      //so we recalculate it each time
      var int_ulWidth = $obj_lastLi[0].offsetLeft + $obj_lastLi.outerWidth() + int_ulPadding,
          int_left = (e.pageX - $obj_div.offset().left) * (int_ulWidth - int_divWidth) / int_divWidth;

      $obj_div.scrollLeft( int_left );

    } );

  }else{

    /// Touch Move

    $obj_div.bind( 'touchmove' , function(e) {
      e.preventDefault();

      var obj_touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0],
          obj_elm = $( this ).offset(),
          num_x = obj_touch.pageX - obj_elm.left,
          num_y = obj_touch.pageY - obj_elm.top;

      if ( num_x < $( this ).width() && num_x > 0 ) {
        if ( num_y < $( this ).height() && num_y > 0 ) {

          var int_ulWidth = $obj_lastLi[0].offsetLeft + $obj_lastLi.outerWidth() + int_ulPadding,
          int_left = (obj_touch.pageX - $obj_div.offset().left) * (int_ulWidth - int_divWidth) / int_divWidth;

          $obj_div.scrollLeft( int_left );

        }
      }

    } );

  }
}



function getBrowserUserAgentsInfo(str_info) {

  var obj_clientInformation = {
        str_OSName:null,
        str_platformName:navigator.platform,
        str_platformOrientation:null,
        str_browserName:null,
        str_browserVersion:$.browser.version
      },
      str_outInfo;


  // Get the Operating System

  if ( navigator.appVersion.indexOf( "Win" ) != -1 ) obj_clientInformation.str_OSName = "Windows";
  if ( navigator.appVersion.indexOf( "Mac" ) != -1 ) obj_clientInformation.str_OSName = "MacOS";
  if ( navigator.appVersion.indexOf( "X11" ) != -1 ) obj_clientInformation.str_OSName = "UNIX";
  if ( navigator.appVersion.indexOf( "Linux" ) != -1 ) obj_clientInformation.str_OSName = "Linux";

  // Get the Browser Name

  jQuery.each( jQuery.browser , function(i , val) {
    obj_clientInformation.str_browserName = i;
    return false
  } );

  // Get the iPad Orientation

  if ( obj_clientInformation.str_platformName == 'iPad' ) {
    var orientation = window.orientation;
    if ( orientation === 0 ) {
      obj_clientInformation.str_platformOrientation = 'portrait';
    } else if ( orientation === 90 ) {
      obj_clientInformation.str_platformOrientation = 'landscape';
    } else if ( orientation === -90 ) {
      obj_clientInformation.str_platformOrientation = 'landscape';
    } else if ( orientation === 180 ) {
      obj_clientInformation.str_platformOrientation = 'portrait';
    }
    window.onorientationchange = function() {
      orientation = window.orientation;
      if ( orientation === 0 ) {
        obj_clientInformation.str_platformOrientation = 'portrait';
      } else if ( orientation === 90 ) {
        obj_clientInformation.str_platformOrientation = 'landscape';
      } else if ( orientation === -90 ) {
        obj_clientInformation.str_platformOrientation = 'landscape';
      } else if ( orientation === 180 ) {
        obj_clientInformation.str_platformOrientation = 'portrait';
      }
      //alert(obj_clientInformation.str_OSName +' | '+obj_clientInformation.str_platformName +' | '+obj_clientInformation.str_browserName +' | '+obj_clientInformation.str_browserVersion + ' | '+obj_clientInformation.str_platformOrientation)
    }
  }


  str_info = str_info.toLowerCase();

  switch(str_info){
    case 'osname':
      str_outInfo = obj_clientInformation.str_OSName;
      break;
    case 'platformname':
      str_outInfo = obj_clientInformation.str_platformName;
      break;
    case 'platformorientation':
      str_outInfo = obj_clientInformation.str_platformOrientation;
      break;
    case 'browsername':
      str_outInfo = obj_clientInformation.str_browserName;
      break;
    case 'browserversion':
      str_outInfo = obj_clientInformation.str_browserVersion;
      break;
    default:
      str_outInfo = obj_clientInformation;
  }

  return str_outInfo;

}





/* function that on load animate bottom content */
function onLoadAnimationBottomContent() {

  if ( $( "#bottomContent" ).length > 0 ) {

    var int_heightBottomContent = $( "#bottomContentDiv" ).outerHeight( true ),
        int_widthBottomContentParagraph = $( "#bottomContent>div" ).not( ".withSubMenu" ).find( ".paragraph" ).outerWidth( true ),
        int_numberParagraphBottomContent = $( "#bottomContentDiv .paragraph" ).length;

    /* Fadeout toVisitBox if bottomContent has content */
    if ( $( "#bottomContentDiv>div" ).length > 0 ) {
      $( "#toVisit" ).fadeOut();
    }

    /* IE 7 Fix (margin: 0 auto) need width */
    if ( $.browser.msie && $.browser.version.substr( 0 , 1 ) <= 7 ) {
      if ( $( "#bottomContent>div" ).not( ".withSubMenu" ).outerWidth( true ) ) {
        $( "#bottomContentDiv" ).css( {"width": (int_widthBottomContentParagraph + 35) * int_numberParagraphBottomContent + "px" } )
      }
    }

    $( "#bottomContentDiv" ).css( {"bottom" : "-" + int_heightBottomContent + "px"} )
    $( "#bottomContent" ).css( "bottom" , "-" + int_heightBottomContent + "px" );

    setTimeout( function() {
      $( "#bottomContent" ).animate( {"bottom": "28px"} );
    } , 500 )

    $( "ul.pageLevel1 a, ul.pageLevel2 a" ).click( function() {
      var $obj_pageLevelAnchors = this;
      if ( !$obj_pageLevelAnchors.hasAttribute( "target" ) ) {

        $( "#bottomContent" ).animate( {"bottom": "-" + int_heightBottomContent + "px"} , function() {
          location.href = $obj_pageLevelAnchors.href;
        } );
        return false;
      }
    } );
  }
}

/* function that animates the highlight bar on left column */
function onLoadAnimateHighlightBar() {
  $( "#leftColumnContent .highlightBar" ).stop().hover( function() {
    $( this ).stop().animate( {
      backgroundColor:"#FFF201"
    } )
    $( this ).find( "span" ).stop().animate( {
      color:"#B76F11"
    } )
  } , function() {
    $( this ).stop().animate( {
      backgroundColor:"#B76F11"
    } )
    $( this ).find( "span" ).stop().animate( {
      color:"#FFF201"
    } )
  } )
}

/* function that animates the content of mainContent */
function onLoadAnimationMainContent() {

  var bol_sectionLocation = $( "#mapGoogleHotelTeatro" ).length,
      bol_sectionRestaurant = $( "#restaurantBarList" ).length;

  setTimeout( function() {
    $( "#mainContent" ).css( {"top":"145px"} )
  } , 200 )

  if ( !bol_sectionLocation ) {
    $( "#mainContent .paragraph" ).each( function(index) {
      $( this ).css( {"z-index":100 - index,"margin-left":"-" + $( this ).outerWidth( true ) + "px"} );
      /*$( this ).find( ".paragraphText" ).css( {"height":$( "#menuBar" ).height() + 2 + "px"} )*/
    } );

    $( "#mainContent .paragraph" ).each( function(index) {
      $( this ).delay( index * 1000 ).animate( {"margin-left":"0"} , 1000 );
    } );
  }
  else {

  }
}

/* This function is called when form newsletter is submitted */
function onLoadAjaxNewsletter(int_parID , type) {

  var str_inputEmail = $( "#AccessUserEmail_" + int_parID ).val(),
      str_inputName = $( "#AccessUserName_" + int_parID ).val();

  if ( type == "subscribe" ) {
    var str_dataString = "IsPostBack=True&" + int_categoryID + "=on&AccessUserName=" + str_inputName + "&AccessUserEmail=" + str_inputEmail + "&Submit=OK";
  } else if ( type == "unSubscribe" ) {
    var str_dataString = "IsPostBack=True&AccessUserEmail=" + str_inputEmail + "&Submit=OK";
  }

  if ( str_inputEmail == '' ) {
    $( '.insertEmail' ).html( str_mandatoryField );
    return false;
  }
  else if ( validateEmail( str_inputEmail ) == 0 ) {
    $( '.insertEmail' ).html( str_emailNotValid );
    return false;
  }
  else {

    $.ajax( {
      url: location.protocol + "//" + location.hostname + int_PageID,
      data:str_dataString,
      type:"POST",
      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;

        if ( type == "subscribe" ) {
          $( '.insertEmail' ).html( str_successMessage );
        } else if ( type == "unSubscribe" ) {
          $( '.insertEmail' ).html( str_successUnSubscribeMessage );
        }
      }
    } );
    return false;
  }
}

/* function that initialize and change datepicker options and dates */
function onLoadCreateDatePicker() {

  /* get actual Date */
  var dat_date = new Date(),
      str_arrive = dat_date.getDate() + '/' + (dat_date.getMonth() + 1) + '/' + dat_date.getFullYear(),
      str_depart = (dat_date.getDate() + 1) + '/' + (dat_date.getMonth() + 1) + '/' + dat_date.getFullYear(); // set date dd+1 / mm / yyyy


  if ( !isValidDate( str_depart ) ) {
    str_depart = 01 + '/' + (dat_date.getMonth() + 2) + '/' + dat_date.getFullYear(); // set date 1 / mm+1 / yyyy
  }

  $( "#arrive" ).val( str_arrive );
  $( "#depart" ).val( str_depart );

  /* initialize the datePicker on #depart */
  $( "#depart" ).datepicker( {
    showOn: "button",
    dateFormat:"dd/mm/yy",
    buttonImage: "/Files/Templates/Designs/HotelTeatro/images/datepicker.png",
    buttonImageOnly: true,
    hideIfNoPrevNext: true
  } );

  /* initialize the datePicker on #arrive. When changed, changes date of #depart */
  $( "#arrive" ).datepicker( {
    showOn: "button",
    dateFormat:"dd/mm/yy",
    buttonImage: "/Files/Templates/Designs/HotelTeatro/images/datepicker.png",
    buttonImageOnly: true,
    hideIfNoPrevNext: true,
    onSelect:function() {
      var dat_date2 = $( this ).datepicker( 'getDate' , '+1d' );
      dat_date2.setDate( dat_date2.getDate() + 1 );

      $( "#depart" ).datepicker( "setDate" , dat_date2 );
      $( "#depart" ).datepicker( "option" , "minDate" , dat_date2 );
    }
  } );

  /* set the minDate of datepickers */
  $( "#arrive" ).datepicker( "option" , "minDate" , str_arrive );
  $( "#depart" ).datepicker( "option" , "minDate" , str_depart );
}

/* Create Map of Porto in section Localization */
function onLoadCreatePortoMap() {

  var arr_centerMap = [49,46],
      int_leftPosition = 0,
      int_topPosition = 0;

  $( ".mapPoint img[title]" ).tooltip();

  $( "#mapPorto" ).parents( "#mainContent" ).css( "position" , "static" );

  $( ".mapPoint" ).hover( function() {
        $( this ).find( ".pointerImg" ).attr( "src" , "/Files/Templates/Designs/HotelTeatro/images/points.png" );
        $( this ).find( ".pointName p" ).animate( {"opacity":"0.6"} );
      } , function() {
        $( this ).find( ".pointerImg" ).attr( "src" , "/Files/Templates/Designs/HotelTeatro/images/points2.png" );
        $( this ).find( ".pointName p" ).animate( {"opacity":"1"} );
      }
  );

  /*add the funcionality on hover text do the img hover */
  $( ".mapPoint .pointName" ).hover( function() {
    $( this ).parent().find( ".pointerImg" ).mouseenter();
  } , function() {
    $( this ).parent().find( ".pointerImg" ).mouseleave();
  } );

  $( ".mapPoint" ).each( function() {

    int_leftPosition = ($( this ).find( ".pointX" ).text() * arr_centerMap[0] / 100) + arr_centerMap[0];
    int_topPosition = ($( this ).find( ".pointY" ).text() * -arr_centerMap[1] / 100) + arr_centerMap[1];

    $( this ).css( {"left":int_leftPosition + "%","top":int_topPosition + "%"} );

  } )
}

/* function that create menu of page Press */
function onLoadCreateSubMenus() {
  var num_paragraphHeaders = $( "h2.paragraphHeader" ).length,
      str_subMenu = '<ul id="menuArticles">',
      str_paragraphHeader;

  str_paragraphHeader = $( "h2.paragraphHeader:first" ).html();
  $( "h2.paragraphHeader" ).each( function(i) {
    str_subMenu += '<li id="link_' + $( this ).parent().attr( "id" ) + '"><a href="javascript:void(0)" ' +
                   'onclick="updateParagraph(' + "'" + $( this ).parent().attr( "id" ) + "'" + ')">' + $( this ).text() +
                   '</a></li>';
  } );

  if ( num_paragraphHeaders > 1 ) {
    str_subMenu += '</ul>';
    $( "#bottomContentDiv" ).prepend( str_subMenu );
    $( "#bottomContentDiv" ).addClass( "withSubMenu" );

    setTimeout( function() {
      $( ".menuArticles" ).css( "display" , "none" );
      $( ".menuArticles:first" ).css( "display" , "block" );
    } , 1 );

    $( "#bottomContentDiv li:eq(0)" ).addClass( "activeItem" );
    $( "h1" ).html( str_paragraphHeader );
    $( "h2.paragraphHeader" ).addClass( "displayNone" );
  }
  else {
    // DO NOTHING
  }
}

/* function onLoad to format Contact Section */
function onLoadFormatContactSection() {
  $( "#mainContent" ).find( ".paragraphText" ).addClass( "paragraphMap" );
  $( "#mainContent" ).find( ".paragraph" ).css( "background" , "0 none" );
}

/* function that fixes the position fixed of ipad */
function onLoadIpadFixPosition() {
  if ( navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod' ) {
    $( "#footer,#toVisit" ).css( {
      position:'absolute !important',
      display:'none'
    } );
  
    window.onload = function(){
       document.getElementById( 'footer' ).style.top =
      (window.pageYOffset + window.innerHeight - 25) + 'px';
      document.getElementById( 'toVisit' ).style.top=
      (window.pageYOffset + window.innerHeight - 40) + 'px';
      
    };

    window.onscroll = function() {
   document.getElementById( 'footer' ).style.top =
      (window.pageYOffset + window.innerHeight - 25) + 'px';
      document.getElementById( 'toVisit' ).style.top =
      (window.pageYOffset + window.innerHeight - 40) + 'px';
    };

     $( "#footer,#toVisit" ).css( {    
      display:'block'
    } );
    
  };
}

/* function called on window ready of map City */
function onLoadMapCity() {
  $( 'html,body' ).css( { 'height':"100%","overflow":"hidden"} );

  $( "head" ).append( "<style type='text/css'>.tooltip {background-color: transparent !important;}</style>" );

  $( "#localizationMenu a" ).removeAttr( "href" );
  $( ".panning img[title]" ).tooltip().mousemove(
      function(e) {

        //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
        $( '.tooltip' ).css( 'top' , e.pageY - 25 );
        $( '.tooltip' ).css( 'left' , e.pageX + 15 );

      } );

   $( ".panning img[title]" ).bind( 'touchmove' , function(e) {
      e.preventDefault();

      var obj_touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0],
          obj_elm = $( this ).offset(),
          num_x = obj_touch.pageX - obj_elm.left,
          num_y = obj_touch.pageY - obj_elm.top;

      if ( num_x < $( this ).width() && num_x > 0 ) {
        if ( num_y < $( this ).height() && num_y > 0 ) {

          //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
          $( '.tooltip' ).css( 'top' , obj_touch.pageY - 25 );
          $( '.tooltip' ).css( 'left' , obj_touch.pageX + 15 );

        }
      }

    } );

  $outer_container = $( "#outer_container" );
  $imagePan_panning = $( "#imagePan .panning" );
  $imagePan = $( "#imagePan" );
  $imagePan_container = $( "#imagePan .container" );

  $outer_container.css( "top" , ($( window ).height() - ($outer_container.outerHeight())) / 2 );
  $imagePan_panning.css( "margin-top" , ($imagePan.height() - $imagePan_panning.height()) / 2 + "px" );

  containerWidth = $imagePan.width();
  containerHeight = $imagePan.height();

  totalContentW = $imagePan_panning.width();
  totalContentH = $imagePan_panning.height();

  $imagePan_container.css( "width" , totalContentW ).css( "height" , totalContentH );

  function MouseMove(e) {
    var mouseCoordsX = (e.pageX - $imagePan.offset().left) + 800,
        mouseCoordsY = (e.pageY - $imagePan.offset().top),
        mousePercentX = mouseCoordsX / containerWidth,
        mousePercentY = mouseCoordsY / containerHeight,
        destX = -(((totalContentW - (containerWidth)) - containerWidth) * (mousePercentX)),
        destY = -(((totalContentH - (containerHeight)) - containerHeight) * (mousePercentY)),
        thePosA = mouseCoordsX - destX,
        thePosB = destX - mouseCoordsX,
        thePosC = mouseCoordsY - destY,
        thePosD = destY - mouseCoordsY,
        marginL = $imagePan_panning.css( "marginLeft" ).replace( "px" , "" ),
        marginT = $imagePan_panning.css( "marginTop" ).replace( "px" , "" ),
        animSpeed = 500, //ease amount
        easeType = "easeOutCirc";
    if ( mouseCoordsX > destX || mouseCoordsY > destY ) {
      //$imagePan_container.css("left",-thePosA-marginL); $imagePan_container.css("top",-thePosC-marginT); //without easing
      $imagePan_container.stop().animate( {left: -thePosA - marginL, top: -thePosC - marginT} , animSpeed , easeType ); //with easing
    } else if ( mouseCoordsX < destX || mouseCoordsY < destY ) {
      //$imagePan_container.css("left",thePosB-marginL); $imagePan_container.css("top",thePosD-marginT); //without easing
      $imagePan_container.stop().animate( {left: thePosB - marginL, top: thePosD - marginT} , animSpeed , easeType ); //with easing
    }
    else {
      $imagePan_container.stop();
    }
  }

  function MouseTouch(touchX,touchY) {
    var mouseCoordsX = (touchX - $imagePan.offset().left) + 800,
        mouseCoordsY = (touchY - $imagePan.offset().top),
        mousePercentX = mouseCoordsX / containerWidth,
        mousePercentY = mouseCoordsY / containerHeight,
        destX = -(((totalContentW - (containerWidth)) - containerWidth) * (mousePercentX)),
        destY = -(((totalContentH - (containerHeight)) - containerHeight) * (mousePercentY)),
        thePosA = mouseCoordsX - destX,
        thePosB = destX - mouseCoordsX,
        thePosC = mouseCoordsY - destY,
        thePosD = destY - mouseCoordsY,
        marginL = $imagePan_panning.css( "marginLeft" ).replace( "px" , "" ),
        marginT = $imagePan_panning.css( "marginTop" ).replace( "px" , "" ),
        animSpeed = 500, //ease amount
        easeType = "easeOutCirc";
    if ( mouseCoordsX > destX || mouseCoordsY > destY ) {
      //$imagePan_container.css("left",-thePosA-marginL); $imagePan_container.css("top",-thePosC-marginT); //without easing
      $imagePan_container.stop().animate( {left: -thePosA - marginL, top: -thePosC - marginT} , animSpeed , easeType ); //with easing
    } else if ( mouseCoordsX < destX || mouseCoordsY < destY ) {
      //$imagePan_container.css("left",thePosB-marginL); $imagePan_container.css("top",thePosD-marginT); //without easing
      $imagePan_container.stop().animate( {left: thePosB - marginL, top: thePosD - marginT} , animSpeed , easeType ); //with easing
    }
    else {
      $imagePan_container.stop();
    }
  }

  $imagePan_panning.css( "margin-left" , ($imagePan.width() - $imagePan_panning.width()) / 2 ).css( "margin-top" , ($imagePan.height() - $imagePan_panning.height()) / 2 );

  if(getBrowserUserAgentsInfo('platformName') != 'iPad' && getBrowserUserAgentsInfo('platformName') != 'iPhone' && getBrowserUserAgentsInfo('platformName') != 'iPod'){

    $imagePan.bind( "mousemove" , function(event) {
      MouseMove( event );
    } );

  }else{

    $imagePan.bind( 'touchmove' , function(e) {
      e.preventDefault();

      var obj_touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0],
          obj_elm = $( this ).offset(),
          num_x = obj_touch.pageX - obj_elm.left,
          num_y = obj_touch.pageY - obj_elm.top;

      if ( num_x < $( this ).width() && num_x > 0 ) {
        if ( num_y < $( this ).height() && num_y > 0 ) {
          MouseTouch( obj_touch.pageX, obj_touch.pageY );
        }
      }

    } );

  }


}

/* function onLoad on section restaurantBar */
function onLoadRestaurantBar() {
  /* remove background and border of paragraph */
  $( "#restaurantBarList" ).parents( ".paragraph" ).css( {"background" : "none", "border":"0 none","position":"relative" } );

  setTimeout( function() {
    $( "#restaurantBarList" ).parents( "#mainContentDiv" ).css( {"overflow" : "visible"} );
    $( "#restaurantBarList" ).parents( "#mainContent" ).css( {"overflow" : "visible"} );
  } , 1000 );

  $( ".promocaoField a" ).click( function() {

    var str_classParent = $( this ).parents( "li" ).attr( "class" );

    $( ".productListDescription" ).hide();

    str_classParent = str_classParent.split( "_" );
    str_classParent = str_classParent[1].split( " " );

    var int_offsetLeft = $( ".restaurantBarListItem_" + str_classParent ).offset().left;
    $( ".productLongDescription_" + str_classParent ).css( "display" , "block" );
    $( ".productLongDescription_" + str_classParent ).css( "left" , int_offsetLeft - 42 + "px" );

    $( '.scroll-pane' ).jScrollPane();

    setTimeout(function(){
      $( ".jspPane" ).css( {"width":"417px"} )
    },1000)
  } );

  $( ".withImage:last" ).css( "clear" , "left" );
  $( ".withImage:last" ).css( "margin-left" , $( "#restaurantBarList:last" ).offset().left - 42 + "px" );

  $( ".closeDivRestaurant" ).click( function() {
    $( this ).parents( ".productListDescription" ).css( "display" , "none" );
  } );

  setInterval( function() {
    if ( vars.in_animation ) {
      $( ".withImage img" ).each( function() {
        if ( !bol_animateRestaurantImages ) {
          $( this ).animate( {"opacity":"0"} , "800" );
          bol_animateRestaurantImages = true;
        }
        else {
          $( this ).animate( {"opacity":"1"} , "800" );
          bol_animateRestaurantImages = false;
        }
      } );
      vars.in_animation = false
    }
  } , 500 );
}

/* function that create the animation of the visit box*/
function onLoadToVisitBox() {

  var toVisitHeight = $( "#toVisit .textVisit" ).outerHeight( true );
  
  $( ".titleVisit" ).click( function() {

    setTimeout( function() {
      if ( navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod' ) {
       $( "#toVisit" ).animate( { "top" :  (window.pageYOffset + window.innerHeight) - toVisitHeight  + "px" } );
       $( "#toVisit" ).css( { "height" :  toVisitHeight + "px" } );
      }else{
       $( "#toVisit" ).animate( { "height" :  toVisitHeight + 15 + "px" } );
      }
      $( "#toVisit" ).find( ".textVisit" ).css( "display" , "block" );      
      
    } , 1000 );

    $( this ).animate( {
      "color":"#343434"
    } , "slow" );
    $( this ).parents( "#toVisit" ).animate( {
      "backgroundColor":"#AEB4A1"
    } , "slow" );

    bol_animateToVisitClose = true;

  } );

  $( ".closeToVisit" ).click( function() {

    setTimeout( function() {
      if ( navigator.platform == 'iPad' || navigator.platform == 'iPhone' || navigator.platform == 'iPod' ) {
        $( "#toVisit" ).animate( { "top" :  (window.pageYOffset + window.innerHeight - 40) + 'px' } );
      }
      $( "#toVisit" ).animate( { "height" : "15px" } , function() {
        bol_animateToVisitClose = false;
      } );      
      $( "#toVisit" ).find( ".textVisit" ).css( "display" , "none" );
    } , 1000 );

    return false;
  } );

  $( "#toVisit" ).hover( function() {
    if ( !bol_animateToVisitClose ) {
      $( this ).find( ".titleVisit" ).stop().animate( {
        "color":"#AEB4A1"
      } , "slow" );
      $( this ).stop().animate( {
        "backgroundColor":"#333333"
      } , "slow" );
    }
  } , function() {

    if ( !bol_animateToVisitClose ) {
      $( this ).find( ".titleVisit" ).stop().animate( {
        "color":"#343434"
      } , "slow" );
      $( this ).stop().animate( {
        "backgroundColor":"#AEB4A1"
      } , "slow" );
    }
  } );
}

/* function that onLoad call this function */
function onLoadNewsletter() {
  $( "#newsletterSubscribe #Submit" ).click( function() {
    onLoadAjaxNewsletter( int_parID , "subscribe" );
  } )

  $( "#newsletterSubscribe #submitUnSubscribe" ).click( function() {
    onLoadAjaxNewsletter( int_parID , "unSubscribe" );
  } )
}

/* append the date on weather section */
function onLoadWeatherSection() {

  dayAndHourWeatherSection();

  $( "#dateWeather" ).prepend( "<span class='currentDate'>" + str_dateShortDayName + ", " + str_dateDay + " " + str_dateMonthShortName + "</span>" );

  setInterval( function() {
    dayAndHourWeatherSection();
  } , 1000 )
}

/* function that creates the animation, slide images and rooms  */
function onLoadRoomGallery() {

  /* remove href attribute of first li anchor (number 74) */
  $( "ul#productList li" ).eq( 0 ).find( "a" ).removeAttr( "href" );

  /* change the opacity of button nextRoom */
  $( ".nextRoom" ).css( {"opacity":"0.6"} );

  $( ".nextRoom" ).hover( function() {
    $( this ).animate( { "opacity" : "1" } );
  } , function() {
    $( this ).animate( { "opacity" : "0.6" } );
  } )

  /* action of close button */
  $( "#productDescription>a" ).click( function() {
    if ( !bol_animateRooms ) {
      $( this ).parent().animate( {width:0} , "fast",function(){
        $(this).hide();
      });
      //$( this ).parent().toggle('slide');
      bol_animateRooms = true;
    }
  } )

  /* action of next button */
  $( ".nextRoom" ).click( function() {
    if ( int_nextRoom == 1 || int_nextRoom == 6 ) {
      $( "ul#productList li" ).eq( 1 ).click();
      int_nextRoom = 2;
    }
    else {
      int_nextRoom = $( "ul#productList li.activeItem" ).index() + 1;
      $( "ul#productList li" ).eq( int_nextRoom ).click();
    }
  } );

  /* action on click of the room */
  $( "ul#productList li" ).click( function() {
    $( "ul#productList li" ).removeClass();
    if ( bol_animateRooms ) {
      $( "#productDescription" ).show().animate( {width:380} , "fast" );
      //$( "#productDescription" ).toggle('slide');
      bol_animateRooms = false;
    }

    var int_index = $( this ).index(),
        int_targetSlide = int_index + 1;
    if ( int_index != 0 ) {
      $( this ).addClass( "activeItem" );
      int_nextRoom = $( "ul#productList li.activeItem" ).index() + 1;
      $( "#productDescription div" ).css( "display" , "none" );
      $( "#productDescription div" ).eq( int_index ).css( { 'float':'left','display' : 'block'} );
      api.goTo( int_targetSlide ); //change the background image of the site
      if ( !vars.is_paused ) {
        vars.is_paused = true; //pause the slideshow of background image of the site
      }
    }
  } )
}

/* function onsubmit redirect to synxis Hotel url */
function onSubmitQuickBook() {
  var dat_arrive = $( "#synxis input#arrive" ).val(),
      dat_depart = $( "#synxis input#depart" ).val(),
      str_url = "https://gc.synxis.com/rez.aspx?Hotel=28169&Chain=5154&template=GCO&shell=GCO2&locale=" + str_longLang + "&src=teatro&";
  window.open( str_url + "&arrive=" + dat_arrive + "&depart=" + dat_depart );
}

/* function onLoad of called on gallery section */
function showHideGalleryHover() {

  /* Se o #mainContent for vazio, esconde a barra #mainContent */
  if ( $( "#galleryDiv" ).parents( "body" ).find( "#mainContentDiv>div" ).length == 1 ) { //lenght == 1 porque o controls-wrapper da galeria passa para o #mainContentDiv>div
    setTimeout( function() {
      $( "#menuBar" ).animate( {"top":-($( "#menuBar" ).height() + 30) + "px"} , "fast" ); // hide the menubar
    } , 500 );
  }

  if ( navigator.platform != 'iPad' || navigator.platform != 'iPhone' || navigator.platform != 'iPod' ) {

    setTimeout( function() {
      $( "#galleryDiv" ).animate( {"margin-bottom":"-67px"} , "slow" );
    } , 2500 );

    setTimeout( function() {
      hoverScrollGallery();
      $( "#galleryDiv" ).hover( function() {
        $( this ).stop().animate( {"margin-bottom":"0px"} );
      } , function() {
        $( this ).stop().animate( {"margin-bottom":"-67px"} );
      } );
    } , 3000 );

  }
}

/* function called onclick of city map */
function updateCityMap(time) {

  var str_dayDivId = $( '#contentCity>div:first' ).attr( 'id' ),
      str_nightDivId = $( '#contentCity>div:last' ).attr( 'id' );

  $( "area" ).removeClass();

  if ( time == "night" ) {
    $( "#" + str_nightDivId ).fadeIn();
    $( "#" + str_dayDivId ).fadeOut();
    $( "#imgMap #night" ).fadeIn();
    $( "#imgMap #day" ).fadeOut();
    $( "#Map area" ).eq( 1 ).addClass( "noCursor" );

  } else if ( time == "day" ) {
    $( "#" + str_nightDivId ).fadeOut();
    $( "#" + str_dayDivId ).fadeIn();
    $( "#imgMap #night" ).fadeOut();
    $( "#imgMap #day" ).fadeIn();
    $( "#Map area" ).eq( 0 ).addClass( "noCursor" );
  }
}

/* function that update paragraphs on page Press */
function updateParagraph(index) {
  str_paragraphHeader = $( "#" + index ).find( "h2.paragraphHeader" ).html();

  $( "h1" ).html( str_paragraphHeader );
  $( "h2.paragraphHeader" ).addClass( "displayNone" );
  $( ".menuArticles" ).css( "display" , "none" );
  $( "#menuArticles li" ).removeClass( "activeItem" );
  $( "#menuArticles #link_" + index ).addClass( "activeItem" );
  $( "#" + index ).fadeIn( function() {
  } );
}

/* Select Language*/
function selectLanguage(str_inputLang) {
  $( "#languageHome li a,#language li a" ).each( function() {

    var str_nameLanguage = $( this ).text(); //    IE Fix
    if ( str_nameLanguage.toLowerCase() == str_inputLang.toLowerCase() ) {
      $( this ).removeAttr( "href" );
      $( this ).parent().addClass( "languageSelected" );
    }
  } )
}
