(function ($) {
    $.fn.showMore = function (options) {
        "use strict";

        var currentelem = 1;
        this.each(function () {
            var currentid = '';
            var element = $(this);
            var auto = parseInt(element.innerHeight()) / 2;
            var fullheight = element.innerHeight();
            var maxWidth = element.css('width');
            var settings = $.extend({
                minheight: auto,
                buttontxtmore: "show more",
                buttontxtless: "show less",
                buttoncss: "showmore-button",
                animationspeed: auto
            }, options);

            element.attr('id') != undefined ? currentid = element.attr('id') : currentid = currentelem;
            element.wrap("<div id='showmore-" + currentid + "' data-showmore" + (maxWidth == '0px' ? "" : " style='max-width:" + maxWidth + ";'") + "></div>");

            if (element.parent().not('[data-showmore]')) {
                if (fullheight > settings.minheight) {
                    element.css('min-height', settings.minheight).css('max-height', settings.minheight).css('overflow', 'hidden');
                    var showMoreButton = $("<div>", {
                        id: "showmore-button-" + currentid,
                        "class": settings.buttoncss,
                        click: function () {

                            if (element.css('max-height') != 'none') {
                                element.css('height', settings.minheight).css('max-height', '').animate({height: fullheight}, settings.animationspeed, function () {
                                    showMoreButton.html(settings.buttontxtless);
                                });
                                showMoreButton.toggleClass('show');
                            } else {
                                element.animate({height: settings.minheight}, settings.animationspeed, function () {
                                    showMoreButton.html(settings.buttontxtmore);
                                    showMoreButton.toggleClass('show');
                                    element.css('max-height', settings.minheight);
                                });
                            }
                        },
                        html: settings.buttontxtmore
                    });
                    element.after(showMoreButton);
                }
                currentelem++;
            }
        });
        return this;
    };
}(jQuery));

// A simple jQuery modal (http://github.com/kylefox/jquery-modal)
(function (factory) {
    // Making your jQuery plugin work better with npm tools
    // http://blog.npmjs.org/post/112712169830/making-your-jquery-plugin-work-better-with-npm
    if (typeof module === "object" && typeof module.exports === "object") {
        factory(require("jquery"), window, document);
    } else {
        factory(jQuery, window, document);
    }
}(function ($, window, document, undefined) {

    var modals = [],
        getCurrent = function () {
            return modals.length ? modals[modals.length - 1] : null;
        },
        selectCurrent = function () {
            var i,
                selected = false;
            for (i = modals.length - 1; i >= 0; i--) {
                if (modals[i].$blocker) {
                    modals[i].$blocker.toggleClass('current', !selected).toggleClass('behind', selected);
                    selected = true;
                }
            }
        };

    $.modal = function (el, options) {
        var remove, target;
        this.$body = $('body');
        this.options = $.extend({}, $.modal.defaults, options);
        this.options.doFade = !isNaN(parseInt(this.options.fadeDuration, 10));
        this.$blocker = null;
        if (this.options.closeExisting)
            while ($.modal.isActive())
                $.modal.close(); // Close any open modals.
        modals.push(this);
        if (el.is('a')) {
            target = el.attr('href');
            this.anchor = el;
            //Select element by id from href
            if (/^#/.test(target)) {
                this.$elm = $(target);
                if (this.$elm.length !== 1) return null;
                this.$body.append(this.$elm);
                this.open();
                //AJAX
            } else {
                this.$elm = $('<div>');
                this.$body.append(this.$elm);
                remove = function (event, modal) {
                    modal.elm.remove();
                };
                this.showSpinner();
                el.trigger($.modal.AJAX_SEND);
                $.get(target).done(function (html) {
                    if (!$.modal.isActive()) return;
                    el.trigger($.modal.AJAX_SUCCESS);
                    var current = getCurrent();
                    current.$elm.empty().append(html).on($.modal.CLOSE, remove);
                    current.hideSpinner();
                    current.open();
                    el.trigger($.modal.AJAX_COMPLETE);
                }).fail(function () {
                    el.trigger($.modal.AJAX_FAIL);
                    var current = getCurrent();
                    current.hideSpinner();
                    modals.pop(); // remove expected modal from the list
                    el.trigger($.modal.AJAX_COMPLETE);
                });
            }
        } else {
            this.$elm = el;
            this.anchor = el;
            this.$body.append(this.$elm);
            this.open();
        }
    };

    $.modal.prototype = {
        constructor: $.modal,

        open: function () {
            var m = this;
            this.block();
            this.anchor.blur();
            if (this.options.doFade) {
                setTimeout(function () {
                    m.show();
                }, this.options.fadeDuration * this.options.fadeDelay);
            } else {
                this.show();
            }
            $(document).off('keydown.modal').on('keydown.modal', function (event) {
                var current = getCurrent();
                if (event.which === 27 && current.options.escapeClose) current.close();
            });
            if (this.options.clickClose)
                this.$blocker.click(function (e) {
                    if (e.target === this)
                        $.modal.close();
                });
        },

        close: function () {
            modals.pop();
            this.unblock();
            this.hide();
            if (!$.modal.isActive())
                $(document).off('keydown.modal');
        },

        block: function () {
            this.$elm.trigger($.modal.BEFORE_BLOCK, [this._ctx()]);
            this.$body.css('overflow', 'hidden');
            this.$blocker = $('<div class="' + this.options.blockerClass + ' blocker current"></div>').appendTo(this.$body);
            selectCurrent();
            if (this.options.doFade) {
                this.$blocker.css('opacity', 0).animate({opacity: 1}, this.options.fadeDuration);
            }
            this.$elm.trigger($.modal.BLOCK, [this._ctx()]);
        },

        unblock: function (now) {
            if (!now && this.options.doFade)
                this.$blocker.fadeOut(this.options.fadeDuration, this.unblock.bind(this, true));
            else {
                this.$blocker.children().appendTo(this.$body);
                this.$blocker.remove();
                this.$blocker = null;
                selectCurrent();
                if (!$.modal.isActive())
                    this.$body.css('overflow', '');
            }
        },

        show: function () {
            this.$elm.trigger($.modal.BEFORE_OPEN, [this._ctx()]);
            if (this.options.showClose) {
                this.closeButton = $('<a href="#close-modal" rel="modal:close" class="close-modal ' + this.options.closeClass + '">' + this.options.closeText + '</a>');
                this.$elm.append(this.closeButton);
            }
            this.$elm.addClass(this.options.modalClass).appendTo(this.$blocker);
            if (this.options.doFade) {
                this.$elm.css({opacity: 0, display: 'inline-block'}).animate({opacity: 1}, this.options.fadeDuration);
            } else {
                this.$elm.css('display', 'inline-block');
            }
            this.$elm.trigger($.modal.OPEN, [this._ctx()]);
        },

        hide: function () {
            this.$elm.trigger($.modal.BEFORE_CLOSE, [this._ctx()]);
            if (this.closeButton) this.closeButton.remove();
            var _this = this;
            if (this.options.doFade) {
                this.$elm.fadeOut(this.options.fadeDuration, function () {
                    _this.$elm.trigger($.modal.AFTER_CLOSE, [_this._ctx()]);
                });
            } else {
                this.$elm.hide(0, function () {
                    _this.$elm.trigger($.modal.AFTER_CLOSE, [_this._ctx()]);
                });
            }
            this.$elm.trigger($.modal.CLOSE, [this._ctx()]);
        },

        showSpinner: function () {
            if (!this.options.showSpinner) return;
            this.spinner = this.spinner || $('<div class="' + this.options.modalClass + '-spinner"></div>')
                .append(this.options.spinnerHtml);
            this.$body.append(this.spinner);
            this.spinner.show();
        },

        hideSpinner: function () {
            if (this.spinner) this.spinner.remove();
        },

        //Return context for custom events
        _ctx: function () {
            return {
                elm: this.$elm,
                $elm: this.$elm,
                $blocker: this.$blocker,
                options: this.options,
                $anchor: this.anchor
            };
        }
    };

    $.modal.close = function (event) {
        if (!$.modal.isActive()) return;
        if (event) event.preventDefault();
        var current = getCurrent();
        current.close();
        return current.$elm;
    };

    // Returns if there currently is an active modal
    $.modal.isActive = function () {
        return modals.length > 0;
    };

    $.modal.getCurrent = getCurrent;

    $.modal.defaults = {
        closeExisting: true,
        escapeClose: true,
        clickClose: true,
        closeText: '',
        closeClass: '',
        modalClass: "modal",
        blockerClass: "jquery-modal",
        spinnerHtml: '<div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div>',
        showSpinner: true,
        showClose: true,
        fadeDuration: null,   // Number of milliseconds the fade animation takes.
        fadeDelay: 1.0        // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.)
    };

    // Event constants
    $.modal.BEFORE_BLOCK = 'modal:before-block';
    $.modal.BLOCK = 'modal:block';
    $.modal.BEFORE_OPEN = 'modal:before-open';
    $.modal.OPEN = 'modal:open';
    $.modal.BEFORE_CLOSE = 'modal:before-close';
    $.modal.CLOSE = 'modal:close';
    $.modal.AFTER_CLOSE = 'modal:after-close';
    $.modal.AJAX_SEND = 'modal:ajax:send';
    $.modal.AJAX_SUCCESS = 'modal:ajax:success';
    $.modal.AJAX_FAIL = 'modal:ajax:fail';
    $.modal.AJAX_COMPLETE = 'modal:ajax:complete';

    $.fn.modal = function (options) {
        if (this.length === 1) {
            new $.modal(this, options);
        }
        return this;
    };

    // Automatically bind links with rel="modal:close" to, well, close the modal.
    $(document).on('click.modal', 'a[rel~="modal:close"]', $.modal.close);
    $(document).on('click.modal', 'a[rel~="modal:open"]', function (event) {
        event.preventDefault();
        $(this).modal();
    });
}));

/*!
 * jQuery Cookie Plugin v1.4.1
 * https://github.com/carhartl/jquery-cookie
 *
 * Copyright 2006, 2014 Klaus Hartl
 * Released under the MIT license
 */
