/*  accessibility  */
/**
 * Component accessibility
 * makes content more accessible to people with disabilities.
 * @module Accessibility
 * @param  {jQuery} $ Instance of jQuery
 */
XA.component.accessibility = (function ($) {
    /**
    * This object stores all public api methods
    * @type {Object.<Methods>}
    * @memberOf module:Accessibility
    * */
    var api = {};
    /**
        * getAllIndexedElement - returns elements that have tab index attribute
        * @returns {jQuery<DOMElement>} elements that have tab index attribute
    */
    var getAllIndexedElement = function () {
        return $("body").find("[tabindex]");
    };

    /**
        * activateFirstElement - activate first element on a page that have tab index attribute
        * active element
        * @returns {String} component name 
    */
    api.activateFirstElement = function () {
        api.indexedElements.eq(0).attr("tabindex", "0");
    };
    /**
       * getComponentName - helper that provides component name based on 
       * active element
       * @returns {String} component name 
   */
    var getComponentName = function () {
        var $activeElement = $(document.activeElement),
            currComponent = $activeElement.closest(".initialized"),
            componentName = currComponent.length
                ? currComponent.attr("class").split(" ")[1]
                : "";
        return componentName;
    };
    /**
        * getWrapper - helper that provides wrapper element for
        * active element
        * @param {String} selector selector of parent wrapper
        * @returns {jQuery<DOMElement>} 
    */
    var getWrapper = function (selector) {
        var $activeElement = $(document.activeElement);
        return $activeElement.closest(selector);
    };

    /**
        * activateTab - helper for Tabs component
    */
    var activateTab = function (direction, currTab) {
        var activatedTab = currTab;
        if (direction == "left" && currTab.prev()) {
            currTab.attr("tabindex", "-1");
            activatedTab = currTab.prev();
        } else if (direction == "right" && currTab.next()) {
            currTab.attr("tabindex", "-1");
            activatedTab = currTab.next();
        }
        activatedTab
            .attr("tabindex", "0")
            .trigger("click")
            .focus();
    };

    /**
     * activateItem - helper for Accordion component
    */
    var activateItem = function (direction, currItem, event) {
        var itemWrapper = currItem.closest("li.item"),
            activatedTab = currItem,
            nextItem = itemWrapper.next(),
            prevItem = itemWrapper.prev();
        if (direction == "down" && nextItem.length) {
            event.preventDefault();
            currItem.attr("tabindex", "-1");
            activatedTab = nextItem;
            
        } else if (direction == "up" && prevItem.length) {
            event.preventDefault();
            currItem.attr("tabindex", "-1");
            activatedTab = prevItem;
        }
        activatedTab
            .find(".toggle-header")
            .attr("tabindex", "0")
            .focus();
    };

    /**
     * toggleFlip - helper for Flip component
    */
    var toggleFlip = function (currItem) {
        var nextItem = currItem.next().length ? currItem.next() : currItem.prev();
        currItem.attr("tabindex", "-1");
        nextItem
            .trigger("click")
            .attr("tabindex", "0")
            .focus();
    };

    /**
     * componentLogic - object that contains list of components as a object key
     * and function with logic that make this component WCAG friendly
     * @type {Object}
     */
    var componentLogic = {
        tabs: function (keyCode) {
            var currTab = getWrapper("li.active");
            if (currTab) {
                if (keyCode == api.keys.right) {
                    activateTab("right", currTab);
                } else if (keyCode == api.keys.left) {
                    activateTab("left", currTab);
                }
            }
        },
        accordion: function (keyCode, isShiftPressed, event) {
            var currItem = getWrapper("div.toggle-header");
            if (currItem) {
                if (keyCode == api.keys.down) {
                    activateItem("down", currItem, event);
                } else if (keyCode == api.keys.up) {
                    activateItem("up", currItem, event);
                } else if (!isShiftPressed && keyCode == api.keys.tab) {
                    activateItem("down", currItem, event);
                } else if (isShiftPressed && keyCode == api.keys.tab){
                    activateItem("up", currItem, event);
                }
            }
        },
        flip: function (keyCode) {
            var currItem = getWrapper("[class*='Side']");
            if (currItem) {
                if (keyCode == api.keys.right || keyCode == api.keys.left) {
                    toggleFlip(currItem);
                }
            }
        }
    };
    /**
    * bindEvents method get component name by calling 
    * ["getComponentName"]{@link module:Accessibility.getComponentName} method and running apropriate to
    * component logic
    * @memberOf module:Accessibility
    * @param {number} keycode keycode of pressed button on keyboard
    * @alias module:Accessibility.bindEvents
    * @private
    * */
    var bindEvents = function (keyCode, isShiftPressed, event) {
        var component = getComponentName();
        if (componentLogic[component]) {
            componentLogic[component](keyCode, isShiftPressed, event);
        }
    };

    /**
    * This object stores keycode of keyboard buttons
    * @type {Object}
    * @memberOf module:Accessibility 
    * @alias module:Accessibility.keys
    * */
    api.keys = {
        end: 35,
        home: 36,
        left: 37,
        up: 38,
        right: 39,
        down: 40,
        delete: 46,
        enter: 13,
        space: 32,
        tab: 9
    };
    /**
         * indexedElements variable take list of all Indexed Element on a page by calling
         * ["getAllIndexedElement"]{@link module:Accessibility.getAllIndexedElement} method
         * @memberOf module:Accessibility
         * @param {Object} properties list of properties for accordion component
         * @alias module:Accessibility.indexedElements
    */
    api.indexedElements = getAllIndexedElement();
    /**
     * watchEvents method bind keyup event on document and on each trigger calls
     * ["bindEvents"]{@link module:Accessibility.bindEvents}
     * @memberOf module:Accessibility
     * @alias module:Accessibility.watchEvents
     */
    api.watchEvents = function () {
        $(document).on("keydown", function (event) {
            var keyCode = event.keyCode,
                isShiftPressed = event.shiftKey;
            bindEvents(keyCode, isShiftPressed, event);
        });
    };
    /**
    * registerLogic method register accessability logic to
    * ["componentLogic"]{@link module:Accessibility.componentLogic} list
    * @memberOf module:Accessibility
    * @param {string} componentName name of component which logic should be registered
    * @param {Function} componentFunc function for component that will be triggered for accessability support
    * @alias module:Accessibility.registerLogic
    */
    api.registerLogic = function (componentName, componentFunc) {
        componentLogic[componentName] = componentFunc;
    }
    /**
    * unregisterLogic method delete accessability logic from
    * ["unregisterLogic"]{@link module:Accessibility.unregisterLogic} list
    * @memberOf module:Accessibility
    * @param {string} componentName name of component which logic should be deleted
    * @alias module:Accessibility.unregisterLogic
    */
    api.unregisterLogic = function (componentName) {
        delete componentLogic[componentName]
    }
    /**
    * getRegisteredLogic method return list of accessability logic
    * ["unregisterLogic"]{@link module:Accessibility.unregisterLogic} list
    * @memberOf module:Accessibility
    * @returns {Object} list of registered components and their logic
    * @alias module:Accessibility.getRegisteredLogic
    */
    api.getRegisteredLogic = function () {
        return componentLogic
    }
    /**
        * initInstance method call
        * ["watchEvents"]{@link module:Accessibility.watchEvents} method
        * and call
        * ["activateFirstElement"]{@link module:Accessibility.activateFirstElement}
        * @memberOf module:Accessibility
        * @method
        * @alias module:Accessibility.initInstance
        */
    api.initInstance = function () {
        api.watchEvents();
        api.activateFirstElement();
    };
    /**
     * init method calls 
     * [".initInstance"]{@link module:Accessibility.initInstance} method.
     * @memberOf module:Accessibility
     * @alias module:Accessibility.init
     */
    api.init = function () {
        api.initInstance();
    };

    return api;
})(jQuery, document);

