/*! npm.im/object-fit-images 3.2.4 */
var objectFitImages = function () { "use strict"; function t(t, e) { return "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='" + t + "' height='" + e + "'%3E%3C/svg%3E" } function e(t) { if (t.srcset && !p && window.picturefill) { var e = window.picturefill._; t[e.ns] && t[e.ns].evaled || e.fillImg(t, { reselect: !0 }), t[e.ns].curSrc || (t[e.ns].supported = !1, e.fillImg(t, { reselect: !0 })), t.currentSrc = t[e.ns].curSrc || t.src } } function i(t) { for (var e, i = getComputedStyle(t).fontFamily, r = {}; null !== (e = u.exec(i));)r[e[1]] = e[2]; return r } function r(e, i, r) { var n = t(i || 1, r || 0); b.call(e, "src") !== n && h.call(e, "src", n) } function n(t, e) { t.naturalWidth ? e(t) : setTimeout(n, 100, t, e) } function c(t) { var c = i(t), o = t[l]; if (c["object-fit"] = c["object-fit"] || "fill", !o.img) { if ("fill" === c["object-fit"]) return; if (!o.skipTest && f && !c["object-position"]) return } if (!o.img) { o.img = new Image(t.width, t.height), o.img.srcset = b.call(t, "data-ofi-srcset") || t.srcset, o.img.src = b.call(t, "data-ofi-src") || t.src, h.call(t, "data-ofi-src", t.src), t.srcset && h.call(t, "data-ofi-srcset", t.srcset), r(t, t.naturalWidth || t.width, t.naturalHeight || t.height), t.srcset && (t.srcset = ""); try { s(t) } catch (t) { window.console && console.warn("https://bit.ly/ofi-old-browser") } } e(o.img), t.style.backgroundImage = 'url("' + (o.img.currentSrc || o.img.src).replace(/"/g, '\\"') + '")', t.style.backgroundPosition = c["object-position"] || "center", t.style.backgroundRepeat = "no-repeat", t.style.backgroundOrigin = "content-box", /scale-down/.test(c["object-fit"]) ? n(o.img, function () { o.img.naturalWidth > t.width || o.img.naturalHeight > t.height ? t.style.backgroundSize = "contain" : t.style.backgroundSize = "auto" }) : t.style.backgroundSize = c["object-fit"].replace("none", "auto").replace("fill", "100% 100%"), n(o.img, function (e) { r(t, e.naturalWidth, e.naturalHeight) }) } function s(t) { var e = { get: function (e) { return t[l].img[e ? e : "src"] }, set: function (e, i) { return t[l].img[i ? i : "src"] = e, h.call(t, "data-ofi-" + i, e), c(t), e } }; Object.defineProperty(t, "src", e), Object.defineProperty(t, "currentSrc", { get: function () { return e.get("currentSrc") } }), Object.defineProperty(t, "srcset", { get: function () { return e.get("srcset") }, set: function (t) { return e.set(t, "srcset") } }) } function o() { function t(t, e) { return t[l] && t[l].img && ("src" === e || "srcset" === e) ? t[l].img : t } d || (HTMLImageElement.prototype.getAttribute = function (e) { return b.call(t(this, e), e) }, HTMLImageElement.prototype.setAttribute = function (e, i) { return h.call(t(this, e), e, String(i)) }) } function a(t, e) { var i = !y && !t; if (e = e || {}, t = t || "img", d && !e.skipTest || !m) return !1; "img" === t ? t = document.getElementsByTagName("img") : "string" == typeof t ? t = document.querySelectorAll(t) : "length" in t || (t = [t]); for (var r = 0; r < t.length; r++)t[r][l] = t[r][l] || { skipTest: e.skipTest }, c(t[r]); i && (document.body.addEventListener("load", function (t) { "IMG" === t.target.tagName && a(t.target, { skipTest: e.skipTest }) }, !0), y = !0, t = "img"), e.watchMQ && window.addEventListener("resize", a.bind(null, t, { skipTest: e.skipTest })) } var l = "bfred-it:object-fit-images", u = /(object-fit|object-position)\s*:\s*([-.\w\s%]+)/g, g = "undefined" == typeof Image ? { style: { "object-position": 1 } } : new Image, f = "object-fit" in g.style, d = "object-position" in g.style, m = "background-size" in g.style, p = "string" == typeof g.currentSrc, b = g.getAttribute, h = g.setAttribute, y = !1; return a.supportsObjectFit = f, a.supportsObjectPosition = d, o(), a }();

/* inview min js */
!function (t) { function e() { var e, i, n = { height: a.innerHeight, width: a.innerWidth }; return n.height || (e = r.compatMode, (e || !t.support.boxModel) && (i = "CSS1Compat" === e ? f : r.body, n = { height: i.clientHeight, width: i.clientWidth })), n } function i() { return { top: a.pageYOffset || f.scrollTop || r.body.scrollTop, left: a.pageXOffset || f.scrollLeft || r.body.scrollLeft } } function n() { var n, l = t(), r = 0; if (t.each(d, function (t, e) { var i = e.data.selector, n = e.$element; l = l.add(i ? n.find(i) : n) }), n = l.length) for (o = o || e(), h = h || i(); n > r; r++)if (t.contains(f, l[r])) { var a, c, p, s = t(l[r]), u = { height: s.height(), width: s.width() }, g = s.offset(), v = s.data("inview"); if (!h || !o) return; g.top + u.height > h.top && g.top < h.top + o.height && g.left + u.width > h.left && g.left < h.left + o.width ? (a = h.left > g.left ? "right" : h.left + o.width < g.left + u.width ? "left" : "both", c = h.top > g.top ? "bottom" : h.top + o.height < g.top + u.height ? "top" : "both", p = a + "-" + c, v && v === p || s.data("inview", p).trigger("inview", [!0, a, c])) : v && s.data("inview", !1).trigger("inview", [!1]) } } var o, h, l, d = {}, r = document, a = window, f = r.documentElement, c = t.expando; t.event.special.inview = { add: function (e) { d[e.guid + "-" + this[c]] = { data: e, $element: t(this) }, l || t.isEmptyObject(d) || (l = setInterval(n, 250)) }, remove: function (e) { try { delete d[e.guid + "-" + this[c]] } catch (i) { } t.isEmptyObject(d) && (clearInterval(l), l = null) } }, t(a).bind("scroll resize scrollstop", function () { o = h = null }), !f.addEventListener && f.attachEvent && f.attachEvent("onfocusin", function () { h = null }) }(jQuery);


$(function () {
    objectFitImages();


    // Video autoplay
    $('.video-wrapper video').on('inview', function (event, isInView) {
        $(this).trigger(isInView ? 'play' : 'pause');
    });


    // Responsive menu trigger
    $(".menu-trigger").on('click', function () {
        $('.menu-trigger, .header .top-menu').toggleClass('active');
        return false;
    });


    // Dropdown
    $('*[data-dropdown]').on('click', function () {
        var datatarget = $(this).data('dropdown');
        $(datatarget).toggle();
        $('html').click(function () {
            $(datatarget).hide();
        });
        $(datatarget).click(function (e) {
            e.stopPropagation();
        });
        return false;
    });


    // Form button state
    $('#mc_embed_signup #mc-embedded-subscribe-form .gdprConsent input[type="checkbox"]').click(function () {
        if ($(this).is(':checked')) {
            $('#mc_embed_signup #mc-embedded-subscribe-form .button').removeAttr('disabled');
        } else {
            $('#mc_embed_signup #mc-embedded-subscribe-form .button').attr('disabled', 'disabled');
        }
    });


    // Slider
    var touchDevice = false;
    if (navigator.userAgent.match(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/)) {
        touchDevice = true;
    };

    $('.slider .wrapper > ul').each(function () {
        if ($(this).find('li').length > 3) {
            $(this).bxSlider({
                touchEnabled: touchDevice,
                slideMargin: 55,
                minSlides: 1,
                maxSlides: 3,
                moveSlides: 1,
                slideWidth: 420,
                shrinkItems: true
            });
        };
    })

    // Hotel slider
    if ($('.hotel-slider > ul li').length > 1) {
        $('.hotel-slider > ul').bxSlider({
            touchEnabled: touchDevice,
            mode: 'fade'
        });
    };




    // Gallery slider
    window.setTimeout(function () {
        $('.gallery-slider > ul').bxSlider({
            touchEnabled: touchDevice
        });
    }, 1000);




    // History Slider
    $('.history-slider > ul').bxSlider({
        touchEnabled: touchDevice,
        slideMargin: 40,
        minSlides: 1,
        maxSlides: 3,
        moveSlides: 1,
        slideWidth: 340,
        shrinkItems: true,
        pager: false,
        infiniteLoop: false
    });




    // Tabs
    $('.tabs-wrap .tab-select li:first-child, .tabs-wrap .tab-content:first-of-type').addClass('active');
    $('.single-tabs .tab-select li:nth-child(2), .single-tabs .tab-content:nth-of-type(2)').addClass('active');
    $('.tab-select li').on('click', function () {
        $(this).parent().find('li').removeClass('active').each(function () {
            var tabsTarget = $(this).attr('data-tab');
            $(tabsTarget).removeClass('active');
        });
        $(this).addClass('active');
        var tabTarget = $(this).attr('data-tab');
        $(tabTarget).addClass('active');
        return false;
    });


    // Room booking form toggle
    function hasParent(element, parent) {
        let parents = $(element).parents();
        for (let i = 0; i < parents.length; i++) {
            if (parents[i] === parent) return true;
        }
        return false;
    }
    if ($(window).width() > 767) {
        if ($('.room-booking-form').length) {
            $('.media-content-list li figure figcaption .button-pink:not([href^="mailto:"])').on('click', function (e) {
                // if ($(this)[0].href.startsWith('mailto:')) return;
                
                let bookButton = e.target;

                let bookingForm = $(this).parent().parent().find('.room-booking-form')[0];
                $(bookingForm).toggle();

                function closeForm(e) {
                    if (e.target === bookButton || hasParent(e.target, bookingForm)) return;
                    $(bookingForm).hide();
                    $(document).off('click', closeForm);
                }
                $(document).on('click', closeForm)
                
                e.preventDefault();
            });

            // don't close popup if clicked inside datepicker (e.g. when selecting a month or year)
            $('.flatpickr-calendar').click(function (e) {
                e.stopPropagation();
            });
        };
    }


    // Show/hide input value
    $('input[type="text"], input[type="password"], input[type="email"]').each(function () {
        var valtxt = $(this).attr('value');
        $(this).focus(function () { if ($(this).val() == valtxt) { $(this).val(''); } });
        $(this).blur(function () { if ($(this).val() == '') { $(this).val(valtxt); } });
    });
    $("textarea").focus(function () { if (this.value === this.defaultValue) { this.value = ''; } }).blur(function () { if (this.value === '') { this.value = this.defaultValue; } });


}); 