if (window.console === undefined){
  window.console = {};
}
if(window.console.log === undefined){
  window.console.log = function(){};
}

jQuery(function($) {

  $('body').addClass('js');

  var w = $(window);

  var bgimg = $('#wrp-background img');
  if (bgimg[0].complete) {
    bgimg.fadeIn(1000);
  }
  else {
    if ($.browser.opera) {
      bgimg.css('top', '-9999px').show()
        .bind('load', function() {
          $(this).hide().css('top', '0').fadeIn(1000);
        });
    }
    else {
      bgimg.bind('load', function() {
        $(this).fadeIn(1000);
      });
    }

    // Somehow load on image rises not every time in IE9 (may be in 7 and 8 too)
    // that's why we checking it after all loaded.
    $(window).bind('load', function(){
      if ($('#wrp-background img')[0].complete && !$('#wrp-background img').is(':visible')){
        $('#wrp-background img').fadeIn();
      }
    });
  }

  w.menuSpeed = 600;

  $(".r_t a").hover(function() {
    $(".map").css('display', 'block');
    $(".r_t label").css('display', 'block');
  });

  $('select').cfe();

  if ($(".preview > ul").length == 1) {
    $(".preview").jCarouselLite({
      btnNext: ".pagination .next",
      btnPrev: ".pagination .prev",
      speed: 1200
    });
  }

  // -- padding on input from form on online-booking page
  if (navigator.appVersion.indexOf("Mac") != -1) {
    $('div.div-enter-button input.enter-button').css('padding', '4px 0 0 0');
//        $('#reservation_name, #contact, #email, #datepicker, #time, #guests').css({
//            'padding':'6px 0 0px 10px','font-size':'12px','line-height':'24px'
//        });
    $('#content .entry-content .news_img p, .entry-content-news .news_img p').css({
      'padding':'0'
    });
  }

  $("#container div.menu").hover(
    function() {

      var t_m = this.id;
      $("div.map_" + t_m).fadeIn(250);
      $(this).children('label').fadeIn(300);

      if ($(this).hasClass("m_t") || $(this).hasClass("l_b")) {
        $(this).animate({'margin-left':"20px"}, 300);
      }

      if ($(this).hasClass("l_t") || $(this).hasClass("l_b")) {
        $(this).animate({'margin-left':"20px"}, 300);
      }
      else {
        $(this).animate({'margin-right':"-20px"}, 300);
      }
      $("#content, .pagination").css('opacity', '0.65', '-moz-box-shadow', '1px 1px 2px #fff');
      $("#container div.menu").css('opacity', '0.8', '-moz-box-shadow', '1px 1px 2px #fff');

    }, function() {
      var t_m = this.id;
      $("div.map_" + t_m).fadeOut(250);

      $(this).children('label').fadeOut(300);
      $("#content, .pagination").css('opacity', '1', '-moz-box-shadow', 'none');
      $("#container div.menu").css('opacity', '0.8', '-moz-box-shadow', '1px 1px 2px #fff');

      if ( $(this).hasClass("m_t")) {
        $(this).animate({'margin-left':0}, 300);
      }

      if ($(this).hasClass("l_t") || $(this).hasClass("l_b")) {
        $(this).animate({'margin-left':0}, 300);
      }
      else {
        $(this).animate({'margin-right':0}, 300);
      }

    }
  );

  $('ul.menu li').hover(
    function() {
      $(this).addClass("hover");
    }, function() {
      $(this).removeClass('hover');
    }
  );

  $(window).bind('resize.content',
    function() {
      if ($('body').hasClass('home')) {
        /* home begin */
        main_height = $("#content").height();
        menu_lt_height = $(".menu.l_t").height();
        window_height = $(window).height();
        document_height = $(document).height();
        nav_height = $("nav").height();
        nav_margin = parseInt($("nav").css("margin-bottom"));

        content_offset = $("#content").offset();
        menu_lt_offset = $(".menu.l_t").offset();
        footer_offset = $("footer").offset();

        margin_top = (window_height - main_height) / 2;
        offset = content_offset.top - menu_lt_offset.top;
        footer_height = document_height - footer_offset.top;
        margin_top2 = parseInt(margin_top - offset - nav_height - nav_margin - footer_height);

        if (window_height > main_height) {
          $(".home #main").css("padding-top", margin_top2);
        }
        /* home end */

      }
      else if ($('body').hasClass('single')) {
        main_height = $("#main").height();
        nav_height = $("nav").height();
        nav_margin = parseInt($("nav").css("margin-bottom"));

        window_height = $(window).height();
        document_height = $(document).height();
        footer_offset = $("footer").offset();
        footer_height = document_height - footer_offset.top;

        if (window_height > main_height) {
          content_height = main_height + nav_height + nav_margin + footer_height;
          margin_top = (window_height - content_height) / 2;
          $("header").css("height", margin_top);
        }
      }
      else if ($('body').hasClass('page-id-37')) {
        main_height = $("#main_location").height();
        nav_height = $("nav").height();
        nav_margin = parseInt($("nav").css("margin-bottom"));

        window_height = $(window).height();
        document_height = $(document).height();
        footer_offset = $("footer").offset();
        footer_height = document_height - footer_offset.top;

        if (window_height > main_height) {
          content_height = main_height + nav_height + nav_margin + footer_height;
          margin_top = (window_height - content_height) / 2;
          $("header").css("height", margin_top);
        }
      }
      else {
        var main_height = $("#main").height(),
          window_height = parseInt($(window).height()),
          document_height = parseInt($(document).height()),
          footer_offset = $("footer").offset(),
          footer_height = document_height - parseInt(footer_offset.top),
          content_height, margin_top;

        if (window_height > main_height) {
          content_height = main_height + footer_height;
          $("header").css("height", (window_height - content_height) / 2);
        }
      }
    }).trigger('resize.content');

  $('#menu-footer li:last').css('border-right', 'none');

  // preload background image in popup
  $('#citibank-privilieges-popup, #overlay').show().hide();

  $('#citibank-privilieges').bind('click', function(e){
    console.log('click');
    e.preventDefault();
    var overlay = $('#overlay');
    if (overlay.length == 0){
      overlay = $('<div id="overlay"/>');
      $('body').append(overlay);
    }

    overlay.fadeIn();
    $('#citibank-privilieges-popup').fadeIn();

    overlay.height($(document).height());

    $(document).bind('keyup.citibank-close', function(e){
      if (e.keyCode == 27){
        $('#citibank-privilieges-popup, #overlay').fadeOut();
        $(document).unbind('keyup.citibank-close');
      }
    });

    $('#citibank-privilieges-popup .close-popup, #overlay').bind('click.citibank-close', function(e){
      e.preventDefault();
      $('#citibank-privilieges-popup, #overlay').fadeOut();

      $('#citibank-privilieges-popup .close-popup, #overlay').unbind('click.citibank-close');
    });
  });

});

function loadGMScript(callback) {
  callback = callback || 'gm_initialize';
  var script = document.createElement("script");
  script.type = "text/javascript";
  script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=" + callback;
  document.body.appendChild(script);
}