XA.register("accessibility", XA.component.accessibility);


/*  component-tabs  */
/**
 * Component Tabs
 * @module Tabs
 * @param  {jQuery} $ Instance of jQuery
 * @return {Object} List of tabs methods
 */
XA.component.tabs = (function($) {
    /**
     * This object stores all public api methods
     * @type {Object.<Methods>}
     * @memberOf module:Tabs
     * @
     * */
    var api = {},
        instance;
    /**
     * isFlipInside chech if inside Tab component present Flip component
     * @memberOf module:Tab
     * @method
     * @param {jQuery} $instance Tabs Root DOM element of tab component wrapped by jQuery
     * @alias module:Tab.isFlipInside
     * @return {boolean}
     * @private
     */
    var isFlipInside = function(instance) {
        return !!instance.find(".component.flip").length;
    };
    /**
     * tabsScrollable modify tabs to support scroll for tabs header
     * @memberOf module:Tab
     * @method
     * @param {jQuery} $tabsScroll Tabs Root DOM element of tab component wrapped by jQuery
     * @alias module:Tab.tabsScrollable
     * @private
     */
    function tabsScrollable($tabsScroll) {
        var speed = 150; //tabs scroll speed

        function initNavScroll($tabsNav) {
            var sum = 0,
                maxHeight = 0;

            if ($tabsNav.length) {
                $tabsNav
                    .parent()
                    .find(".prev")
                    .remove();
                $tabsNav
                    .parent()
                    .find(".next")
                    .remove();
                $tabsNav.unwrap();

                $tabsNav.css("width", "auto");
                $tabsNav.css("height", "auto");
                $tabsNav.css("left", 0);
            }

            $tabsNav.find("li").each(function() {
                sum += $(this).outerWidth(true);
            });

            $tabsNav.find("li").each(function() {
                maxHeight = Math.max(maxHeight, $(this).height());
            });

            $tabsNav.wrap("<div class='wrapper'>");
            $("<div class='next tab-slider'>></div>").insertAfter($tabsNav);
            $("<div class='prev tab-slider'><</div>").insertBefore($tabsNav);

            $tabsNav.parent().css("height", parseInt(maxHeight, 10));
            $tabsNav
                .parent()
                .find(".tab-slider")
                .css("height", parseInt(maxHeight, 10) - 2);
            //fix for 8111
            sum += 10;
            if (sum > $tabsNav.parent().width()) {
                $tabsNav
                    .parent()
                    .find(".prev")
                    .hide();
                $tabsNav.width(sum);
            } else {
                $tabsNav
                    .parent()
                    .find(".prev")
                    .hide();
                $tabsNav
                    .parent()
                    .find(".next")
                    .hide();
            }
        }

        function bindPrevNextEvents(current, $tabsNav) {
            current.find(".prev").click(function() {
                var left = parseInt($tabsNav.css("left"), 10);
                left += speed;

                if (left > 0) {
                    left = 0;
                    $tabsNav.stop().animate({
                        left: left
                    });

                    $tabsNav
                        .parent()
                        .find(".prev")
                        .hide();
                    $tabsNav
                        .parent()
                        .find(".next")
                        .show();
                } else {
                    $tabsNav.stop().animate({
                        left: left
                    });

                    $tabsNav
                        .parent()
                        .find(".prev")
                        .show();
                    $tabsNav
                        .parent()
                        .find(".next")
                        .show();
                }
            });

            current.find(".next").click(function() {
                var left = parseInt($tabsNav.css("left"), 10),
                    navWidth = $tabsNav.width(),
                    navParentWidth = $tabsNav.parent().width();

                left -= speed;

                if (navWidth + left < navParentWidth) {
                    left = navWidth - navParentWidth + 20;
                    $tabsNav.stop().animate({
                        left: -left
                    });

                    $tabsNav
                        .parent()
                        .find(".prev")
                        .show();
                    $tabsNav
                        .parent()
                        .find(".next")
                        .hide();
                } else {
                    $tabsNav.stop().animate({
                        left: left
                    });

                    $tabsNav
                        .parent()
                        .find(".prev")
                        .show();
                    $tabsNav
                        .parent()
                        .find(".next")
                        .show();
                }
            });
        }

        function bindChangeTabs($tabsNav, $tabsContainer) {
            $tabsNav.find("li").click(function(event) {
                var index = $(this).index(),
                    instance = $(this).closest(".component.tabs");

                $(this).addClass("active");
                $(this)
                    .siblings()
                    .removeClass("active");

                $tabsContainer.find(".tab").removeClass("active");
                $tabsContainer
                    .find(".tab:eq(" + index + ")")
                    .addClass("active");

                if (isFlipInside(instance)) {
                    try {
                        XA.component.flip.equalSideHeight(instance);
                    } catch (e) {
                        /* eslint-disable no-console */
                        console.warn(
                            "Error during calculation height of Flip list in toggle"
                        ); // jshint ignore:line
                        /* eslint-enable no-console */
                    }
                }
                event.preventDefault();
            });
        }

        function initTabsScrollable($tabs) {
            $tabs.each(function() {
                var $tabsNav = $(this).find(".tabs-heading"),
                    $tabsContainer = $(this).find(".tabs-container");

                $tabsNav.find("li:first-child").addClass("active");
                $tabsContainer.find(".tab:eq(0)").addClass("active");

                bindChangeTabs($tabsNav, $tabsContainer);
                initNavScroll($tabsNav);
                bindPrevNextEvents($(this), $tabsNav);
            });
        }

        initTabsScrollable($tabsScroll);
        $(window).resize(function() {
            initTabsScrollable($tabsScroll);
        });
    }
    /**
     * selectActiveTab activate selected tab
     * @memberOf module:Tab
     * @method
     * @param {jQuery} $tabNav Tabs header DOM element of tab component wrapped by jQuery
     * @param {jQuery} $tabs Tabs content DOM element of tab component wrapped by jQuery
     * @alias module:Tab.selectActiveTab
     * @private
     */
    function selectActiveTab($tabNav, $tabs) {
        var tabRootId = $tabNav.closest(".component.tabs").attr("id");
        var tabToSelect = XA.queryString.getQueryParam(tabRootId || "tab");

        if (
            tabToSelect != null &&
            !isNaN(parseInt(tabToSelect)) &&
            isFinite(tabToSelect)
        ) {
            tabToSelect = parseInt(tabToSelect);
            if ($tabNav.length > tabToSelect) {
                $($tabNav[tabToSelect]).addClass("active");
                $($tabs[tabToSelect]).addClass("active");

                return;
            }
        }
        $tabNav.first().addClass("active");
        $tabNav.first().attr("tabindex", "0");
        $tabs.first().addClass("active");
    }

    /**
     * initInstance initializes component according to his option
     * @memberOf module:Tabs
     * @method
     * @param {jQuery} component Root DOM element of archive component wrapped by jQuery
     * @alias module:Tabs.initInstance
     */
    api.initInstance = function(component) {
        var $tabModule = component.find(".tabs-inner");
        if (component.hasClass("tabs-scrollable")) {
            tabsScrollable(component);
        } else {
            $tabModule.each(function() {
                var $tabNav = $(this).find(".tabs-heading > li"),
                    $tabs = $(this).find("> .tabs-container > .tab");

                selectActiveTab($tabNav, $tabs);

                $tabNav
                    .click(function(event) {
                        var current = $(this),
                            index = current.index(),
                            tabInner = current.parent().parent();

                        current.siblings().removeClass("active");
                        tabInner
                            .find("> .tabs-container > .tab")
                            .removeClass("active");
                        current.addClass("active");
                        $(
                            tabInner
                                .children(".tabs-container")
                                .children(".tab")
                                .eq(index)
                        ).addClass("active");
                        if (isFlipInside(component)) {
                            try {
                                XA.component.flip.equalSideHeight(component);
                            } catch (e) {
                                /* eslint-disable no-console */
                                console.warn(
                                    "Error during calculation height of Flip list in toggle"
                                ); // jshint ignore:line
                                /* eslint-enable no-console */
                            }
                        }
                        current.focus();
                        event.preventDefault();
                    })
                    .keyup(function(event) {
                        var currentHeading = $(this);
                        switch (event.keyCode) {
                            case 38: {
                                currentHeading.prev("li").click();
                                break;
                            }
                            case 40: {
                                currentHeading.next("li").click();
                                break;
                            }
                        }
                    });
            });
        }

        if (isFlipInside(component)) {
            try {
                XA.component.flip.equalSideHeight(component);
            } catch (e) {
                /* eslint-disable no-console */
                console.warn(
                    "Error during calculation height of Flip list in toggle"
                ); // jshint ignore:line
                /* eslint-enable no-console */
            }
        }
    };
    /**
     * init method calls in a loop for each
     * tabs component on a page and runs Tab's
     * ["initInstance"]{@link module:Tabs.api.initInstance} method
     * @memberOf module:Tabs
     * @alias module:Tabs.init
     */
    api.init = function() {
        var $tabs = $(".tabs:not(.initialized)");
        $tabs.each(function() {
            var instance = $(this);
            api.initInstance(instance);
            $(this).addClass("initialized");
        });
    };

    return api;
})(jQuery);

