$(document).ready(function() {
  // Persist navigation tab highlighting when hovering dropdown.
  var nav_bg_image = $(".main-menu .nav > ul > li > a:not(.active)").css('background-image');
  var nav_bg_hover_image = $(".main-menu .nav > ul > li > a.active").css('background-image');
  var nav_bg_color = $(".main-menu .nav > ul > li > a:not(.active)").css('background-color');
  var nav_bg_hover_color = $(".main-menu .nav > ul > li > a.active").css('background-color');

  $(".main-menu ul li ul *").hover(function() {
    $(this).parent().siblings('a:not(.active)').each(function() { setBackground(this, nav_bg_hover_image, nav_bg_hover_color) })
  }, function() {
    $(this).parent().siblings('a:not(.active)').each(function() { setBackground(this, nav_bg_image, nav_bg_color) })
  })

  $(".main-menu .nav > ul > li > a:not(.active)").hover(function() {
    setBackground(this, nav_bg_hover_image, nav_bg_hover_color)
  }, function() {
    setBackground(this, nav_bg_image, nav_bg_color)
  })

  // Subscribe Form Placeholder
	$('#subscribe-form .sign-up').each(function() {
		searchText = $(this).attr('title');

		$(this).focus(function() {
			if($(this).val()==searchText) {
				$(this).val('');
			}
		})

		$(this).blur(function() {
			if(empty($(this).val())) {
				$(this).val(searchText);
			}
		})
	})

  // Booking Form Datepicker
	$("#date").datepicker({dateFormat: 'dd/mm/yy', minDate: 0})

  $("#subscribe").change(function() { toggleInterests() });
  toggleInterests();
});

function toggleInterests() {
  if ($('#subscribe').is(':checked')) {
    $('.mailchimp_interests:input').removeAttr('disabled');
  } else {
    $('.mailchimp_interests:input').attr('disabled', true);
  }
}

function setBackground(object, image, color) {
  $(object).css({
    'background-image': image,
    'background-color': color
  })
}

function empty(str) {
	if (str === "" || str === 0 || str === "0" || str === null || str === false || typeof str === 'undefined') {
		return true;
	}
	if (typeof str == 'object') {
		var key;
		for (key in str) {
			return false;
		}
		return true;
	}
	return false;
}