(function (factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD (Register as an anonymous module)
        define(['jquery'], factory);
    } else if (typeof exports === 'object') {
        // Node/CommonJS
        module.exports = factory(require('jquery'));
    } else {
        // Browser globals
        factory(jQuery);
    }
}(function ($) {

    var pluses = /\+/g;

    function encode(s) {
        return config.raw ? s : encodeURIComponent(s);
    }

    function decode(s) {
        return config.raw ? s : decodeURIComponent(s);
    }

    function stringifyCookieValue(value) {
        return encode(config.json ? JSON.stringify(value) : String(value));
    }

    function parseCookieValue(s) {
        if (s.indexOf('"') === 0) {
            // This is a quoted cookie as according to RFC2068, unescape...
            s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
        }

        try {
            // Replace server-side written pluses with spaces.
            // If we can't decode the cookie, ignore it, it's unusable.
            // If we can't parse the cookie, ignore it, it's unusable.
            s = decodeURIComponent(s.replace(pluses, ' '));
            return config.json ? JSON.parse(s) : s;
        } catch (e) {
        }
    }

    function read(s, converter) {
        var value = config.raw ? s : parseCookieValue(s);
        return $.isFunction(converter) ? converter(value) : value;
    }

    var config = $.cookie = function (key, value, options) {

        // Write

        if (arguments.length > 1 && !$.isFunction(value)) {
            options = $.extend({}, config.defaults, options);

            if (typeof options.expires === 'number') {
                var days = options.expires, t = options.expires = new Date();
                t.setMilliseconds(t.getMilliseconds() + days * 864e+5);
            }

            return (document.cookie = [
                encode(key), '=', stringifyCookieValue(value),
                options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
                options.path ? '; path=' + options.path : '',
                options.domain ? '; domain=' + options.domain : '',
                options.secure ? '; secure' : ''
            ].join(''));
        }

        // Read

        var result = key ? undefined : {},
            // To prevent the for loop in the first place assign an empty array
            // in case there are no cookies at all. Also prevents odd result when
            // calling $.cookie().
            cookies = document.cookie ? document.cookie.split('; ') : [],
            i = 0,
            l = cookies.length;

        for (; i < l; i++) {
            var parts = cookies[i].split('='),
                name = decode(parts.shift()),
                cookie = parts.join('=');

            if (key === name) {
                // If second argument (value) is a function it's a converter...
                result = read(cookie, value);
                break;
            }

            // Prevent storing a cookie that we couldn't decode.
            if (!key && (cookie = read(cookie)) !== undefined) {
                result[name] = cookie;
            }
        }

        return result;
    };

    config.defaults = {};

    $.removeCookie = function (key, options) {
        // Must not alter options, thus extending a fresh object...
        $.cookie(key, '', $.extend({}, options, {expires: -1}));
        return !$.cookie(key);
    };

}));

/**
 * Copyright Marc J. Schmidt. See the LICENSE file at the top-level
 * directory of this distribution and at
 * https://github.com/marcj/css-element-queries/blob/master/LICENSE.
 */
(function () {

    /**
     * Class for dimension change detection.
     *
     * @param {Element|Element[]|Elements|jQuery} element
     * @param {Function} callback
     *
     * @constructor
     */
    var ResizeSensor = function (element, callback) {
        /**
         *
         * @constructor
         */
        function EventQueue() {
            this.q = [];
            this.add = function (ev) {
                this.q.push(ev);
            };

            var i, j;
            this.call = function () {
                for (i = 0, j = this.q.length; i < j; i++) {
                    this.q[i].call();
                }
            };
        }

        /**
         * @param {HTMLElement} element
         * @param {String}      prop
         * @returns {String|Number}
         */
        function getComputedStyle(element, prop) {
            if (element.currentStyle) {
                return element.currentStyle[prop];
            } else if (window.getComputedStyle) {
                return window.getComputedStyle(element, null).getPropertyValue(prop);
            } else {
                return element.style[prop];
            }
        }

        /**
         *
         * @param {HTMLElement} element
         * @param {Function}    resized
         */
        function attachResizeEvent(element, resized) {
            if (!element.resizedAttached) {
                element.resizedAttached = new EventQueue();
                element.resizedAttached.add(resized);
            } else if (element.resizedAttached) {
                element.resizedAttached.add(resized);
                return;
            }

            element.resizeSensor = document.createElement('div');
            element.resizeSensor.className = 'resize-sensor';
            var style = 'position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: hidden; z-index: -1; visibility: hidden;';
            var styleChild = 'position: absolute; left: 0; top: 0; transition: 0s;';

            element.resizeSensor.style.cssText = style;
            element.resizeSensor.innerHTML =
                '<div class="resize-sensor-expand" style="' + style + '">' +
                '<div style="' + styleChild + '"></div>' +
                '</div>' +
                '<div class="resize-sensor-shrink" style="' + style + '">' +
                '<div style="' + styleChild + ' width: 200%; height: 200%"></div>' +
                '</div>';
            element.appendChild(element.resizeSensor);

            if (!{fixed: 1, absolute: 1}[getComputedStyle(element, 'position')]) {
                element.style.position = 'relative';
            }

            var expand = element.resizeSensor.childNodes[0];
            var expandChild = expand.childNodes[0];
            var shrink = element.resizeSensor.childNodes[1];
            var shrinkChild = shrink.childNodes[0];

            var lastWidth, lastHeight;

            var reset = function () {
                expandChild.style.width = expand.offsetWidth + 10 + 'px';
                expandChild.style.height = expand.offsetHeight + 10 + 'px';
                expand.scrollLeft = expand.scrollWidth;
                expand.scrollTop = expand.scrollHeight;
                shrink.scrollLeft = shrink.scrollWidth;
                shrink.scrollTop = shrink.scrollHeight;
                lastWidth = element.offsetWidth;
                lastHeight = element.offsetHeight;
            };

            reset();

            var changed = function () {
                if (element.resizedAttached) {
                    element.resizedAttached.call();
                }
            };

            var addEvent = function (el, name, cb) {
                if (el.attachEvent) {
                    el.attachEvent('on' + name, cb);
                } else {
                    el.addEventListener(name, cb);
                }
            };

            var onScroll = function () {
                if (element.offsetWidth != lastWidth || element.offsetHeight != lastHeight) {
                    changed();
                }
                reset();
            };

            addEvent(expand, 'scroll', onScroll);
            addEvent(shrink, 'scroll', onScroll);
        }

        var elementType = Object.prototype.toString.call(element);
        var isCollectionTyped = ('[object Array]' === elementType
            || ('[object NodeList]' === elementType)
            || ('[object HTMLCollection]' === elementType)
            || ('undefined' !== typeof jQuery && element instanceof jQuery) //jquery
            || ('undefined' !== typeof Elements && element instanceof Elements) //mootools
        );

        if (isCollectionTyped) {
            var i = 0, j = element.length;
            for (; i < j; i++) {
                attachResizeEvent(element[i], callback);
            }
        } else {
            attachResizeEvent(element, callback);
        }

        this.detach = function () {
            if (isCollectionTyped) {
                var i = 0, j = element.length;
                for (; i < j; i++) {
                    ResizeSensor.detach(element[i]);
                }
            } else {
                ResizeSensor.detach(element);
            }
        };
    };

    ResizeSensor.detach = function (element) {
        if (element.resizeSensor) {
            element.removeChild(element.resizeSensor);
            delete element.resizeSensor;
            delete element.resizedAttached;
        }
    };

    // make available to common module loader
    if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
        module.exports = ResizeSensor;
    } else {
        window.ResizeSensor = ResizeSensor;
    }

})();

/*!
 * Theia Sticky Sidebar v1.7.0
 * https://github.com/WeCodePixels/theia-sticky-sidebar
 *
 * Glues your website's sidebars, making them permanently visible while scrolling.
 *
 * Copyright 2013-2016 WeCodePixels and other contributors
 * Released under the MIT license
 */