XA.register("tabs", XA.component.tabs);


/*  component-toggle  */
/**
 * Component Toggle
 * @module Toggle
 * @param  {jQuery} $ Instance of jQuery
 * @return {Object} List of toggle methods
 */
XA.component.toggle = (function($) {
    /**
     * This object stores all public api methods
     * @type {Object.<Methods>}
     * @memberOf module:Toggle
     * */
    var api = {};

    var properties, instance;
    /**
     * Returns list of flip components
     * @memberOf module:Toggle
     * @method
     * @param {DOMElement} instance Root DOM element of toggle component
     * @alias module:Toggle.openToggle
     * @private
     * @return {jQuery} list of flip components
     */
    var getFlipList = function(instance) {
        return $(instance).find(".component.flip");
    };
	/**
     * Adds attribute "open" for "details" tag.
     * If inside toggle event calendar is added, this method will trigger
     * "resize method"
     * If inside toggle flip component is added, it will call
     * ["Flip.equalSideHeightInToggle"]{@link  module:Flip.equalSideHeightInToggle}
     * @memberOf module:Toggle
     * @method
     * @param {DOMElement} instance Root DOM element of toggle component
     * @alias module:Toggle.openToggle
     * @private
     */
    var openToggle = function(instance) {
        var flipList = getFlipList(instance),
            eventCalendar = $(instance).find('.event-calendar');
        $(instance).find('details').attr('open', 'open');
        if (eventCalendar.length){
            eventCalendar.trigger('resize')
        }
        if (flipList.lengt) {
            try {
                XA.component.flip.equalSideHeightInToggle(instance)
            } catch (e) {
                /* eslint-disable no-console */
                console.warn('Error during calculation height of Flip list in toggle'); // jshint ignore:line
                /* eslint-enable no-console */

            }
        }

    }
	/**
     * Removes attribute "open" for "details" tag
     * @memberOf module:Toggle
     * @method
     * @param {DOMElement} instance Root DOM element of toggle component
     * @alias module:Toggle.closeToggle
     * @private
     */
    var closeToggle = function(instance) {
        $(instance).find('details').removeAttr('open');
    }

	/**
     * Sets css animation for component-content of an component
     * @memberOf module:Toggle
     * @method
     * @param {DOMElement} instance Root DOM element of toggle component
     * @alias module:Toggle.setAnimation
     * @private
     */
    var setAnimation = function(instance) {
        $(instance).find('details summary~.component>.component-content').css({
            'animation-name': properties.easing,
            'animation-duration': (properties.speed || 500) + 'ms'
        });
    };
	/**
     * Checks value of properties.expandOnHover;
     * @memberOf module:Toggle
     * @method
     * @alias module:Toggle.isExpandOnHover
     * @private
     * @return {Boolean} properties.expandOnHover
     */
    var isExpandOnHover = function() {
        return properties.expandOnHover;
    };
    /**
     * Checks value of properties.expandedByDefault;
     * @memberOf module:Toggle
     * @method
     * @alias module:Toggle.isExpanded
     * @private
     * @return {Boolean} properties.expandedByDefault
     */
    var isExpanded = function() {
        return properties.expandedByDefault;
    };
    /**
     * Binds watchers on "summary" element that will call
     * ["openToggle"]{@link  module:Toggle.openToggle}
     * method
     * @memberOf module:Toggle
     * @method
     * @param {jQuery} instance Root DOM element of toggle component
     * @alias module:Toggle.bindEvents
     * @private
     */
	var bindEvents = function(instance) {
        var summary = $(instance).find('summary');
        if (isExpandOnHover()) {
            summary.on('mouseenter', function() {
                openToggle(instance);
            });
        }
        if (isExpanded()) {
            openToggle(instance);
        }

        summary.on('click', function(event) {
            event.preventDefault();
            var details = $(this).closest('details')
            if (details.attr('open')) {
                closeToggle(instance);
            } else {
                openToggle(instance);
            }
        });
    };
	/**
     * Call
     * ["bindEvents"]{@link  module:Toggle.bindEvents}
     * ["setAnimation"]{@link  module:Toggle.setAnimation}
     * methods
     * @memberOf module:Toggle
     * @method
     * @param {jQuery} component Root DOM element of toggle component wrapped by jQuery
     * @alias module:Toggle.initToggle
     * @private
     */
    var initToggle = function(component) {
        bindEvents(component);
		setAnimation(component);
	};
    /**
     * Call
     * ["initToggle"]{@link  module:Toggle.initToggle}
     * method
     * @memberOf module:Toggle
     * @method
     * @param {jQuery} component Root DOM element of toggle component wrapped by jQuery
     * @alias module:Toggle.initInstance
     */
    api.initInstance = function(component) {
        initToggle(component);
    };
    /**
     * Finds all not-initialized 
     * Toggle components and in a loop for each of them
     * runs Toggle's
     * ["initInstance"]{@link module:Toggle.initInstance}
     * method.
     * @memberOf module:Toggle
     * @alias module:Toggle.init
     */
    api.init = function() {
        $('.toggle:not(.initialized)').each(function() {
            instance = $(this);
            properties = instance.data('properties');
            api.initInstance(this,properties);
            instance.addClass('initialized');
        });
    };

    return api;
})(jQuery);

