document.addEventListener('DOMContentLoaded', function (){
var formEl=document.querySelector('.lt-mailerlite-form');
if(!formEl){
return;
}
var mlLoaded=false;
function loadMailerLite(){
if(mlLoaded) return;
mlLoaded=true;
(function (w, d, e, u, f, l, n){
w[f]=w[f]||function (){
(w[f].q=w[f].q||[]).push(arguments);
};
l=d.createElement(e);
l.async=1;
l.src=u;
n=d.getElementsByTagName(e)[0];
n.parentNode.insertBefore(l, n);
})(window, document, 'script', 'https://assets.mailerlite.com/js/universal.js', 'ml');
ml('account', '840633');
}
if('IntersectionObserver' in window){
var observer=new IntersectionObserver(function (entries, obs){
entries.forEach(function (entry){
if(entry.isIntersecting){
loadMailerLite();
obs.disconnect();
}});
}, {
rootMargin: '200px 0px',
threshold: 0
});
observer.observe(formEl);
}
var scrollTriggered=false;
function onScroll(){
if(scrollTriggered) return;
var scrollY=window.scrollY||window.pageYOffset||0;
var docHeight=document.documentElement.scrollHeight - window.innerHeight;
if(docHeight > 0&&(scrollY / docHeight) > 0.3){
scrollTriggered=true;
loadMailerLite();
window.removeEventListener('scroll', onScroll);
}}
window.addEventListener('scroll', onScroll);
if(!('IntersectionObserver' in window)){
loadMailerLite();
}});
jQuery(document).ready(function($){
var $searchInput=$('#menu-search');
var $resultsContainer=$('#search-results');
if($searchInput.length&&$resultsContainer.length){
$searchInput.focus();
var currentIndex=-1;
$searchInput.on('keydown', function(e){
var $items=$resultsContainer.find('a');
if(e.key==="ArrowDown"||e.key==="ArrowUp"){
e.preventDefault();
if($items.length > 0){
if(e.key==="ArrowDown"){
currentIndex=(currentIndex + 1) % $items.length;
}else if(e.key==="ArrowUp"){
currentIndex=(currentIndex - 1 + $items.length) % $items.length;
}
$items.removeClass('active');
$($items[currentIndex]).addClass('active');
$resultsContainer.scrollTop($($items[currentIndex]).position().top
- $resultsContainer.height() / 2
+ $($items[currentIndex]).outerHeight() / 2
);
}}else if(e.key==="Enter"){
if(currentIndex >=0){
var href=$resultsContainer.find('a.active').attr('href');
if(href){
window.location.href=href;
}}
}});
$searchInput.on('input', function(){
var value=$(this).val().toLowerCase();
$resultsContainer.empty().hide();
var uniqueLinks={};
currentIndex=-1;
if(value===""){
$resultsContainer.hide();
return;
}
$('.navbar-nav > li').each(function(){
var parent=$(this);
var hasVisibleChildren=false;
parent.find('.dropdown-menu .dropdown-item').each(function(){
var itemText=$(this).text().toLowerCase();
var itemHref=$(this).attr('href');
if(itemText.indexOf(value) > -1 &&
itemHref &&
itemHref.indexOf('/tours/')!==-1
){
if(!uniqueLinks[itemHref]){
$resultsContainer.append('<a href="' + itemHref + '">' + $(this).text() + '</a>'
);
uniqueLinks[itemHref]=true;
hasVisibleChildren=true;
}}
});
if(hasVisibleChildren){
$resultsContainer.show();
}});
if(typeof window.tourData!=='undefined'&&Array.isArray(window.tourData)){
$.each(window.tourData, function(index, tour){
if(tour.country &&
tour.country.toLowerCase().indexOf(value) > -1 &&
tour.link
){
if(!uniqueLinks[tour.link]){
$resultsContainer.append('<a href="' + tour.link + '">' +
tour.title + ' (' + tour.country + ')' +
'</a>'
);
uniqueLinks[tour.link]=true;
$resultsContainer.show();
}}
});
}});
}
$('#menu-icon').on('click', function(){
$('#myNavbar').toggleClass('mobile-solid');
});
/*
$(window).on('scroll', function(){
if($(this).scrollTop() > 500&&$(this).width() < 767){
$('#myNavbar').addClass('solid');
}else if($(this).scrollTop() > 500){
$('#myNavbar').addClass('solid');
}else{
$('#myNavbar').removeClass('solid');
}});
*/
});