(function ($) {
    $.fn.theiaStickySidebar = function (options) {
        var defaults = {
            'containerSelector': '',
            'additionalMarginTop': 0,
            'additionalMarginBottom': 0,
            'updateSidebarHeight': true,
            'minWidth': 0,
            'disableOnResponsiveLayouts': true,
            'sidebarBehavior': 'modern',
            'defaultPosition': 'relative',
            'namespace': 'TSS'
        };
        options = $.extend(defaults, options);

        // Validate options
        options.additionalMarginTop = parseInt(options.additionalMarginTop) || 0;
        options.additionalMarginBottom = parseInt(options.additionalMarginBottom) || 0;

        tryInitOrHookIntoEvents(options, this);

        // Try doing init, otherwise hook into window.resize and document.scroll and try again then.
        function tryInitOrHookIntoEvents(options, $that) {
            var success = tryInit(options, $that);

            if (!success) {
                console.log('TSS: Body width smaller than options.minWidth. Init is delayed.');

                $(document).on('scroll.' + options.namespace, function (options, $that) {
                    return function (evt) {
                        var success = tryInit(options, $that);

                        if (success) {
                            $(this).unbind(evt);
                        }
                    };
                }(options, $that));
                $(window).on('resize.' + options.namespace, function (options, $that) {
                    return function (evt) {
                        var success = tryInit(options, $that);

                        if (success) {
                            $(this).unbind(evt);
                        }
                    };
                }(options, $that))
            }
        }

        // Try doing init if proper conditions are met.
        function tryInit(options, $that) {
            if (options.initialized === true) {
                return true;
            }

            if ($('body').width() < options.minWidth) {
                return false;
            }

            init(options, $that);

            return true;
        }

        // Init the sticky sidebar(s).
        function init(options, $that) {
            options.initialized = true;

            // Add CSS
            var existingStylesheet = $('#theia-sticky-sidebar-stylesheet-' + options.namespace);
            if (existingStylesheet.length === 0) {
                $('head').append($('<style id="theia-sticky-sidebar-stylesheet-' + options.namespace + '">.theiaStickySidebar:after {content: ""; display: table; clear: both;}</style>'));
            }

            $that.each(function () {
                var o = {};

                o.sidebar = $(this);

                // Save options
                o.options = options || {};

                // Get container
                o.container = $(o.options.containerSelector);
                if (o.container.length == 0) {
                    o.container = o.sidebar.parent();
                }

                // Create sticky sidebar
                o.sidebar.parents().css('-webkit-transform', 'none'); // Fix for WebKit bug - https://code.google.com/p/chromium/issues/detail?id=20574
                o.sidebar.css({
                    'position': o.options.defaultPosition,
                    'overflow': 'visible',
                    // The "box-sizing" must be set to "content-box" because we set a fixed height to this element when the sticky sidebar has a fixed position.
                    '-webkit-box-sizing': 'border-box',
                    '-moz-box-sizing': 'border-box',
                    'box-sizing': 'border-box'
                });

                // Get the sticky sidebar element. If none has been found, then create one.
                o.stickySidebar = o.sidebar.find('.theiaStickySidebar');
                if (o.stickySidebar.length == 0) {
                    // Remove <script> tags, otherwise they will be run again when added to the stickySidebar.
                    var javaScriptMIMETypes = /(?:text|application)\/(?:x-)?(?:javascript|ecmascript)/i;
                    o.sidebar.find('script').filter(function (index, script) {
                        return script.type.length === 0 || script.type.match(javaScriptMIMETypes);
                    }).remove();

                    o.stickySidebar = $('<div>').addClass('theiaStickySidebar').append(o.sidebar.children());
                    o.sidebar.append(o.stickySidebar);
                }

                // Get existing top and bottom margins and paddings
                o.marginBottom = parseInt(o.sidebar.css('margin-bottom'));
                o.paddingTop = parseInt(o.sidebar.css('padding-top'));
                o.paddingBottom = parseInt(o.sidebar.css('padding-bottom'));

                // Add a temporary padding rule to check for collapsable margins.
                var collapsedTopHeight = o.stickySidebar.offset().top;
                var collapsedBottomHeight = o.stickySidebar.outerHeight();
                o.stickySidebar.css('padding-top', 1);
                o.stickySidebar.css('padding-bottom', 1);
                collapsedTopHeight -= o.stickySidebar.offset().top;
                collapsedBottomHeight = o.stickySidebar.outerHeight() - collapsedBottomHeight - collapsedTopHeight;
                if (collapsedTopHeight == 0) {
                    o.stickySidebar.css('padding-top', 0);
                    o.stickySidebarPaddingTop = 0;
                } else {
                    o.stickySidebarPaddingTop = 1;
                }

                if (collapsedBottomHeight == 0) {
                    o.stickySidebar.css('padding-bottom', 0);
                    o.stickySidebarPaddingBottom = 0;
                } else {
                    o.stickySidebarPaddingBottom = 1;
                }

                // We use this to know whether the user is scrolling up or down.
                o.previousScrollTop = null;

                // Scroll top (value) when the sidebar has fixed position.
                o.fixedScrollTop = 0;

                // Set sidebar to default values.
                resetSidebar();

                o.onScroll = function (o) {
                    // Stop if the sidebar isn't visible.
                    if (!o.stickySidebar.is(":visible")) {
                        return;
                    }

                    // Stop if the window is too small.
                    if ($('body').width() < o.options.minWidth) {
                        resetSidebar();
                        return;
                    }

                    // Stop if the sidebar width is larger than the container width (e.g. the theme is responsive and the sidebar is now below the content)
                    if (o.options.disableOnResponsiveLayouts) {
                        var sidebarWidth = o.sidebar.outerWidth(o.sidebar.css('float') == 'none');

                        if (sidebarWidth + 50 > o.container.width()) {
                            resetSidebar();
                            return;
                        }
                    }

                    var scrollTop = $(document).scrollTop();
                    var position = 'static';

                    // If the user has scrolled down enough for the sidebar to be clipped at the top, then we can consider changing its position.
                    if (scrollTop >= o.sidebar.offset().top + (o.paddingTop - o.options.additionalMarginTop)) {
                        // The top and bottom offsets, used in various calculations.
                        var offsetTop = o.paddingTop + options.additionalMarginTop;
                        var offsetBottom = o.paddingBottom + o.marginBottom + options.additionalMarginBottom;

                        // All top and bottom positions are relative to the window, not to the parent elemnts.
                        var containerTop = o.sidebar.offset().top;
                        var containerBottom = o.sidebar.offset().top + getClearedHeight(o.container);

                        // The top and bottom offsets relative to the window screen top (zero) and bottom (window height).
                        var windowOffsetTop = 0 + options.additionalMarginTop;
                        var windowOffsetBottom;

                        var sidebarSmallerThanWindow = (o.stickySidebar.outerHeight() + offsetTop + offsetBottom) < $(window).height();
                        if (sidebarSmallerThanWindow) {
                            windowOffsetBottom = windowOffsetTop + o.stickySidebar.outerHeight();
                        } else {
                            windowOffsetBottom = $(window).height() - o.marginBottom - o.paddingBottom - options.additionalMarginBottom;
                        }

                        var staticLimitTop = containerTop - scrollTop + o.paddingTop;
                        var staticLimitBottom = containerBottom - scrollTop - o.paddingBottom - o.marginBottom;

                        var top = o.stickySidebar.offset().top - scrollTop;
                        var scrollTopDiff = o.previousScrollTop - scrollTop;

                        // If the sidebar position is fixed, then it won't move up or down by itself. So, we manually adjust the top coordinate.
                        if (o.stickySidebar.css('position') == 'fixed') {
                            if (o.options.sidebarBehavior == 'modern') {
                                top += scrollTopDiff;
                            }
                        }

                        if (o.options.sidebarBehavior == 'stick-to-top') {
                            top = options.additionalMarginTop;
                        }

                        if (o.options.sidebarBehavior == 'stick-to-bottom') {
                            top = windowOffsetBottom - o.stickySidebar.outerHeight();
                        }

                        if (scrollTopDiff > 0) { // If the user is scrolling up.
                            top = Math.min(top, windowOffsetTop);
                        } else { // If the user is scrolling down.
                            top = Math.max(top, windowOffsetBottom - o.stickySidebar.outerHeight());
                        }

                        top = Math.max(top, staticLimitTop);

                        top = Math.min(top, staticLimitBottom - o.stickySidebar.outerHeight());

                        // If the sidebar is the same height as the container, we won't use fixed positioning.
                        var sidebarSameHeightAsContainer = o.container.height() == o.stickySidebar.outerHeight();

                        if (!sidebarSameHeightAsContainer && top == windowOffsetTop) {
                            position = 'fixed';
                        } else if (!sidebarSameHeightAsContainer && top == windowOffsetBottom - o.stickySidebar.outerHeight()) {
                            position = 'fixed';
                        } else if (scrollTop + top - o.sidebar.offset().top - o.paddingTop <= options.additionalMarginTop) {
                            // Stuck to the top of the page. No special behavior.
                            position = 'static';
                        } else {
                            // Stuck to the bottom of the page.
                            position = 'absolute';
                        }
                    }

                    /*
                     * Performance notice: It's OK to set these CSS values at each resize/scroll, even if they don't change.
                     * It's way slower to first check if the values have changed.
                     */
                    if (position == 'fixed') {
                        var scrollLeft = $(document).scrollLeft();

                        o.stickySidebar.css({
                            'position': 'fixed',
                            'width': getWidthForObject(o.stickySidebar) + 'px',
                            'transform': 'translateY(' + top + 'px)',
                            'left': (o.sidebar.offset().left + parseInt(o.sidebar.css('padding-left')) - scrollLeft) + 'px',
                            'top': '0px'
                        });
                    } else if (position == 'absolute') {
                        var css = {};

                        if (o.stickySidebar.css('position') != 'absolute') {
                            css.position = 'absolute';
                            css.transform = 'translateY(' + (scrollTop + top - o.sidebar.offset().top - o.stickySidebarPaddingTop - o.stickySidebarPaddingBottom) + 'px)';
                            css.top = '0px';
                        }

                        css.width = getWidthForObject(o.stickySidebar) + 'px';
                        css.left = '';

                        o.stickySidebar.css(css);
                    } else if (position == 'static') {
                        resetSidebar();
                    }

                    if (position != 'static') {
                        if (o.options.updateSidebarHeight == true) {
                            o.sidebar.css({
                                'min-height': o.stickySidebar.outerHeight() + o.stickySidebar.offset().top - o.sidebar.offset().top + o.paddingBottom
                            });
                        }
                    }

                    o.previousScrollTop = scrollTop;
                };

                // Initialize the sidebar's position.
                o.onScroll(o);

                // Recalculate the sidebar's position on every scroll and resize.
                $(document).on('scroll.' + o.options.namespace, function (o) {
                    return function () {
                        o.onScroll(o);
                    };
                }(o));
                $(window).on('resize.' + o.options.namespace, function (o) {
                    return function () {
                        o.stickySidebar.css({'position': 'static'});
                        o.onScroll(o);
                    };
                }(o));

                // Recalculate the sidebar's position every time the sidebar changes its size.
                if (typeof ResizeSensor !== 'undefined') {
                    new ResizeSensor(o.stickySidebar[0], function (o) {
                        return function () {
                            o.onScroll(o);
                        };
                    }(o));
                }

                // Reset the sidebar to its default state
                function resetSidebar() {
                    o.fixedScrollTop = 0;
                    o.sidebar.css({
                        'min-height': '1px'
                    });
                    o.stickySidebar.css({
                        'position': 'static',
                        'width': '',
                        'transform': 'none'
                    });
                }

                // Get the height of a div as if its floated children were cleared. Note that this function fails if the floats are more than one level deep.
                function getClearedHeight(e) {
                    var height = e.height();

                    e.children().each(function () {
                        height = Math.max(height, $(this).height());
                    });

                    return height;
                }
            });
        }

        function getWidthForObject(object) {
            var width;

            try {
                width = object[0].getBoundingClientRect().width;
            } catch (err) {
            }

            if (typeof width === "undefined") {
                width = object.width();
            }

            return width;
        }

        return this;
    }
})(jQuery);

/*! owl.carousel2.thumbs - v0.1.8 | (c) 2016 @gijsroge | MIT license | https://github.com/gijsroge/OwlCarousel2-Thumbs */
/**
 * Thumbs Plugin
 * @version 2.0.0
 * @author Gijs RogÃ©
 * @license The MIT License (MIT)
 */