XA.register('component-toggle', XA.component.toggle);

/*  details-polyfill  */
/*
Details Element Polyfill 2.0.0
Copyright © 2017 Javan Makhmali
 */
(function () { }).call(this),
    function () {
    if (document.querySelector('body').getAttribute('class') && document.querySelector('body').getAttribute('class').indexOf('on-page-editor') > -1) {
            return;
        }
        var t, e, n, r, u, o, i, a, s, l, c, d;
        l = {
            element: function () {
                var t, e, n, r, u;
                return e = document.createElement("details"), "open" in e ? (e.innerHTML = "<summary>a</summary>b", e.setAttribute("style", "position: absolute; left: -9999px"), r = null != (u = document.body) ? u : document.documentElement, r.appendChild(e), t = e.offsetHeight, e.open = !0, n = e.offsetHeight, r.removeChild(e), t !== n) : !1
            }(),
            toggleEvent: function () {
                var t;
                return t = document.createElement("details"), "ontoggle" in t
            }()
        }, l.element && l.toggleEvent || (i = function () {
            return document.head.insertAdjacentHTML("afterbegin", '<style>@charset"UTF-8";details:not([open])>*:not(summary){display:none;}details>summary{display:block;}details>summary::before{content:"\u25ba";padding-right:0.3rem;font-size:0.6rem;cursor:default;}details[open]>summary::before{content:"\u25bc";}</style>')
        }, o = function () {
            var t, e, n, r, u;
            return t = document.createElement("details").constructor.prototype, r = t.setAttribute, n = t.removeAttribute, u = null != (e = Object.getOwnPropertyDescriptor(t, "open")) ? e.set : void 0, Object.defineProperties(t, {
                open: {
                    set: function (t) {
                        return "DETAILS" === this.tagName ? (t ? this.setAttribute("open", "") : this.removeAttribute("open"), t) : null != u ? u.call(this, t) : void 0
                    }
                },
                setAttribute: {
                    value: function (t, e) {
                        return d(this, function (n) {
                            return function () {
                                return r.call(n, t, e)
                            }
                        }(this))
                    }
                },
                removeAttribute: {
                    value: function (t) {
                        return d(this, function (e) {
                            return function () {
                                return n.call(e, t)
                            }
                        }(this))
                    }
                }
            })
        }, a = function () {
            return r(function (t) {
                var e;
                return e = t.querySelector("summary"), t.hasAttribute("open") ? (t.removeAttribute("open"), e.setAttribute("aria-expanded", !1)) : (t.setAttribute("open", ""), e.setAttribute("aria-expanded", !0))
            })
        }, u = function () {
            var e, n, r, u, o;
            for (u = document.querySelectorAll("summary"), e = 0, n = u.length; n > e; e++) o = u[e], t(o);
            return "undefined" != typeof MutationObserver && null !== MutationObserver ? (r = new MutationObserver(function (e) {
                var n, r, u, i, a;
                for (i = [], r = 0, u = e.length; u > r; r++) n = e[r].addedNodes, i.push(function () {
                    var e, r, u;
                    for (u = [], e = 0, r = n.length; r > e; e++) a = n[e], "DETAILS" === a.tagName && (o = a.querySelector("summary")) ? u.push(t(o, a)) : u.push(void 0);
                    return u
                }());
                return i
            }), r.observe(document.documentElement, {
                subtree: !0,
                childList: !0
            })) : document.addEventListener("DOMNodeInserted", function (e) {
                return "SUMMARY" === e.target.tagName ? t(e.target) : void 0
            })
        }, t = function (t, e) {
            return null == e && (e = n(t, "DETAILS")), t.setAttribute("aria-expanded", e.hasAttribute("open")), t.hasAttribute("tabindex") || t.setAttribute("tabindex", "0"), t.hasAttribute("role") ? void 0 : t.setAttribute("role", "button")
        }, s = function () {
            var t;
            return "undefined" != typeof MutationObserver && null !== MutationObserver ? (t = new MutationObserver(function (t) {
                var e, n, r, u, o, i;
                for (o = [], n = 0, r = t.length; r > n; n++) u = t[n], i = u.target, e = u.attributeName, "DETAILS" === i.tagName && "open" === e ? o.push(c(i)) : o.push(void 0);
                return o
            }), t.observe(document.documentElement, {
                attributes: !0,
                subtree: !0
            })) : r(function (t) {
                var e;
                return e = t.getAttribute("open"), setTimeout(function () {
                    return t.getAttribute("open") !== e ? c(t) : void 0
                }, 1)
            })
        }, e = function (t) {
            return !(t.defaultPrevented || t.altKey || t.ctrlKey || t.metaKey || t.shiftKey || t.target.isContentEditable)
        }, r = function (t) {
            return addEventListener("click", function (r) {
                var u, o;
                return e(r) && r.which <= 1 && (u = n(r.target, "SUMMARY")) && "DETAILS" === (null != (o = u.parentElement) ? o.tagName : void 0) ? t(u.parentElement) : void 0
            }, !1), addEventListener("keydown", function (r) {
                var u, o, i;
                return e(r) && (13 === (o = r.keyCode) || 32 === o) && (u = n(r.target, "SUMMARY")) && "DETAILS" === (null != (i = u.parentElement) ? i.tagName : void 0) ? (t(u.parentElement), r.preventDefault()) : void 0
            }, !1)
        }, n = function () {
            return "function" == typeof Element.prototype.closest ? function (t, e) {
                return t.closest(e)
            } : function (t, e) {
                for (; t;) {
                    if (t.tagName === e) return t;
                    t = t.parentElement
                }
            }
        }(), c = function (t) {
            var e;
            return e = document.createEvent("Events"), e.initEvent("toggle", !0, !1), t.dispatchEvent(e)
        }, d = function (t, e) {
            var n, r;
            return n = t.getAttribute("open"), r = e(), t.getAttribute("open") !== n && c(t), r
        }, l.element || (i(), o(), a(), u()), l.element && !l.toggleEvent && s())
    }.call(this),
    function () { }.call(this);