(function ($, window, document, undefined) {
    'use strict';

    /**
     * Creates the thumbs plugin.
     * @class The thumbs Plugin
     * @param {Owl} carousel - The Owl Carousel
     */
    var Thumbs = function (carousel) {


        /**
         * Reference to the core.
         * @protected
         * @type {Owl}
         */
        this.owl = carousel;


        /**
         * All DOM elements for thumbnails
         * @protected
         * @type {Object}
         */
        this._thumbcontent = [];


        /**
         * Instance identiefier
         * @type {number}
         * @private
         */
        this._identifier = 0;


        /**
         * Return current item regardless of clones
         * @protected
         * @type {Object}
         */
        this.owl_currentitem = this.owl.options.startPosition;


        /**
         * The carousel element.
         * @type {jQuery}
         */
        this.$element = this.owl.$element;


        /**
         * All event handlers.
         * @protected
         * @type {Object}
         */
        this._handlers = {
            'prepared.owl.carousel': $.proxy(function (e) {
                if (e.namespace && this.owl.options.thumbs && !this.owl.options.thumbImage && !this.owl.options.thumbsPrerendered && !this.owl.options.thumbImage) {
                    if ($(e.content).find('[data-thumb]').attr('data-thumb') !== undefined) {
                        this._thumbcontent.push($(e.content).find('[data-thumb]').attr('data-thumb'));
                    }
                } else if (e.namespace && this.owl.options.thumbs && this.owl.options.thumbImage) {
                    var innerImage = $(e.content).find('img');
                    this._thumbcontent.push(innerImage);
                }
            }, this),

            'initialized.owl.carousel': $.proxy(function (e) {
                if (e.namespace && this.owl.options.thumbs) {
                    this.render();
                    this.listen();
                    this._identifier = this.owl.$element.data('slider-id');
                    this.setActive();
                }
            }, this),

            'changed.owl.carousel': $.proxy(function (e) {
                if (e.namespace && e.property.name === 'position' && this.owl.options.thumbs) {
                    this._identifier = this.owl.$element.data('slider-id');
                    this.setActive();
                }
            }, this)
        };

        // set default options
        this.owl.options = $.extend({}, Thumbs.Defaults, this.owl.options);

        // register the event handlers
        this.owl.$element.on(this._handlers);
    };


    /**
     * Default options.
     * @public
     */
    Thumbs.Defaults = {
        thumbs: true,
        thumbImage: false,
        thumbContainerClass: 'owl-thumbs',
        thumbItemClass: 'owl-thumb-item',
        moveThumbsInside: false
    };


    /**
     * Listen for thumbnail click
     * @protected
     */
    Thumbs.prototype.listen = function () {

        //set default options
        var options = this.owl.options;

        if (options.thumbsPrerendered) {
            this._thumbcontent._thumbcontainer = $('.' + options.thumbContainerClass);
        }

        //check what thumbitem has been clicked and move slider to that item
        $(this._thumbcontent._thumbcontainer).on('click', this._thumbcontent._thumbcontainer.children(), $.proxy(function (e) {

            // find relative slider
            this._identifier = $(e.target).closest('.' + options.thumbContainerClass).data('slider-id');

            // get index of clicked thumbnail
            var index = $(e.target).parent().is(this._thumbcontent._thumbcontainer) ? $(e.target).index() : $(e.target).closest('.' + options.thumbItemClass).index();

            if (options.thumbsPrerendered) {
                // slide to slide :)
                $('[data-slider-id=' + this._identifier + ']').trigger('to.owl.carousel', [index, options.dotsSpeed, true]);
            } else {
                this.owl.to(index, options.dotsSpeed);
            }

            e.preventDefault();
        }, this));
    };


    /**
     * Builds thumbnails
     * @protected
     */
    Thumbs.prototype.render = function () {

        //set default options
        var options = this.owl.options;

        //create thumbcontainer
        if (!options.thumbsPrerendered) {
            this._thumbcontent._thumbcontainer = $('<div>').addClass(options.thumbContainerClass).appendTo(this.$element);
        } else {
            this._thumbcontent._thumbcontainer = $('.' + options.thumbContainerClass + '');
            if (options.moveThumbsInside) {
                this._thumbcontent._thumbcontainer.appendTo(this.$element);
            }
        }

        //create thumb items
        var i;
        if (!options.thumbImage) {
            for (i = 0; i < this._thumbcontent.length; ++i) {
                this._thumbcontent._thumbcontainer.append('<button class=' + options.thumbItemClass + '>' + this._thumbcontent[i] + '</button>');
            }
        } else {
            for (i = 0; i < this._thumbcontent.length; ++i) {
                this._thumbcontent._thumbcontainer.append('<button class=' + options.thumbItemClass + '><img src="' + this._thumbcontent[i].attr('src') + '" alt="' + this._thumbcontent[i].attr('alt') + '" /></button>');
            }
        }
    };


    /**
     * Updates active class on thumbnails
     * @protected
     */
    Thumbs.prototype.setActive = function () {

        // get startslide
        this.owl_currentitem = this.owl._current - (this.owl._clones.length / 2);
        if (this.owl_currentitem === this.owl._items.length) {
            this.owl_currentitem = 0;
        }

        //set default options
        var options = this.owl.options;

        // set relative thumbnail container
        var thumbContainer = options.thumbsPrerendered ? $('.' + options.thumbContainerClass + '[data-slider-id="' + this._identifier + '"]') : this._thumbcontent._thumbcontainer;
        thumbContainer.children().filter('.active').removeClass('active');
        thumbContainer.children().eq(this.owl_currentitem).addClass('active');
    };


    /**
     * Destroys the plugin.
     * @public
     */
    Thumbs.prototype.destroy = function () {
        var handler, property;
        for (handler in this._handlers) {
            this.owl.$element.off(handler, this._handlers[handler]);
        }
        for (property in Object.getOwnPropertyNames(this)) {
            typeof this[property] !== 'function' && (this[property] = null);
        }
    };

    $.fn.owlCarousel.Constructor.Plugins.Thumbs = Thumbs;

})(window.Zepto || window.jQuery, window, document);

// jQuery toast plugin created by Kamran Ahmed copyright MIT license 2015
// https://github.com/kamranahmedse/jquery-toast-plugin
if (typeof Object.create !== 'function') {
    Object.create = function (obj) {
        function F() {
        }

        F.prototype = obj;
        return new F();
    };
}

(function ($, window, document, undefined) {

    "use strict";

    var Toast = {

        _positionClasses: ['bottom-left', 'bottom-right', 'top-right', 'top-left', 'bottom-center', 'top-center', 'mid-center'],
        _defaultIcons: ['success', 'error', 'info', 'warning'],

        init: function (options, elem) {
            this.prepareOptions(options, $.toast.options);
            this.process();
        },

        prepareOptions: function (options, options_to_extend) {
            var _options = {};
            if ((typeof options === 'string') || (options instanceof Array)) {
                _options.text = options;
            } else {
                _options = options;
            }
            this.options = $.extend({}, options_to_extend, _options);
        },

        process: function () {
            this.setup();
            this.addToDom();
            this.position();
            this.bindToast();
            this.animate();
        },

        setup: function () {

            var _toastContent = '';

            this._toastEl = this._toastEl || $('<div></div>', {
                class: 'jq-toast-single'
            });

            // For the loader on top
            _toastContent += '<span class="jq-toast-loader"></span>';

            if (this.options.allowToastClose) {
                _toastContent += '<span class="close-jq-toast-single">&times;</span>';
            }
            ;

            if (this.options.text instanceof Array) {

                if (this.options.heading) {
                    _toastContent += '<h2 class="jq-toast-heading">' + this.options.heading + '</h2>';
                }
                ;

                _toastContent += '<ul class="jq-toast-ul">';
                for (var i = 0; i < this.options.text.length; i++) {
                    _toastContent += '<li class="jq-toast-li" id="jq-toast-item-' + i + '">' + this.options.text[i] + '</li>';
                }
                _toastContent += '</ul>';

            } else {
                if (this.options.heading) {
                    _toastContent += '<h2 class="jq-toast-heading">' + this.options.heading + '</h2>';
                }
                ;
                _toastContent += this.options.text;
            }

            this._toastEl.html(_toastContent);

            if (this.options.bgColor !== false) {
                this._toastEl.css("background-color", this.options.bgColor);
            }
            ;

            if (this.options.textColor !== false) {
                this._toastEl.css("color", this.options.textColor);
            }
            ;

            if (this.options.textAlign) {
                this._toastEl.css('text-align', this.options.textAlign);
            }

            if (this.options.icon !== false) {
                this._toastEl.addClass('jq-has-icon');

                if ($.inArray(this.options.icon, this._defaultIcons) !== -1) {
                    this._toastEl.addClass('jq-icon-' + this.options.icon);
                }
                ;
            }
            ;

            if (this.options.class !== false) {
                this._toastEl.addClass(this.options.class)
            }
        },

        position: function () {
            if ((typeof this.options.position === 'string') && ($.inArray(this.options.position, this._positionClasses) !== -1)) {

                if (this.options.position === 'bottom-center') {
                    this._container.css({
                        left: ($(window).outerWidth() / 2) - this._container.outerWidth() / 2,
                        bottom: 7
                    });
                } else if (this.options.position === 'top-center') {
                    this._container.css({
                        left: ($(window).outerWidth() / 2) - this._container.outerWidth() / 2,
                        top: 20
                    });
                } else if (this.options.position === 'mid-center') {
                    this._container.css({
                        left: ($(window).outerWidth() / 2) - this._container.outerWidth() / 2,
                        top: ($(window).outerHeight() / 2) - this._container.outerHeight() / 2
                    });
                } else {
                    this._container.addClass(this.options.position);
                }

            } else if (typeof this.options.position === 'object') {
                this._container.css({
                    top: this.options.position.top ? this.options.position.top : 'auto',
                    bottom: this.options.position.bottom ? this.options.position.bottom : 'auto',
                    left: this.options.position.left ? this.options.position.left : 'auto',
                    right: this.options.position.right ? this.options.position.right : 'auto'
                });
            } else {
                this._container.addClass('bottom-left');
            }
        },

        bindToast: function () {

            var that = this;

            this._toastEl.on('afterShown', function () {
                that.processLoader();
            });

            this._toastEl.find('.close-jq-toast-single').on('click', function (e) {

                e.preventDefault();

                if (that.options.showHideTransition === 'fade') {
                    that._toastEl.trigger('beforeHide');
                    that._toastEl.fadeOut(function () {
                        that._toastEl.trigger('afterHidden');
                    });
                } else if (that.options.showHideTransition === 'slide') {
                    that._toastEl.trigger('beforeHide');
                    that._toastEl.slideUp(function () {
                        that._toastEl.trigger('afterHidden');
                    });
                } else {
                    that._toastEl.trigger('beforeHide');
                    that._toastEl.hide(function () {
                        that._toastEl.trigger('afterHidden');
                    });
                }
            });

            if (typeof this.options.beforeShow == 'function') {
                this._toastEl.on('beforeShow', function () {
                    that.options.beforeShow(that._toastEl);
                });
            }
            ;

            if (typeof this.options.afterShown == 'function') {
                this._toastEl.on('afterShown', function () {
                    that.options.afterShown(that._toastEl);
                });
            }
            ;

            if (typeof this.options.beforeHide == 'function') {
                this._toastEl.on('beforeHide', function () {
                    that.options.beforeHide(that._toastEl);
                });
            }
            ;

            if (typeof this.options.afterHidden == 'function') {
                this._toastEl.on('afterHidden', function () {
                    that.options.afterHidden(that._toastEl);
                });
            }
            ;

            if (typeof this.options.onClick == 'function') {
                this._toastEl.on('click', function () {
                    that.options.onClick(that._toastEl);
                });
            }
            ;
        },

        addToDom: function () {

            var _container = $('.jq-toast-wrap');

            if (_container.length === 0) {

                _container = $('<div></div>', {
                    class: "jq-toast-wrap",
                    role: "alert",
                    "aria-live": "polite"
                });

                $('body').append(_container);

            } else if (!this.options.stack || isNaN(parseInt(this.options.stack, 10))) {
                _container.empty();
            }

            _container.find('.jq-toast-single:hidden').remove();

            _container.append(this._toastEl);

            if (this.options.stack && !isNaN(parseInt(this.options.stack), 10)) {

                var _prevToastCount = _container.find('.jq-toast-single').length,
                    _extToastCount = _prevToastCount - this.options.stack;

                if (_extToastCount > 0) {
                    $('.jq-toast-wrap').find('.jq-toast-single').slice(0, _extToastCount).remove();
                }
                ;

            }

            this._container = _container;
        },

        canAutoHide: function () {
            return (this.options.hideAfter !== false) && !isNaN(parseInt(this.options.hideAfter, 10));
        },

        processLoader: function () {
            // Show the loader only, if auto-hide is on and loader is demanded
            if (!this.canAutoHide() || this.options.loader === false) {
                return false;
            }

            var loader = this._toastEl.find('.jq-toast-loader');

            // 400 is the default time that jquery uses for fade/slide
            // Divide by 1000 for milliseconds to seconds conversion
            var transitionTime = (this.options.hideAfter - 400) / 1000 + 's';
            var loaderBg = this.options.loaderBg;

            var style = loader.attr('style') || '';
            style = style.substring(0, style.indexOf('-webkit-transition')); // Remove the last transition definition

            style += '-webkit-transition: width ' + transitionTime + ' ease-in; \
                      -o-transition: width ' + transitionTime + ' ease-in; \
                      transition: width ' + transitionTime + ' ease-in; \
                      background-color: ' + loaderBg + ';';


            loader.attr('style', style).addClass('jq-toast-loaded');
        },

        animate: function () {

            var that = this;

            this._toastEl.hide();

            this._toastEl.trigger('beforeShow');

            if (this.options.showHideTransition.toLowerCase() === 'fade') {
                this._toastEl.fadeIn(function () {
                    that._toastEl.trigger('afterShown');
                });
            } else if (this.options.showHideTransition.toLowerCase() === 'slide') {
                this._toastEl.slideDown(function () {
                    that._toastEl.trigger('afterShown');
                });
            } else {
                this._toastEl.show(function () {
                    that._toastEl.trigger('afterShown');
                });
            }

            if (this.canAutoHide()) {

                var that = this;

                window.setTimeout(function () {

                    if (that.options.showHideTransition.toLowerCase() === 'fade') {
                        that._toastEl.trigger('beforeHide');
                        that._toastEl.fadeOut(function () {
                            that._toastEl.trigger('afterHidden');
                        });
                    } else if (that.options.showHideTransition.toLowerCase() === 'slide') {
                        that._toastEl.trigger('beforeHide');
                        that._toastEl.slideUp(function () {
                            that._toastEl.trigger('afterHidden');
                        });
                    } else {
                        that._toastEl.trigger('beforeHide');
                        that._toastEl.hide(function () {
                            that._toastEl.trigger('afterHidden');
                        });
                    }

                }, this.options.hideAfter);
            }
            ;
        },

        reset: function (resetWhat) {

            if (resetWhat === 'all') {
                $('.jq-toast-wrap').remove();
            } else {
                this._toastEl.remove();
            }

        },

        update: function (options) {
            this.prepareOptions(options, this.options);
            this.setup();
            this.bindToast();
        },

        close: function () {
            this._toastEl.find('.close-jq-toast-single').click();
        }
    };

    $.toast = function (options) {
        var toast = Object.create(Toast);
        toast.init(options, this);

        return {

            reset: function (what) {
                toast.reset(what);
            },

            update: function (options) {
                toast.update(options);
            },

            close: function () {
                toast.close();
            }
        }
    };

    $.toast.options = {
        text: '',
        heading: '',
        showHideTransition: 'fade',
        allowToastClose: true,
        hideAfter: 3000,
        loader: true,
        loaderBg: '#9EC600',
        stack: 5,
        position: 'bottom-left',
        bgColor: false,
        textColor: false,
        textAlign: 'left',
        icon: false,
        beforeShow: function () {
        },
        afterShown: function () {
        },
        beforeHide: function () {
        },
        afterHidden: function () {
        },
        onClick: function () {
        }
    };

})(jQuery, window, document);

jQuery(document).ready(function ($) {

    var sectionHeight = $('.main-header').outerHeight(true) + $('.cat-menu').outerHeight(true);
    $('<style type="text/css">body.archive-amazing:after {height: ' + sectionHeight + 'px; top: ' + sectionHeight + 'px;}</style>').appendTo('head');

    $('.nav-tabs button').click(function () {
        var $this = $(this);
        var dataPane = $this.data('pane');
        $this.addClass('active');
        $this.siblings('button').removeClass('active');
        $('#' + dataPane).show();
        $('#' + dataPane).siblings('.tab-pane').hide();
    });
    $('.nav-tabs button:first-child').addClass('active');

    if ($('#popup-ads').length) {
        $.cookie('irk-show-popup', 1, {expires: 1, path: '/'});
        $('#popup-ads').modal();
    }

    if ($('#notifications-modal').length && !$.cookie('irk-show-notifications-modal')) {
        $.cookie('irk-show-notifications-modal', 1, {expires: 1, path: '/'});
        $('#notifications-modal').modal();
    }


    var modalLoader = $('.modal-loader-wrapper');

    $(document).on('click', function (e) {
        $('.main-header .dropdown-toggle').removeClass('show');
    });
    $('.main-header .dropdown-toggle').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        $(this).toggleClass('show');
    });

    if ($('.cat-menu').length && !$('body').hasClass('demo2')) {
        $(function () {
            'use strict';

            $('.cat-menu').append("<li id='magic-line'></li>");
            var magicLine = $('#magic-line');

            if ($('body').hasClass('rtl')) {
                magicLine.data('origRight', ($('#cat-menu').width() - (magicLine.width() + magicLine.position().left))).data('origWidth', magicLine.width());

                $('.cat-menu > .menu-item').hover(function () {
                    var $thisBar = $(this);
                    var rightPos = $('.cat-menu').width() - ($thisBar.width() + $thisBar.position().left);
                    var newWidth = $thisBar.width();
                    magicLine.css({
                        "right": rightPos,
                        "width": newWidth
                    });
                }, function () {
                    magicLine.css({
                        "right": magicLine.data('origRight'),
                        "width": magicLine.data('origWidth')
                    });
                });
            } else {
                magicLine.data('origLeft', magicLine.position().left).data('origWidth', magicLine.width());

                $('.cat-menu > .menu-item').hover(function () {
                    var $thisBar = $(this);
                    var leftPos = $thisBar.position().left;
                    var newWidth = $thisBar.width();
                    magicLine.css({
                        "left": leftPos,
                        "width": newWidth
                    });
                }, function () {
                    magicLine.css({
                        "left": magicLine.data('origLeft'),
                        "width": magicLine.data('origWidth')
                    });
                });
            }
        });
    }

    var newMenuHeight = $(window.top).height() - ($('.main-header').height() + $('#cat-menu').height());
    var megaMenuWidth = $('.cat-menu').width() - 220;
    var megaMenuHeight = IRK_DATA.mega_menu_height / 100;
    $('.cat-menu .mega-menu-main-item > .sub-menu').height(newMenuHeight * megaMenuHeight);
    $('.cat-menu .mega-menu-main-item .sub-menu > .mega-menu > .sub-menu').height(newMenuHeight * megaMenuHeight);
    $('.cat-menu .mega-menu-main-item > .sub-menu > .mega-menu > .sub-menu').width(megaMenuWidth);
    $('.cat-menu > .menu-item-has-children').hover(function () {
        $('.overlay').css({'opacity': 1});
    }, function () {
        $('.overlay').css({'opacity': 0});
    });

    $('.cat-menu .mega-menu-main-item').hover(function () {
        $(this).find('> .sub-menu').addClass('active');
    });
    $('.cat-menu .mega-menu-main-item > .sub-menu > .menu-item').mouseout(function (e) {
        $(this).parentsUntil('.mega-menu-main-item').removeClass('active');
    });

    var lastScrollTop = 0, st, direction;

    function detectDirection() {
        st = window.pageYOffset;
        if (st > lastScrollTop) {
            direction = "down";
        } else {
            direction = "up";
        }
        lastScrollTop = st;
        return direction;
    }

    if (IRK_DATA.sticky_header && !$('body.home').hasClass('demo2')) {
        var catMenuTop = $('.main-header').height();
        if ($('#wpadminbar').length) {
            catMenuTop = catMenuTop + $('#wpadminbar').height();
        }
        $('#cat-menu').css({'top': catMenuTop});
        $(window).bind('scroll', function () {
            var dir = detectDirection();
            var catMenu = $('#cat-menu');
            if (dir === 'down') {
                catMenu.css({'top': catMenuTop - catMenu.height() - 1});
            } else if (dir === 'up') {
                catMenu.css({'top': catMenuTop});
            }
        });
    }
    if ($('body').hasClass('home') && $('body').hasClass('demo2')) {
        var catMenuTop = $('.main-header').height();
        if ($('#wpadminbar').length) {
            catMenuTop = catMenuTop + $('#wpadminbar').height();
        }
        $('#cat-menu').css({'top': catMenuTop});
    }

    var searchInput = $('.search-form input[type=text]');
    searchInput.focus(function () {
        $('.main-header').addClass('focus-search');
    });
    searchInput.blur(function () {
        $('.main-header').removeClass('focus-search');
    });

    var nonce = $('meta[name="irk-nonce"]').attr('content');
    var $reset = searchInput.next('.reset');
    var searchResult = $('.search-form + .search-results');
    var _cat = $('.search-form #_cat');
    searchInput.on('input', function () {
        var $this = $(this);
        var searchTerm = $this.val();
        $reset.show();
        if (searchTerm.length < 2) {
            searchResult.hide();
            $reset.hide();
            $this.removeClass('focused');
            return false;
        }

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_search_product',
                searchTerm: searchTerm,
                _cat: _cat.val(),
                nonce: nonce
            },
            success: function (response) {
                if (response.search_results !== '') {
                    searchResult.html(response.search_results).fadeIn();
                    $this.addClass('focused');
                } else {
                    searchResult.empty().hide();
                    $this.removeClass('focused');
                }
            },
            error: function () {
                searchResult.empty().hide();
                $this.removeClass('focused');
            },
            complete: function (data) {

            }
        });
    });
    $(window).click(function () {
        searchResult.empty().hide();
        searchInput.val('');
        searchInput.removeClass('focused');
        $reset.hide();
    });
    $('.search-form').click(function (event) {
        event.stopPropagation();
    });
    $reset.click(function () {
        searchResult.empty().hide();
        searchInput.val('');
        searchInput.removeClass('focused');
        $reset.hide();
    });

    $('.compare-search').on('submit', function (e) {
        e.preventDefault();
        var $this = $(this);
        var searchTerm = $this.find('input[type=text]').val();
        var searchResult = $('#compare-modal .search-results');
        var productCat = $this.find('#product_cat');
        if (searchTerm.length < 2) {
            searchResult.empty().hide();
            return false;
        }

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_compare_search_product',
                searchTerm: searchTerm,
                productCat: productCat.val(),
                nonce: nonce
            },
            success: function (response) {
                if (response._result !== '') {
                    searchResult.html(response.search_results).fadeIn();
                } else {
                    searchResult.empty().hide();
                }
            },
            error: function () {
                searchResult.empty().hide();
            },
            complete: function (data) {
            }
        });
    });

    $('.overlay').click(function (e) {
        $('body').removeClass('show-cat-menu');
    });
    $('#cat-toggle').click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        $('body').addClass('show-cat-menu');
    });

    $('#cat-menu .menu-item-has-children > a').prepend('<span class="plus" data-icon="plus"></span>');
    $(document).on('click', '#cat-menu .menu-item-has-children .plus', function (e) {
        e.preventDefault();
        var $this = $(this);
        $this.toggleClass('show');
        $this.parentsUntil('.menu-item-has-children').next('.sub-menu').toggle();
        if ($this.hasClass('show')) {
            $this.attr('data-icon', 'minus');
        } else {
            $this.attr('data-icon', 'plus');
        }
    });

    $('#top-toggle').click(function (e) {
        e.preventDefault();
        $('.top-menu ul.menu').slideToggle();
    });

    $('.mainbar .widget_products, .mainbar .widget_recently_viewed_products, .mainbar .widget_top_rated_products').addClass('widget-products-slider');
    $('.mainbar .widget_products .product_list_widget, .mainbar .widget_recently_viewed_products .product_list_widget, .mainbar .widget_top_rated_products .product_list_widget').addClass('owl-carousel').wrap('<div class="slider-inner"></div>');
    $('.mainbar .widget_products .header h3, .mainbar .widget_recently_viewed_products .header h3, .mainbar .widget_top_rated_products .header h3').addClass('title').wrapInner('<span></span>');
    $('.mainbar .widget_products .header h3 span').prepend('<span class="icon mdi mdi-shopping-outline"></span>');
    $('.mainbar .widget_recently_viewed_products .header h3 span').prepend('<span class="icon mdi mdi-eye-check-outline"></span>');
    $('.mainbar .widget_top_rated_products .header h3 span').prepend('<span class="icon mdi mdi-star-outline"></span>');
    $('.mainbar .widget_products .product_list_widget li, .mainbar .widget_recently_viewed_products .product_list_widget li, .mainbar .widget_top_rated_products .product_list_widget li').wrap('<div class="item"></div>');
    $('.mainbar .widget_products .product_list_widget li img, .mainbar .widget_recently_viewed_products .product_list_widget li img, .mainbar .widget_top_rated_products .product_list_widget li img').wrap('<div class="img-wrapper"></div>');
    $('.mainbar .widget_products .product_list_widget li .product-title, .mainbar .widget_recently_viewed_products .product_list_widget li .product-title, .mainbar .widget_top_rated_products .product_list_widget li .product-title').wrap('<div class="title"></div>');

    $('.elementor-widget-wp-widget-irk_banner_ads .elementor-widget-container').addClass('widget-ads widget');
    $('.elementor-widget-wp-widget-irk_posts_slider .elementor-widget-container').addClass('widget-posts-slider widget');
    //$('.elementor-widget-wp-widget-irk_products_slider .elementor-widget-container').addClass('widget-products-slider widget');
    $('.elementor-widget-wp-widget-irk_brands_slider .elementor-widget-container').addClass('widget-brands-slider widget');
    $('.elementor-widget-wp-widget-irk_promotion_categories .elementor-widget-container').addClass('widget-promotion-categories widget');
    $('.elementor-widget-wp-widget-irk_posts .elementor-widget-container').addClass('widget-posts widget');
    $('.elementor-widget-wp-widget-irk_services .elementor-widget-container').addClass('widget-services widget');
    $('.elementor-widget-wp-widget-irk_promotion_single .elementor-widget-container').addClass('widget-promotion-single widget');
    $('.elementor-widget-wp-widget-irk_product_ads .elementor-widget-container').addClass('widget-product-ads widget');
    $('.elementor-widget-wp-widget-irk_categories .elementor-widget-container').addClass('widget-categories widget');
    elementorHeader($('.elementor-widget-wp-widget-irk_posts_slider .elementor-widget-container > h5'));
    elementorHeader($('.elementor-widget-wp-widget-irk_products_slider .elementor-widget-container .col-12 > h5'));
    elementorHeader($('.elementor-widget-wp-widget-irk_brands_slider .elementor-widget-container > h5'));
    elementorHeader($('.elementor-widget-wp-widget-irk_promotion_categories .elementor-widget-container > h5'));
    elementorHeader($('.elementor-widget-wp-widget-irk_posts .elementor-widget-container > h5'));
    elementorHeader($('.elementor-widget-wp-widget-irk_categories .elementor-widget-container > h5'));

    $('.elementor-menu-cart__footer-buttons .elementor-button').addClass('button');

    $('.elementor-widget-wp-widget-irk_products_slider .elementor-widget-container').each(function () {
        $(this).find('> .row > .col-12:nth-child(1) .header').next('.slider-inner').andSelf().wrapAll('<div class="widget-products-slider widget"></div>');
    });

    function elementorHeader(element) {
        element.addClass('title clearfix');
        element.wrap('<header class="header"></header>');
    }

    elementorHeader2($('.elementor-widget-wp-widget-irk_posts_slider .elementor-widget-container > span'));
    elementorHeader2($('.elementor-widget-wp-widget-irk_products_slider .elementor-widget-container .col-12 > span'));
    elementorHeader2($('.elementor-widget-wp-widget-irk_brands_slider .elementor-widget-container > span'));
    elementorHeader2($('.elementor-widget-wp-widget-irk_promotion_categories .elementor-widget-container > span'));
    elementorHeader2($('.elementor-widget-wp-widget-irk_posts .elementor-widget-container > span'));
    elementorHeader2($('.elementor-widget-wp-widget-irk_categories .elementor-widget-container > span'));

    $('.elementor-menu-cart__footer-buttons .elementor-button').addClass('button');

    function elementorHeader2(element) {
        element.next('.view-all').andSelf().wrapAll('<header class="header"><h3 class="title clearfix"></h3></header>');
    }

    $('.jump-to-top').each(function () {
        $(this).click(function () {
            $('html,body').animate({scrollTop: 0}, 'slow');
            return false;
        });
    });

    $('.more-less').showMore({
        minheight: 96,
        buttontxtmore: IRK_DATA.show_more,
        buttontxtless: IRK_DATA.show_less,
        animationspeed: 250
    });
    $('.widget_product_categories .product-categories').showMore({
        minheight: 256,
        buttontxtmore: IRK_DATA.show_more,
        buttontxtless: IRK_DATA.show_less,
        animationspeed: 250
    });
    $('.woocommerce-Tabs-panel--description .expert').showMore({
        minheight: 205,
        buttontxtmore: IRK_DATA.show_more,
        buttontxtless: IRK_DATA.show_less,
        animationspeed: 250
    });
    $('.single .short-attributes').showMore({
        minheight: 128,
        buttontxtmore: '<span>+ ' + IRK_DATA.show_more + '</span>',
        buttontxtless: '<span>-- ' + IRK_DATA.show_less + '</span>',
        animationspeed: 250
    });

    $('.download-app .close').click(function (e) {
        e.preventDefault();
        $('.download-app').hide();
        $.cookie('irk-hide-app-bar', 'yes', {expires: 7, path: '/'});
    });

    var sidebarMargin = 5;
    sidebarMargin = IRK_DATA.sticky_header ? sidebarMargin + $('.main-header').height() : sidebarMargin;
    if (IRK_DATA.sticky_sidebar_home === '1') {
        $('.mainbar, .sidebar-main').theiaStickySidebar({
            additionalMarginTop: sidebarMargin
        });
    }
    if (IRK_DATA.sticky_sidebar_shop === '1') {
        $('.shop-container, .sidebar-shop').theiaStickySidebar({
            additionalMarginTop: sidebarMargin
        });

        //$('.dokan-store #dokan-secondary').next().andSelf().wrapAll('<div>');
        $('.dokan-store .dokan-store-wrap #dokan-secondary, .dokan-store .dokan-store-wrap #dokan-primary').theiaStickySidebar({
            additionalMarginTop: sidebarMargin
        });
    }
    if (IRK_DATA.sticky_sidebar_product === '1') {
        $('.product-content, .sidebar-product').theiaStickySidebar({
            additionalMarginTop: sidebarMargin
        });
    }
    if (IRK_DATA.sticky_sidebar_post === '1') {
        $('.archive-content, .sidebar-post').theiaStickySidebar({
            additionalMarginTop: sidebarMargin
        });
        $('.post-container, .sidebar-post').theiaStickySidebar({
            additionalMarginTop: sidebarMargin
        });
    }
    $('.account-nav-container, .woocommerce-MyAccount-content').theiaStickySidebar({
        additionalMarginTop: sidebarMargin
    });
    $('.woocommerce-cart .cart-wrapper, .woocommerce-cart .totals-wrapper').theiaStickySidebar({
        additionalMarginTop: sidebarMargin
    });
    $('.next-shopping .table-wrapper, .next-shopping .side-wrapper').theiaStickySidebar({
        additionalMarginTop: sidebarMargin
    });
    $('.woocommerce-checkout.custom-checkout .customer-details-wrapper, .woocommerce-checkout.custom-checkout .order-review-wrapper').theiaStickySidebar({
        additionalMarginTop: sidebarMargin
    });
    $('.dokan-dash-sidebar, .dokan-dashboard-content').theiaStickySidebar({
        additionalMarginTop: sidebarMargin
    });

    $('.main-header .woocommerce-MyAccount-navigation-link').removeClass('is-active');

    $('.remove-favorite').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var postID = parseInt($this.data('pid'));
        if (!postID) {
            return false;
        }
        modalLoader.addClass('show');

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_remove_favorite',
                postID: postID,
                nonce: nonce
            },
            success: function (response) {
                if (response === true) {
                    if ($this.hasClass('is-myaccount')) {
                        $this.parentsUntil('.posts-list').remove();
                    }
                }
            },
            error: function () {
                modalLoader.removeClass('show');
            },
            complete: function (data) {
                modalLoader.removeClass('show');
            }
        });
    });

    $('.main-header .dokan-dashboard-menu').unwrap();
    $('.main-header .dokan-dashboard-menu li').addClass('woocommerce-MyAccount-navigation-link dokan-item');
    $('.main-header .dokan-dashboard-menu li').unwrap();
    $('.main-header #mobile-menu-icon, .main-header #toggle-mobile-menu, .main-header .dokan-common-links, .main-header .settings a .fa:nth-child(2)').remove();

    $('.woocommerce-widget-layered-nav-list__item a, .widget_rating_filter .wc-layered-nav-rating a').prepend('<input type="checkbox" class="checkbox">');
    $('.woocommerce-widget-layered-nav-list__item--chosen .checkbox, .widget_rating_filter .chosen .checkbox').attr('checked', true);
    $('.woocommerce-widget-layered-nav-list__item .checkbox, .widget_rating_filter .checkbox, .widget-brands-filter .term-item .checkbox, .widget-vendor-filter .vendor-item .checkbox, .widget-onsale-filter .checkbox').change(function () {
        window.location.href = $(this).parentsUntil('li').attr('href');
    });

    $('.sidebar-shop .widget .header').click(function () {
        var $this = $(this);
        $this.toggleClass('collapse');
        $this.next().slideToggle();

        var widgetID = $this.closest('div').attr('id');
        if ($this.hasClass('collapse')) {
            $.cookie(widgetID, 'collapsed', {expires: 30, path: '/'});
        } else {
            $.removeCookie(widgetID, {path: '/'});
        }
    });
    $('.sidebar-shop .widget').each(function () {
        var $this = $(this);
        var widgetID = $this.attr('id');
        if ($.cookie(widgetID) === 'collapsed') {
            var widgetHeader = $('#' + widgetID).find('.header');
            widgetHeader.addClass('collapse');
            widgetHeader.next().slideUp(1);
        }
    });

    $('#instock-filter, #fake-filter').change(function (e) {
        var $this = $(this);
        $this.toggleClass('checked');
        window.location.href = $this.data('url');
    });

    $(".brand-search input[type=text]").on("keyup", function () {
        var value = $(this).val().toLowerCase();
        $(".widget-brands-filter .term-item").filter(function () {
            $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
        });
    });

    $('.toggle-ordering').click(function (e) {
        e.preventDefault();
        $('body').toggleClass('show-ordering');
    });

    $('.toggle-sidebar-shop').click(function (e) {
        e.preventDefault();
        $('body').toggleClass('show-sidebar-shop');
    });

    if ($('.checkout-steps').length) {
        $wrapper = $('.multistep-checkout-wrapper');
        var firstStep = $('.checkout-steps li:first-child');
        firstStep.addClass('active');
        $wrapper.addClass(firstStep.attr('id'))
        var activeStep = firstStep.data('step');
        $(activeStep).show();

        $('.prev-next .next button').click(function (e) {
            e.preventDefault();
            var $this = $(this);
            var steps = $('ul.checkout-steps');
            var $active = steps.find('li.active');
            var activeStep = $active.data('step');
            if (activeStep === '#customer_details .col-1') {
                if ($('#createaccount').prop("checked") === true) {
                    $('.woocommerce-checkout #customer_details .col-1').find('.input-text, select, input:checkbox').trigger('validate').blur();
                    if ($('.woocommerce-checkout #customer_details .col-1 .woocommerce-invalid').length) {
                        return false;
                    }
                } else {
                    $('.woocommerce-checkout #customer_details .woocommerce-billing-fields__field-wrapper .col-1').find('.input-text, select, input:checkbox').trigger('validate').blur();
                    if ($('.woocommerce-checkout #customer_details .col-1 .woocommerce-billing-fields__field-wrapper .woocommerce-invalid').length) {
                        return false;
                    }
                }
            }
            if (activeStep === '#customer_details .col-2') {
                $('.woocommerce-checkout #customer_details .col-2').find('.input-text, select, input:checkbox').trigger('validate').blur();
                if ($('#ship-to-different-address-checkbox').prop("checked") === true && $('.woocommerce-checkout #customer_details .col-2 .woocommerce-invalid').length) {
                    return false;
                }
            }
            var $next = steps.find('li.active').next('li.step');
            var nextStep = $next.data('step');
            if ($next.is(':last-child')) {
                $this.prop('disabled', true);
            }
            if ($active.is(':last-child')) {
                return false;
            }
            $active.removeClass('active');
            $next.addClass('active');
            $(activeStep).hide();
            $(nextStep).show();
            $('.prev-next .prev button').prop('disabled', false);

            if (nextStep == '.woocommerce-checkout-review-order-table') {
                $(document.body).on('updated_checkout', function () {
                    $('.woocommerce-checkout-review-order-table').show();
                });
            }

            $wrapper.addClass($next.attr('id')).removeClass($active.attr('id'));

            $('html, body').animate({
                scrollTop: $(".checkout-steps").offset().top - sidebarMargin
            }, 300);
        });
        $('.prev-next .prev button').click(function (e) {
            e.preventDefault();
            var $this = $(this);
            var steps = $('ul.checkout-steps');
            var $active = steps.find('li.active');
            var $prev = steps.find('li.active').prev('li.step');
            if ($prev.is(':first-child')) {
                $this.prop('disabled', true);
            }
            if ($active.is(':first-child')) {
                return false;
            }
            $active.removeClass('active');
            $prev.addClass('active');
            var activeStep = $active.data('step');
            var prevStep = $prev.data('step');
            $(activeStep).hide();
            $(prevStep).show();
            $('.prev-next .next button').prop('disabled', false);

            if (prevStep == '.woocommerce-checkout-review-order-table') {
                $(document.body).on('updated_checkout', function () {
                    console.log('try');
                    $('.woocommerce-checkout-review-order-table').show();
                });
            }

            $wrapper.addClass($prev.attr('id')).removeClass($active.attr('id'));

            $('html, body').animate({
                scrollTop: $(".checkout-steps").offset().top - sidebarMargin
            }, 300);
        });
    }

    $(document.body).on('applied_coupon_in_checkout', function () {
        $('.multistep-checkout-wrapper form.checkout_coupon.woocommerce-form-coupon').addClass('show');
    });

    $('form.woocommerce-checkout').after($('.woocommerce-checkout-review-order-table .order-total td strong').clone());
    $(document.body).on('updated_checkout', function () {
        $('form.woocommerce-checkout + strong').html($('.woocommerce-checkout-review-order-table .order-total td strong').html());
    });

    if (IRK_DATA.gallery_thumb_slider && $('.flex-control-thumbs li').length > 8) {
        $('.flex-control-thumbs').addClass('owl-carousel');
        $('.flex-control-thumbs.owl-carousel').owlCarousel({
            nav: true,
            dots: false,
            loop: false,
            autoplay: false,
            margin: 0,
            slideBy: 1,
            navText: ['<span data-icon=arrow-left></span>', '<span data-icon=arrow-right></span>'],
            responsive: {
                0: {
                    items: 3,
                },
                576: {
                    items: 7,
                },
                768: {
                    items: 5,
                },
                992: {
                    items: 6,
                },
                1200: {
                    items: 7,
                }
            }
        });
    }

    if (IRK_DATA.reviews_title) {
        //$('#comments .woocommerce-Reviews-title').html(IRK_DATA.reviews_title);
    }

    $('.product-actions .favorites, .post-meta .favorites').on('click', function (e) {
        e.preventDefault();
        var $this = $(this);
        var postID = parseInt($this.data('pid'));
        if (!postID) {
            return false;
        }
        modalLoader.addClass('show');

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_add_favorites',
                postID: postID,
                nonce: nonce
            },
            success: function (response) {
                if (response === true) {
                    $this.toggleClass('active');
                }
            },
            error: function () {
                modalLoader.removeClass('show');
            },
            complete: function (data) {
                modalLoader.removeClass('show');
            }
        });
    });

    $('a[data-modal]').on('click', function () {
        $($(this).data('modal')).modal({fadeDuration: 100});
        return false;
    });

    function copyToClipboard(element) {
        var $temp = $("<input>");
        $("body").append($temp);
        $temp.val(element.data('url')).select();
        document.execCommand("copy");
        $temp.remove();
    }

    $('.copy-url').click(function (e) {
        e.preventDefault();
        copyToClipboard($(this));
    });

    $(document).on('click', '.add-to-compare', function (e) {
        var $this = $(this);
        if ($this.hasClass('compare')) {
            e.preventDefault();
        }
        $this.toggleClass('active');
        var productID = $this.data('id').toString();
        if (!productID) {
            return false;
        }

        var compareList = $.cookie('irk-compare-list');
        var newList = [];
        var added = false;

        if (!compareList) {
            newList.push(productID);
            added = true;
        } else {
            var compareListArray = compareList.split(',');
            if (jQuery.inArray(productID, compareListArray) !== -1) {
                compareListArray = jQuery.grep(compareListArray, function (value) {
                    return value !== productID;
                });

                if (!compareListArray.length) {
                    $.removeCookie('irk-compare-list', {path: '/'});
                }
            } else {
                compareListArray.push(productID);
                added = true;
            }

            newList = compareListArray;
        }

        $.cookie('irk-compare-list', newList.join(','), {expires: 7, path: '/'});

        if (/*$.cookie('irk-compare-list') !== '' && */added === true) {
            window.location.href = IRK_DATA.compare_page;
        }
    });

    $('a.remove-compare-item').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var productID = $this.data('id').toString();
        if (!productID) {
            return false;
        }

        var compareList = $.cookie('irk-compare-list');
        var compareListArray = compareList.split(',');
        compareListArray = jQuery.grep(compareListArray, function (value) {
            return value !== productID;
        });
        if (!compareListArray.length) {
            $.removeCookie('irk-compare-list', {path: '/'});
            $('.irk-page-compare .compare-table').after('<div class="empty-compare woocommerce-message woocommerce-Message--info">' + IRK_DATA.empty_compare + '</div>').remove();
        } else {
            $.cookie('irk-compare-list', compareListArray.join(','), {expires: 7, path: '/'});
            location.reload();
        }
    });

    $('.products li.product .product-rating .add-to-compare.active input[type=checkbox]').prop('checked', true);

    $('.summary .single_add_to_cart_button').wrap('<div class="add-to-cart-wrapper"></div>');

    if (IRK_DATA.tabs_panel === 'collapsed') {
        $('.woocommerce-Tabs-panel').prepend('<a href="#" class="tab-more">' + IRK_DATA.show_more + '</a>');
    }

    $(document).on('click', '.woocommerce-Tabs-panel .tab-more', function (e) {
        e.preventDefault();
        $(this).parentsUntil('.woocommerce-tabs').toggleClass('expand');
    });

    $('.woocommerce-review-link').click(function (e) {
        $('#tab-reviews').addClass('expand');
    });

    $('.woocommerce-Tabs-panel').each(function () {
        var $this = $(this);
        var tabID = $this.attr('id');
        tabID = tabID.replace('tab-', '');
        var tabTitle = $('li#tab-title-' + tabID + ' a').text();
        $this.prepend('<span class="tab-title">' + tabTitle + '</span>');
    });

    $('#post-filter select').change(function () {
        this.form.submit();
    });

    $('.widget-categories .cat-item a + ul.children').prev('a').append('<span class="expand"></span>');
    $(document).on('click', '.widget-categories .expand', function (e) {
        e.preventDefault();
        var $this = $(this);
        $this.parentsUntil('.cat-item').next('ul.children').slideToggle();
    });

    $('.quick-view').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var productID = parseInt($this.data('id'));
        if (!productID) {
            return false;
        }
        var modal = $('#quick-view-modal');
        var loader = $('.modal-loader').html();
        loader = '<div class="loader-wrapper">' + loader + '</div>';
        modal.find('.inner').html(loader);

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_quick_view',
                productID: productID,
                nonce: nonce
            },
            success: function (response) {
                modal.find('.inner').html(response);
            },
            error: function () {

            },
            complete: function (data) {

            }
        });
    });

    $(document).on('click', '.ajax-add-to-cart', function (e) {
        e.preventDefault();
        var $this = $(this);
        var plus = $this.find('.plus');
        var productID = parseInt($this.data('id'));
        var qty = 1;
        var quantity = $this.prev('.quantity');
        if (quantity.length) {
            qty = parseInt(quantity.find('.qty').val());
        }
        if (!productID) {
            return false;
        }

        var loader = $this.find('.ajax-loader');

        $this.prop('disabled', true);
        plus.hide();
        loader.show();

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_add_to_cart',
                productID: productID,
                quantity: qty,
                nonce: nonce
            },
            success: function (response) {
                $(document.body).trigger('wc_fragment_refresh');
                //$this.find('.button-text').addClass('added-message').text(IRK_DATA.added_to_cart);
                if (response._success === true && IRK_DATA.added_to_cart_toast) {
                    $.toast({
                        text: IRK_DATA.added_to_cart,
                        hideAfter: 5000,
                        showHideTransition: 'slide',
                        allowToastClose: true,
                        stack: 5,
                        position: 'bottom-center',
                        icon: 'success',
                        textAlign: 'center',
                        textColor: 'white',
                        bgColor: '#000',
                    });
                }
            },
            error: function () {

            },
            complete: function (data) {
                $this.prop('disabled', false);
                plus.show();
                loader.hide();
            }
        });
    });

    if (IRK_DATA.added_to_cart_toast) {
        $(document.body).on('added_to_cart', function () {
            $.toast({
                text: IRK_DATA.added_to_cart,
                hideAfter: 5000,
                showHideTransition: 'slide',
                allowToastClose: true,
                stack: 5,
                position: 'bottom-center',
                icon: 'success',
                textAlign: 'center',
                textColor: 'white',
                bgColor: '#000',
            });
        });
    }

    $('#order-tracking').submit(function (e) {
        e.preventDefault();
        var $this = $(this);
        var orderID = parseInt($this.find('input[type=text]').val());
        if (!orderID) {
            return false;
        }

        var statuses = $('.order-tracking ul.statuses');
        var description = $('.order-tracking .description');
        modalLoader.addClass('show');

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_order_tracking',
                orderID: orderID,
                nonce: nonce
            },
            success: function (response) {
                if (response._results === 'not-found') {
                    alert(IRK_DATA.order_not_found);
                } else {
                    $('.tracking-results').html(response._results);
                    $('.order-tracking ul.statuses li.active').prevAll().addClass('active');
                }
            },
            error: function () {

            },
            complete: function (data) {
                modalLoader.removeClass('show');
            }
        });
    });

    $('.footer-info .row .widget:nth-of-type(1)').wrap('<div class="col-12 col-lg-7"></div>');
    $('.footer-info .row .widget:nth-of-type(2)').wrap('<div class="col-12 col-lg-5"></div>');
    $('.footer-info .row .col-12:nth-of-type(1) .textwidget, .site-description .description').showMore({
        minheight: 128,
        buttontxtmore: '<span>' + IRK_DATA.show_more + '</span>',
        buttontxtless: '<span>' + IRK_DATA.show_less + '</span>',
        animationspeed: 250
    });

    $(document).on('click', '.decrease-qty', function (e) {
        e.preventDefault();
        var $this = $(this);
        var qtyInput = $this.next('input');
        var minVal = parseInt(qtyInput.attr('min'));
        minVal = minVal ? minVal : 1;
        var currentVal = parseInt(qtyInput.val());
        if (!isNaN(currentVal) && currentVal > minVal) {
            qtyInput.val(currentVal - 1);
        }
        qtyInput.trigger("change");
    });
    $(document).on('click', '.increase-qty', function (e) {
        e.preventDefault();
        var $this = $(this);
        var qtyInput = $this.prev('input');
        var maxVal = parseInt(qtyInput.attr('max'));
        maxVal = maxVal ? maxVal : 9999;
        var currentVal = parseInt(qtyInput.val());
        if (!isNaN(currentVal) && currentVal < maxVal) {
            console.log(currentVal);
            qtyInput.val(currentVal + 1);
        }
        qtyInput.trigger("change");
    });

    $('#advantage, #disadvantage').on('input', function () {
        var $this = $(this);
        var $value = $this.val();
        if ($value.length > 0) {
            $this.addClass('focused');
        } else {
            $this.removeClass('focused');
        }
    });

    $('#commentform .add-point').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var $value = $this.prev('input').val();
        if ($value.length > 0) {
            $this.prev('input').val('').removeClass('focused');

            $this.parentsUntil('#commentform').find('.dynamic-labels').append('<input type="hidden" name="' + $this.data('type') + '[]" value="' + $value + '"><span>' + $value + '<span class="remove" data-icon="close"></span>');
        }
    });

    $(document).on('click', '.dynamic-labels .remove', function (e) {
        e.preventDefault();
        var $this = $(this);
        $this.parentsUntil('.dynamic-labels').prev('input').andSelf().remove();
    });

    $('.comment-like a').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var commentID = parseInt($this.data('comment-id'));
        if (!commentID) {
            return false;
        }

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_like_comment',
                commentID: commentID,
                nonce: nonce
            },
            success: function (response) {
                if (response._results === true) {
                    $this.find('.count').text(response._count);
                    $this.toggleClass('active');
                }

            },
        });
    });

    $('.rating-slider .slider-step').click(function () {
        var $this = $(this);
        var $step = parseInt($this.data('step'));
        var $rateTitle = $this.data('rate-title');
        $this.prevAll('.slider-step').andSelf().addClass('active');
        $this.nextAll('.slider-step').removeClass('active');

        $this.parentsUntil('.comment-attribute').attr('data-rate-title', $rateTitle);
        if ($('body').hasClass('rtl')) {
            $this.siblings('.slider-handle').css({right: $this.css('right')});
        } else {
            $this.siblings('.slider-handle').css({left: $this.css('left')});
        }
        $this.siblings('.slider-base').css({width: ($step - 1) * 25 + '%'});
        $this.siblings('input').val($step);
    });

    $('table.cart .product-remove a').html('<span data-icon="trash-image"></span>');

    $('.add-next-shopping').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var postID = parseInt($this.data('pid'));
        var cartKey = $this.data('cart-key');
        if (!postID || !cartKey) {
            return false;
        }
        modalLoader.addClass('show');

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_add_next_shopping',
                postID: postID,
                cartKey: cartKey,
                nonce: nonce
            },
            success: function (response) {
                if (response === true) {
                    window.location.reload();
                }
            },
            error: function () {
                modalLoader.removeClass('show');
            },
            complete: function (data) {
                modalLoader.removeClass('show');
            }
        });
    });

    $('.remove-next-shopping').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var postID = parseInt($this.data('pid'));
        if (!postID) {
            return false;
        }
        modalLoader.addClass('show');

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_remove_next_shopping',
                postID: postID,
                nonce: nonce
            },
            success: function (response) {
                if (response === true) {
                    window.location.reload();
                }
            },
            error: function () {
                modalLoader.removeClass('show');
            },
            complete: function (data) {
                modalLoader.removeClass('show');
            }
        });
    });

    $('.add--to--cart').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var postID = parseInt($this.data('pid'));
        if (!postID) {
            return false;
        }
        modalLoader.addClass('show');

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_add_cart_next_shopping',
                postID: postID,
                nonce: nonce
            },
            success: function (response) {
                if (response === true) {
                    window.location.reload();
                }
            },
            error: function () {
                modalLoader.removeClass('show');
            },
            complete: function (data) {
                modalLoader.removeClass('show');
            }
        });
    });

    $('.add-all-next-shopping-cart').click(function (e) {
        e.preventDefault();
        modalLoader.addClass('show');

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_add_all_next_shopping',
                nonce: nonce
            },
            success: function (response) {
                if (response === true) {
                    window.location.reload();
                }
            },
            error: function () {
                modalLoader.removeClass('show');
            },
            complete: function (data) {
                modalLoader.removeClass('show');
            }
        });
    });

    $('#avatar-modal form').submit(function (e) {
        e.preventDefault();
        var $this = $(this);
        var message = $this.find('.message');
        var loader = $this.find('.upload-loader');
        message.removeClass('woocommerce-message woocommerce-error').text('');
        loader.show();

        var formData = new FormData();
        formData.append('action', 'irk_upload_avatar');
        formData.append('nonce', nonce);
        formData.append('avatar', $this.find('#avatar').prop('files')[0]);

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            contentType: false,
            processData: false,
            timeout: 0,
            data: formData,
            success: function (response) {
                if (response._success === false) {
                    message.addClass('woocommerce-error').text(response._message);
                } else {
                    message.addClass('woocommerce-message').text(response._message);
                }
                loader.hide();
            },
            error: function () {
                loader.hide();
            },
            complete: function (data) {
                loader.hide();
            }
        });
    });

    $('.remove-avatar').click(function (e) {
        e.preventDefault();
        var $this = $(this);
        var message = $('#avatar-modal').find('.message');
        var loader = $this.find('.remove-loader');
        var preview = $('#avatar-modal').find('#preview');
        message.removeClass('woocommerce-message woocommerce-error').text('');
        loader.show();

        $.ajax({
            url: IRK_DATA.ajax_url,
            type: 'post',
            dataType: 'json',
            timeout: 20000,
            data: {
                action: 'irk_remove_avatar',
                nonce: nonce,
            },
            success: function (response) {
                if (response._success === true) {
                    message.addClass('woocommerce-message').text(response._message);
                    $this.remove();
                    preview.remove();
                }
            },
            error: function () {
                loader.hide();
            }
        });
    });

    function readURL(input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();

            reader.onload = function (e) {
                $('#avatar-modal #preview').attr('src', e.target.result);
            }

            reader.readAsDataURL(input.files[0]);
        }
    }

    $("#avatar-modal #avatar").change(function () {
        readURL(this);
    });

    $('.faqs-access').click(function (e) {
        var $this = $(this);
        $this.toggleClass('active');
    });

    $('.faqs-welcoming, .main-header .faqs').click(function (e) {
        e.preventDefault();
        $('.faqs-access').toggleClass('active');
    });

    $('.faq-item-title').click(function (e) {
        var $this = $(this);
        $this.toggleClass('active');
        $this.next('.faq-item-content').slideToggle();
    });

    $('.product-info-panel .product-seller').click(function () {
        $('.product-info-panel').addClass('show-info-more-seller').removeClass('show-info-more-stock');
    });
    $('.product-info.stock').click(function () {
        $('.product-info-panel').addClass('show-info-more-stock').removeClass('show-info-more-seller');
    });
    $('.product-info-more .back-btn').click(function () {
        $('.product-info-panel').removeClass('show-info-more-seller show-info-more-stock');
    });

    if ($('body').hasClass('single-product') && wc_single_product_params.review_rating_required !== 'yes') {
        $('#rating').prop('required', false);
    }

    $('.other-sellers-row').each(function () {
        $(this).click(function () {
            $('html,body').animate({scrollTop: $('#dokan-other-vendor-camparison').offset().top - 100}, 'slow');
            return false;
        });
    });

    if (!$('input[name="dokan_statement_export_all"]').length) {
        $('.dokan-reports-area thead tr').append('<th></th>');
    }

    $('.others-categories .term').click(function (e) {
        e.preventDefault();
        $('.subcategories-list .row').toggleClass('show-all');
    });

    $('.footer-info .textwidget a[rel]').attr('rel', 'origin');
});

var preLoader = document.getElementById("pre-loader");
if (preLoader) {
    document.addEventListener("DOMContentLoaded", function(event) {
        preLoader.remove();
    });
}