/*  fixheight  */
/**
 * Component equalHeight
 * makes the same height of content that 'equal' class or for flip sides
 * @module equalHeight
 * @param  {jQuery} $ Instance of jQuery
 * @return {Object} List of equalHeight methods
 */
XA.component.equalHeight = (function ($) {
    /**
    * List of selectors for calculating height functionality
    * @type {Object.<Methods>}
    * @memberOf module:equalHeight
    * */
    var settings = {
        parentSelector: '.equalized-content',
        selector: '.equal:not(.flip.component),.flip .Side0,.flip .Side1'
    };
    /**
     * This object stores all public api methods
     * @type {Object.<Methods>}
     * @memberOf module:equalHeight
     * */
    var api = {};
    /**
    * fixHeight method calculates height of bigger element 
    * and sets up the same size for other elements
    * @memberOf module:equalHeight
    * @alias module:equalHeight.fixHeight
    */
    api.fixHeight = function () {

        $(settings.parentSelector).each(function () {
            var $elements = $(this).find(settings.selector),
                maxHeight = 0;



            $elements.each(function () {
                var $element = $(this);
                $element.css('min-height', 'inherit');
                $element.find('>.component-content').css('min-height', 'inherit');

                if ($element.outerHeight(true) > maxHeight) {
                    maxHeight = $element.outerHeight(true);
                }
            });

            if (maxHeight > 0) {
                $elements.each(function () {
                    var $element = $(this);
                    if ($element.hasClass("Side0") || $element.hasClass("Side1")) {
                        $element.parent().attr('class', 'flip').css({ 'min-height': maxHeight });
                    }
                    $element.css({
                        'min-height': maxHeight
                    });
                    $element.find('>.component-content').css({
                        'min-height': maxHeight
                    });
                });
            }
        });
    }
    /**
      * init method binds call of 
      * ["fixHeight"]{@link module:equalHeight.fixHeight} method
      * for window load and resize events
      * @memberOf module:equalHeight
      * @alias module:equalHeight.init
      */
    api.init = function () {
        $(document).ready(function () {
            api.fixHeight();
        })

        $(window).on('resize', function () {
            setTimeout(api.fixHeight, 0);
        });
    };

    return api;

}(jQuery, document));

XA.register("equalHeight", XA.component.equalHeight);

/*  search-fixheight  */
/**
 * Component searchEqualHeight
 * makes height of search results elements the same
 * @deprecated Latest Theme version use flexboxes.
 * @module searchEqualHeight
 * @param  {jQuery} $ Instance of jQuery
 * @return {Object} List of searchEqualHeight methods
 */
XA.component.searchEqualHeight = (function ($) {
    /**
    * List of selectors for calculating height functionality
    * @type {Object.<Methods>}
    * @memberOf module:searchEqualHeight
    */
    var settings = {
        parentSelector: '.search-results.components',
        selector: 'li'
    };
    /**
    * This object stores all public api methods
    * @type {Object.<Methods>}
    * @memberOf module:searchEqualHeight
    */
    var api = {};
    /**
    * fixHeight method calculates height of bigger element 
    * and sets up the same size for other elements
    * @memberOf module:searchEqualHeight
    * @alias module:searchEqualHeight.fixHeight
    */
    function fixHeight() {

        $(settings.parentSelector).each(function () {
            var $elements = $(this).find(settings.selector),
                maxHeight = 0,
                maxPadding = 0;

            $elements.each(function () {
                $(this).css('min-height', 'inherit');

                if ($(this).height() > maxHeight) {
                    maxHeight = $(this).outerHeight(true);
                }

            });

            if (maxHeight > 0) {
                $elements.css({
                    'padding-bottom': maxPadding,
                    'min-height': maxHeight
                });
            }
        });
    }
    /**
    * init method binds call of 
    * ["fixHeight"]{@link module:searchEqualHeight.fixHeight} method
    * for window load and resize events
    * @memberOf module:searchEqualHeight
    * @alias module:searchEqualHeight.init
     */
    api.init = function () {
        //Latest Theme version use flexboxes.
        //If you don`t want use flex, you must 
        //uncomment code below

        /* $(document).ready(function() {
             setTimeout(fixHeight, 0);
         });
 
         $(window).bind('resize', function() {
             fixHeight();
         });
         */
    };
    return api;
}(jQuery, document));

XA.register("searchEqualHeight", XA.component.searchEqualHeight);

