
/* Font Face Observer v2.1.0 - © Bram Stein. License: BSD-3-Clause */(function(){'use strict';var f,g=[];function l(a){g.push(a);1==g.length&&f()}function m(){for(;g.length;)g[0](),g.shift()}f=function(){setTimeout(m)};function n(a){this.a=p;this.b=void 0;this.f=[];var b=this;try{a(function(a){q(b,a)},function(a){r(b,a)})}catch(c){r(b,c)}}var p=2;function t(a){return new n(function(b,c){c(a)})}function u(a){return new n(function(b){b(a)})}function q(a,b){if(a.a==p){if(b==a)throw new TypeError;var c=!1;try{var d=b&&b.then;if(null!=b&&"object"==typeof b&&"function"==typeof d){d.call(b,function(b){c||q(a,b);c=!0},function(b){c||r(a,b);c=!0});return}}catch(e){c||r(a,e);return}a.a=0;a.b=b;v(a)}}
    function r(a,b){if(a.a==p){if(b==a)throw new TypeError;a.a=1;a.b=b;v(a)}}function v(a){l(function(){if(a.a!=p)for(;a.f.length;){var b=a.f.shift(),c=b[0],d=b[1],e=b[2],b=b[3];try{0==a.a?"function"==typeof c?e(c.call(void 0,a.b)):e(a.b):1==a.a&&("function"==typeof d?e(d.call(void 0,a.b)):b(a.b))}catch(h){b(h)}}})}n.prototype.g=function(a){return this.c(void 0,a)};n.prototype.c=function(a,b){var c=this;return new n(function(d,e){c.f.push([a,b,d,e]);v(c)})};
    function w(a){return new n(function(b,c){function d(c){return function(d){h[c]=d;e+=1;e==a.length&&b(h)}}var e=0,h=[];0==a.length&&b(h);for(var k=0;k<a.length;k+=1)u(a[k]).c(d(k),c)})}function x(a){return new n(function(b,c){for(var d=0;d<a.length;d+=1)u(a[d]).c(b,c)})};window.Promise||(window.Promise=n,window.Promise.resolve=u,window.Promise.reject=t,window.Promise.race=x,window.Promise.all=w,window.Promise.prototype.then=n.prototype.c,window.Promise.prototype["catch"]=n.prototype.g);}());

(function(){function l(a,b){document.addEventListener?a.addEventListener("scroll",b,!1):a.attachEvent("scroll",b)}function m(a){document.body?a():document.addEventListener?document.addEventListener("DOMContentLoaded",function c(){document.removeEventListener("DOMContentLoaded",c);a()}):document.attachEvent("onreadystatechange",function k(){if("interactive"==document.readyState||"complete"==document.readyState)document.detachEvent("onreadystatechange",k),a()})};function t(a){this.a=document.createElement("div");this.a.setAttribute("aria-hidden","true");this.a.appendChild(document.createTextNode(a));this.b=document.createElement("span");this.c=document.createElement("span");this.h=document.createElement("span");this.f=document.createElement("span");this.g=-1;this.b.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;";this.c.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;";
    this.f.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;";this.h.style.cssText="display:inline-block;width:200%;height:200%;font-size:16px;max-width:none;";this.b.appendChild(this.h);this.c.appendChild(this.f);this.a.appendChild(this.b);this.a.appendChild(this.c)}
    function u(a,b){a.a.style.cssText="max-width:none;min-width:20px;min-height:20px;display:inline-block;overflow:hidden;position:absolute;width:auto;margin:0;padding:0;top:-999px;white-space:nowrap;font-synthesis:none;font:"+b+";"}function z(a){var b=a.a.offsetWidth,c=b+100;a.f.style.width=c+"px";a.c.scrollLeft=c;a.b.scrollLeft=a.b.scrollWidth+100;return a.g!==b?(a.g=b,!0):!1}function A(a,b){function c(){var a=k;z(a)&&a.a.parentNode&&b(a.g)}var k=a;l(a.b,c);l(a.c,c);z(a)};function B(a,b){var c=b||{};this.family=a;this.style=c.style||"normal";this.weight=c.weight||"normal";this.stretch=c.stretch||"normal"}var C=null,D=null,E=null,F=null;function G(){if(null===D)if(J()&&/Apple/.test(window.navigator.vendor)){var a=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent);D=!!a&&603>parseInt(a[1],10)}else D=!1;return D}function J(){null===F&&(F=!!document.fonts);return F}
    function K(){if(null===E){var a=document.createElement("div");try{a.style.font="condensed 100px sans-serif"}catch(b){}E=""!==a.style.font}return E}function L(a,b){return[a.style,a.weight,K()?a.stretch:"","100px",b].join(" ")}
    B.prototype.load=function(a,b){var c=this,k=a||"BESbswy",r=0,n=b||3E3,H=(new Date).getTime();return new Promise(function(a,b){if(J()&&!G()){var M=new Promise(function(a,b){function e(){(new Date).getTime()-H>=n?b(Error(""+n+"ms timeout exceeded")):document.fonts.load(L(c,'"'+c.family+'"'),k).then(function(c){1<=c.length?a():setTimeout(e,25)},b)}e()}),N=new Promise(function(a,c){r=setTimeout(function(){c(Error(""+n+"ms timeout exceeded"))},n)});Promise.race([N,M]).then(function(){clearTimeout(r);a(c)},
        b)}else m(function(){function v(){var b;if(b=-1!=f&&-1!=g||-1!=f&&-1!=h||-1!=g&&-1!=h)(b=f!=g&&f!=h&&g!=h)||(null===C&&(b=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent),C=!!b&&(536>parseInt(b[1],10)||536===parseInt(b[1],10)&&11>=parseInt(b[2],10))),b=C&&(f==w&&g==w&&h==w||f==x&&g==x&&h==x||f==y&&g==y&&h==y)),b=!b;b&&(d.parentNode&&d.parentNode.removeChild(d),clearTimeout(r),a(c))}function I(){if((new Date).getTime()-H>=n)d.parentNode&&d.parentNode.removeChild(d),b(Error(""+
        n+"ms timeout exceeded"));else{var a=document.hidden;if(!0===a||void 0===a)f=e.a.offsetWidth,g=p.a.offsetWidth,h=q.a.offsetWidth,v();r=setTimeout(I,50)}}var e=new t(k),p=new t(k),q=new t(k),f=-1,g=-1,h=-1,w=-1,x=-1,y=-1,d=document.createElement("div");d.dir="ltr";u(e,L(c,"sans-serif"));u(p,L(c,"serif"));u(q,L(c,"monospace"));d.appendChild(e.a);d.appendChild(p.a);d.appendChild(q.a);document.body.appendChild(d);w=e.a.offsetWidth;x=p.a.offsetWidth;y=q.a.offsetWidth;I();A(e,function(a){f=a;v()});u(e,
        L(c,'"'+c.family+'",sans-serif'));A(p,function(a){g=a;v()});u(p,L(c,'"'+c.family+'",serif'));A(q,function(a){h=a;v()});u(q,L(c,'"'+c.family+'",monospace'))})})};"object"===typeof module?module.exports=B:(window.FontFaceObserver=B,window.FontFaceObserver.prototype.load=B.prototype.load);}());

/*! Pusha v2.0.0 | MIT License | https://github.com/slavanga/pusha */
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Pusha=t()}(this,function(){"use strict";var d=function(){var e=!1;try{var t=Object.defineProperty({},"passive",{get:function(){e=!0}});window.addEventListener("testPassive",null,t),window.removeEventListener("testPassive",null,t)}catch(e){}return e}(),u=function(){var e=document.createElement("div");e.style.cssText="width: 99px; height: 99px; overflow: scroll; position: absolute; top: -9999px;",document.body.appendChild(e);var t=e.offsetWidth-e.clientWidth;return document.body.removeChild(e),t}();return function(e,t){var n="string"==typeof e?document.querySelector(e):e;if(!n)return!1;var s=document.documentElement,o=document.getElementsByClassName("pusha-blocker")[0],i=n.querySelector("[data-close]"),a=n.querySelector(".pusha-panel__content"),l={closeOnEsc:!0,closeOnClick:!0,disableOverscroll:!0,disableBodyscroll:!1,activeClass:"pusha-active",onOpen:function(){},onClose:function(){}};for(var c in t)l.hasOwnProperty(c)&&(l[c]=t[c]);var r={isOpen:!1,open:function(e){r.isOpen||(r.isOpen=!0,n.classList.add("pusha-panel--active"),s.classList.add(l.activeClass),document.body.scrollHeight>window.innerHeight&&(s.style.paddingRight=u+"px",Array.prototype.forEach.call(document.getElementsByClassName("pusha-push"),function(e){e.style.paddingRight=u+"px"})),e&&(r.activeElement=e.currentTarget,r.activeElement.setAttribute("aria-expanded",!0)),n.setAttribute("aria-hidden",!1),a.focus(),l.onOpen(n))},close:function(e){r.isOpen&&(r.isOpen=!1,n.classList.remove("pusha-panel--active"),s.classList.remove(l.activeClass),s.style.paddingRight="",Array.prototype.forEach.call(document.getElementsByClassName("pusha-push"),function(e){e.style.paddingRight=""}),r.activeElement&&(r.activeElement.setAttribute("aria-expanded",!1),r.activeElement.focus()),n.setAttribute("aria-hidden",!0),l.onClose(n))},toggle:function(e){r.isOpen?r.close(e):r.open(e)},disableOverscroll:function(e){e.addEventListener("touchstart",function(){0===e.scrollTop?e.scrollTop=1:e.scrollTop+e.offsetHeight===e.scrollHeight&&(e.scrollTop=e.scrollTop-1)})},disableBodyscroll:function(t){document.body.addEventListener("touchmove",function(e){r.isOpen&&t.scrollHeight<=t.clientHeight&&e.preventDefault()},!!d&&{passive:!1})}};return n.addEventListener("transitionend",function(e){"opacity"==e.propertyName&&(r.isOpen?s.classList.add("pusha-animated"):s.classList.remove("pusha-animated"))}),window.CSS&&CSS.supports("overscroll-behavior","contain")||(l.disableOverscroll&&r.disableOverscroll(a),l.disableBodyscroll&&r.disableBodyscroll(a)),l.closeOnEsc&&document.addEventListener("keydown",function(e){27===e.keyCode&&r.close(e)}),void 0===o&&((o=document.createElement("div")).className="pusha-blocker",document.body.appendChild(o)),l.closeOnClick&&o.addEventListener("click",r.close),i&&i.addEventListener("click",r.close),a.setAttribute("tabindex","-1"),n.pusha=r}});
/*!
 * https://unpkg.com/smoothscroll-polyfill@0.4.4/dist/smoothscroll.min.js
 */
!function(){"use strict";function o(){var o=window,t=document;if(!("scrollBehavior"in t.documentElement.style&&!0!==o.__forceSmoothScrollPolyfill__)){var l,e=o.HTMLElement||o.Element,r=468,i={scroll:o.scroll||o.scrollTo,scrollBy:o.scrollBy,elementScroll:e.prototype.scroll||n,scrollIntoView:e.prototype.scrollIntoView},s=o.performance&&o.performance.now?o.performance.now.bind(o.performance):Date.now,c=(l=o.navigator.userAgent,new RegExp(["MSIE ","Trident/","Edge/"].join("|")).test(l)?1:0);o.scroll=o.scrollTo=function(){void 0!==arguments[0]&&(!0!==f(arguments[0])?h.call(o,t.body,void 0!==arguments[0].left?~~arguments[0].left:o.scrollX||o.pageXOffset,void 0!==arguments[0].top?~~arguments[0].top:o.scrollY||o.pageYOffset):i.scroll.call(o,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:o.scrollX||o.pageXOffset,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:o.scrollY||o.pageYOffset))},o.scrollBy=function(){void 0!==arguments[0]&&(f(arguments[0])?i.scrollBy.call(o,void 0!==arguments[0].left?arguments[0].left:"object"!=typeof arguments[0]?arguments[0]:0,void 0!==arguments[0].top?arguments[0].top:void 0!==arguments[1]?arguments[1]:0):h.call(o,t.body,~~arguments[0].left+(o.scrollX||o.pageXOffset),~~arguments[0].top+(o.scrollY||o.pageYOffset)))},e.prototype.scroll=e.prototype.scrollTo=function(){if(void 0!==arguments[0])if(!0!==f(arguments[0])){var o=arguments[0].left,t=arguments[0].top;h.call(this,this,void 0===o?this.scrollLeft:~~o,void 0===t?this.scrollTop:~~t)}else{if("number"==typeof arguments[0]&&void 0===arguments[1])throw new SyntaxError("Value could not be converted");i.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left:"object"!=typeof arguments[0]?~~arguments[0]:this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top:void 0!==arguments[1]?~~arguments[1]:this.scrollTop)}},e.prototype.scrollBy=function(){void 0!==arguments[0]&&(!0!==f(arguments[0])?this.scroll({left:~~arguments[0].left+this.scrollLeft,top:~~arguments[0].top+this.scrollTop,behavior:arguments[0].behavior}):i.elementScroll.call(this,void 0!==arguments[0].left?~~arguments[0].left+this.scrollLeft:~~arguments[0]+this.scrollLeft,void 0!==arguments[0].top?~~arguments[0].top+this.scrollTop:~~arguments[1]+this.scrollTop))},e.prototype.scrollIntoView=function(){if(!0!==f(arguments[0])){var l=function(o){for(;o!==t.body&&!1===(e=p(l=o,"Y")&&a(l,"Y"),r=p(l,"X")&&a(l,"X"),e||r);)o=o.parentNode||o.host;var l,e,r;return o}(this),e=l.getBoundingClientRect(),r=this.getBoundingClientRect();l!==t.body?(h.call(this,l,l.scrollLeft+r.left-e.left,l.scrollTop+r.top-e.top),"fixed"!==o.getComputedStyle(l).position&&o.scrollBy({left:e.left,top:e.top,behavior:"smooth"})):o.scrollBy({left:r.left,top:r.top,behavior:"smooth"})}else i.scrollIntoView.call(this,void 0===arguments[0]||arguments[0])}}function n(o,t){this.scrollLeft=o,this.scrollTop=t}function f(o){if(null===o||"object"!=typeof o||void 0===o.behavior||"auto"===o.behavior||"instant"===o.behavior)return!0;if("object"==typeof o&&"smooth"===o.behavior)return!1;throw new TypeError("behavior member of ScrollOptions "+o.behavior+" is not a valid value for enumeration ScrollBehavior.")}function p(o,t){return"Y"===t?o.clientHeight+c<o.scrollHeight:"X"===t?o.clientWidth+c<o.scrollWidth:void 0}function a(t,l){var e=o.getComputedStyle(t,null)["overflow"+l];return"auto"===e||"scroll"===e}function d(t){var l,e,i,c,n=(s()-t.startTime)/r;c=n=n>1?1:n,l=.5*(1-Math.cos(Math.PI*c)),e=t.startX+(t.x-t.startX)*l,i=t.startY+(t.y-t.startY)*l,t.method.call(t.scrollable,e,i),e===t.x&&i===t.y||o.requestAnimationFrame(d.bind(o,t))}function h(l,e,r){var c,f,p,a,h=s();l===t.body?(c=o,f=o.scrollX||o.pageXOffset,p=o.scrollY||o.pageYOffset,a=i.scroll):(c=l,f=l.scrollLeft,p=l.scrollTop,a=n),d({scrollable:c,method:a,startTime:h,startX:f,startY:p,x:e,y:r})}}"object"==typeof exports&&"undefined"!=typeof module?module.exports={polyfill:o}:o()}();
/*! smooth-scroll v15.0.1 | (c) 2018 Chris Ferdinandi | MIT License | http://github.com/cferdinandi/smooth-scroll */
window.Element&&!Element.prototype.closest&&(Element.prototype.closest=function(e){var t,n=(this.document||this.ownerDocument).querySelectorAll(e),o=this;do{for(t=n.length;--t>=0&&n.item(t)!==o;);}while(t<0&&(o=o.parentElement));return o}),(function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}if("function"==typeof window.CustomEvent)return!1;e.prototype=window.Event.prototype,window.CustomEvent=e})(),(function(){for(var e=0,t=["ms","moz","webkit","o"],n=0;n<t.length&&!window.requestAnimationFrame;++n)window.requestAnimationFrame=window[t[n]+"RequestAnimationFrame"],window.cancelAnimationFrame=window[t[n]+"CancelAnimationFrame"]||window[t[n]+"CancelRequestAnimationFrame"];window.requestAnimationFrame||(window.requestAnimationFrame=function(t,n){var o=(new Date).getTime(),i=Math.max(0,16-(o-e)),r=window.setTimeout((function(){t(o+i)}),i);return e=o+i,r}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(e){clearTimeout(e)})})(),(function(e,t){"function"==typeof define&&define.amd?define([],(function(){return t(e)})):"object"==typeof exports?module.exports=t(e):e.SmoothScroll=t(e)})("undefined"!=typeof global?global:"undefined"!=typeof window?window:this,(function(e){"use strict";var t={ignore:"[data-scroll-ignore]",header:null,topOnEmptyHash:!0,speed:500,speedAsDuration:!1,durationMax:null,durationMin:null,clip:!0,offset:0,easing:"easeInOutCubic",customEasing:null,updateURL:!0,popstate:!0,emitEvents:!0},n=function(){return"querySelector"in document&&"addEventListener"in e&&"requestAnimationFrame"in e&&"closest"in e.Element.prototype},o=function(){var e={};return Array.prototype.forEach.call(arguments,(function(t){for(var n in t){if(!t.hasOwnProperty(n))return;e[n]=t[n]}})),e},i=function(t){return!!("matchMedia"in e&&e.matchMedia("(prefers-reduced-motion)").matches)},r=function(t){return parseInt(e.getComputedStyle(t).height,10)},a=function(e){var t;try{t=decodeURIComponent(e)}catch(n){t=e}return t},u=function(e){"#"===e.charAt(0)&&(e=e.substr(1));for(var t,n=String(e),o=n.length,i=-1,r="",a=n.charCodeAt(0);++i<o;){if(0===(t=n.charCodeAt(i)))throw new InvalidCharacterError("Invalid character: the input contains U+0000.");t>=1&&t<=31||127==t||0===i&&t>=48&&t<=57||1===i&&t>=48&&t<=57&&45===a?r+="\\"+t.toString(16)+" ":r+=t>=128||45===t||95===t||t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122?n.charAt(i):"\\"+n.charAt(i)}var u;try{u=decodeURIComponent("#"+r)}catch(e){u="#"+r}return u},c=function(e,t){var n;return"easeInQuad"===e.easing&&(n=t*t),"easeOutQuad"===e.easing&&(n=t*(2-t)),"easeInOutQuad"===e.easing&&(n=t<.5?2*t*t:(4-2*t)*t-1),"easeInCubic"===e.easing&&(n=t*t*t),"easeOutCubic"===e.easing&&(n=--t*t*t+1),"easeInOutCubic"===e.easing&&(n=t<.5?4*t*t*t:(t-1)*(2*t-2)*(2*t-2)+1),"easeInQuart"===e.easing&&(n=t*t*t*t),"easeOutQuart"===e.easing&&(n=1- --t*t*t*t),"easeInOutQuart"===e.easing&&(n=t<.5?8*t*t*t*t:1-8*--t*t*t*t),"easeInQuint"===e.easing&&(n=t*t*t*t*t),"easeOutQuint"===e.easing&&(n=1+--t*t*t*t*t),"easeInOutQuint"===e.easing&&(n=t<.5?16*t*t*t*t*t:1+16*--t*t*t*t*t),e.customEasing&&(n=e.customEasing(t)),n||t},s=function(){return Math.max(document.body.scrollHeight,document.documentElement.scrollHeight,document.body.offsetHeight,document.documentElement.offsetHeight,document.body.clientHeight,document.documentElement.clientHeight)},l=function(t,n,o,i){var r=0;if(t.offsetParent)do{r+=t.offsetTop,t=t.offsetParent}while(t);return r=Math.max(r-n-o,0),i&&(r=Math.min(r,s()-e.innerHeight)),r},m=function(e){return e?r(e)+e.offsetTop:0},d=function(e,t){var n=t.speedAsDuration?t.speed:Math.abs(e/1e3*t.speed);return t.durationMax&&n>t.durationMax?t.durationMax:t.durationMin&&n<t.durationMin?t.durationMin:n},f=function(t){if(history.replaceState&&t.updateURL&&!history.state){var n=e.location.hash;n=n||e.pageYOffset,history.replaceState({smoothScroll:JSON.stringify(t),anchor:n||e.pageYOffset},document.title,n||e.location.href)}},h=function(e,t,n){t||history.pushState&&n.updateURL&&history.pushState({smoothScroll:JSON.stringify(n),anchor:e.id},document.title,e===document.documentElement?"#top":"#"+e.id)},p=function(t,n,o){0===t&&document.body.focus(),o||(t.focus(),document.activeElement!==t&&(t.setAttribute("tabindex","-1"),t.focus(),t.style.outline="none"),e.scrollTo(0,n))},g=function(t,n,o,i){if(n.emitEvents&&"function"==typeof e.CustomEvent){var r=new CustomEvent(t,{bubbles:!0,detail:{anchor:o,toggle:i}});document.dispatchEvent(r)}};return function(r,v){var y,w,E,S,b,A,O,C={};C.cancelScroll=function(e){cancelAnimationFrame(O),O=null,e||g("scrollCancel",y)},C.animateScroll=function(n,i,r){var a=o(y||t,r||{}),u="[object Number]"===Object.prototype.toString.call(n),f=u||!n.tagName?null:n;if(u||f){var v=e.pageYOffset;a.header&&!S&&(S=document.querySelector(a.header)),b||(b=m(S));var w,E,A,I=u?n:l(f,b,parseInt("function"==typeof a.offset?a.offset(n,i):a.offset,10),a.clip),q=I-v,M=s(),F=0,L=d(q,a),x=function(t,o){var r=e.pageYOffset;if(t==o||r==o||(v<o&&e.innerHeight+r)>=M)return C.cancelScroll(!0),p(n,o,u),g("scrollStop",a,n,i),w=null,O=null,!0},H=function(t){w||(w=t),F+=t-w,E=F/parseInt(L,10),E=E>1?1:E,A=v+q*c(a,E),e.scrollTo(0,Math.floor(A)),x(A,I)||(O=e.requestAnimationFrame(H),w=t)};0===e.pageYOffset&&e.scrollTo(0,0),h(n,u,a),g("scrollStart",a,n,i),C.cancelScroll(!0),e.requestAnimationFrame(H)}};var I=function(t){if(!i()&&0===t.button&&!t.metaKey&&!t.ctrlKey&&"closest"in t.target&&(E=t.target.closest(r))&&"a"===E.tagName.toLowerCase()&&!t.target.closest(y.ignore)&&E.hostname===e.location.hostname&&E.pathname===e.location.pathname&&/#/.test(E.href)){var n=u(a(E.hash)),o=y.topOnEmptyHash&&"#"===n?document.documentElement:document.querySelector(n);o=o||"#top"!==n?o:document.documentElement,o&&(t.preventDefault(),f(y),C.animateScroll(o,E))}},q=function(e){if(null!==history.state&&history.state.smoothScroll&&history.state.smoothScroll===JSON.stringify(y)){var t=history.state.anchor;t&&0!==t&&!(t=document.querySelector(u(a(history.state.anchor))))||C.animateScroll(t,null,{updateURL:!1})}},M=function(e){A||(A=setTimeout((function(){A=null,b=m(S)}),66))};return C.destroy=function(){y&&(document.removeEventListener("click",I,!1),e.removeEventListener("resize",M,!1),e.removeEventListener("popstate",q,!1),C.cancelScroll(),y=null,w=null,E=null,S=null,b=null,A=null,O=null)},C.init=function(i){if(!n())throw"Smooth Scroll: This browser does not support the required JavaScript methods and browser APIs.";C.destroy(),y=o(t,i||{}),S=y.header?document.querySelector(y.header):null,b=m(S),document.addEventListener("click",I,!1),S&&e.addEventListener("resize",M,!1),y.updateURL&&y.popstate&&e.addEventListener("popstate",q,!1)},C.init(v),C}}));
var Cookienotice = {
    element: document.getElementById('js-cookienotice'),
    spacer: document.getElementById('js-cookienotice-spacer'),
    btnAccept: document.getElementById('js-cookienotice-accept'),
    btnDeny: document.getElementById('js-cookienotice-deny'),
    init: function () {
        if (!localStorage.cookieAccept && !sessionStorage.cookieAccept && Cookienotice.element) {
            Cookienotice.element.classList.remove('hidden');
            Cookienotice.setSpacerHeight();
        }

        if (Cookienotice.btnAccept) {
            Cookienotice.btnAccept.addEventListener('click', Cookienotice.setAccept);
        }

        if (Cookienotice.btnDeny) {
            Cookienotice.btnDeny.addEventListener('click', Cookienotice.setDeny);
        }
    },
    setAccept: function () {
        Cookienotice.element.classList.add('hidden');
        Cookienotice.resetSpacerHeight();
        localStorage.setItem('cookieAccept', 'true');
    },
    setDeny: function () {
        Cookienotice.element.classList.add('hidden');
        Cookienotice.resetSpacerHeight();
        sessionStorage.setItem('cookieDeny', 'true');
    },
    setSpacerHeight: function () {
        Cookienotice.spacer.style.height = Cookienotice.element.offsetHeight + 'px';
    },
    resetSpacerHeight: function () {
        Cookienotice.spacer.style.height = '';
    }
};

Cookienotice.init();

var GlobalEventThrottle = {
    scrollEvent: null,
    resizeEvent: null,
    readyEvent: null,
    throttleScroll: false,
    throttleResize: false,
    init: function(event) {
        if (typeof scrollEvent === 'function') {
            window.addEventListener('scroll', GlobalEventThrottle.throttleScrollTrigger);
        }

        if (typeof loadEvent === 'function') {
            window.addEventListener('load', loadEvent);
        }

        if (typeof resizeEvent === 'function') {
            window.addEventListener('resize', GlobalEventThrottle.throttleResizeTrigger);
        }

        if (typeof readyEvent === 'function') {
            GlobalEventThrottle.readyEvent = event;
            GlobalEventThrottle.execute(readyEvent);
        }
    },
    throttleScrollTrigger: function(event) {
        GlobalEventThrottle.scrollEvent = event;
        GlobalEventThrottle.throttleScroll = GlobalEventThrottle.throttleScroll || setTimeout(GlobalEventThrottle.execute, 200, scrollEvent, 'throttleScroll');
    },
    throttleResizeTrigger: function(event) {
        GlobalEventThrottle.resizeEvent = event;
        GlobalEventThrottle.throttleResize = GlobalEventThrottle.throttleResize || setTimeout(GlobalEventThrottle.execute, 200, resizeEvent, 'throttleResize');
    },
    execute: function(func, throttle) {
        GlobalEventThrottle[throttle] = (typeof window.requestAnimationFrame === 'function' && window.requestAnimationFrame(func)) || func();
    }
};

GlobalEventThrottle.init();

var VimeoLoader = {
    jsLoaded: false,
    players: [],
    registerAjaxNotify: function() {
        typeof AjaxObserver !== 'function' || AjaxObserver.registerObject('VimeoLoader', VimeoLoader.notifyRefresh, 'js-start-vimeo-initialized', 'js-start-vimeo');
    },
    notifyRefresh: function(event) {
        VimeoLoader.init();
    },
    init: function() {
        if (document.getElementsByClassName('js-start-vimeo').length > 0) {
            if (!VimeoLoader.jsLoaded) {
                VimeoLoader.assignPlayerEvent();
                VimeoLoader.initVimeoJS();
            } else {
                VimeoLoader.assignPlayerEvent();
            }
        }
    },
    assignPlayerEvent: function() {
        Array.prototype.slice.call(document.getElementsByClassName('js-start-vimeo')).forEach(function(item) {
            item.onclick = VimeoLoader.initVideoPlayer;
        });
    },
    initVideoPlayer: function() {
        if (this.parentNode.className.indexOf('is-video-initialized') === -1) {
            var data = JSON.parse(this.getAttribute('data-params'));
            var player = new Vimeo.Player(this.previousElementSibling, data);

            VimeoLoader.players.push(player);
            this.parentNode.className += ' is-video-initialized';
        }
    },
    initVimeoJS: function() {
        var tag = document.createElement('script');
        tag.src = 'https://player.vimeo.com/api/player.js';
        var firstScriptTag = document.getElementsByTagName('script')[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
        VimeoLoader.jsLoaded = true;
    },
    pauseVideo: function(player) {
        if (player !== this.target) {
            player.pause();
        }
    },
    pauseAllVideos: function() {
        VimeoLoader.players.forEach(VimeoLoader.pauseVideo);
    },
};

VimeoLoader.registerAjaxNotify();
VimeoLoader.init();

function onYouTubeIframeAPIReady() {
    YouTubeLoader.assignPlayerEvent();
}

const YouTubeLoader = {
    jsLoaded: false,
    players: [],
    registerAjaxNotify: function() {
        typeof AjaxObserver !== 'function' || AjaxObserver.registerObject('YouTubeLoader', YouTubeLoader.notifyRefresh, 'js-start-youtube-initialized', 'js-start-youtube');
    },
    notifyRefresh: function(event) {
        YouTubeLoader.init();
    },
    init: function() {
        if (document.getElementsByClassName('js-start-youtube').length > 0) {
            if (!YouTubeLoader.jsLoaded) {
                YouTubeLoader.initYouTubeJS();
            } else {
                YouTubeLoader.assignPlayerEvent();
            }
        }
    },
    assignPlayerEvent: function() {
        Array.prototype.slice.call(document.getElementsByClassName('js-start-youtube')).forEach(function(item) {
            item.onclick = YouTubeLoader.initVideoPlayer;
        });
    },
    initVideoPlayer: function() {
        if (this.parentNode.className.indexOf('is-video-initialized') === -1) {
            const data = JSON.parse(this.getAttribute('data-params'));
            data.events = {
                'onReady': YouTubeLoader.playVideo,
                'onStateChange': YouTubeLoader.stateChange,
            };
            YouTubeLoader.players.push(new YT.Player(this.previousElementSibling, data));
            this.parentNode.className += ' is-video-initialized';
        }
    },
    stateChange: function(event) {
        if (event.data === YT.PlayerState.PLAYING) {
            YouTubeLoader.players.forEach(YouTubeLoader.pauseVideo, event);
        }
    },
    initYouTubeJS: function() {
        const tag = document.createElement('script');
        tag.src = 'https://www.youtube.com/iframe_api';
        const firstScriptTag = document.getElementsByTagName('script')[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
        YouTubeLoader.jsLoaded = true;
    },
    pauseVideo: function(player) {
        if (player !== this.target) {
            player.pauseVideo();
        }
    },
    pauseAllVideos: function() {
        YouTubeLoader.players.forEach(YouTubeLoader.pauseVideo);
    },
    playVideo: function(event) {
        if(event.target.getPlayerState() === YT.PlayerState.UNSTARTED){
            event.target.playVideo();
        }
        if(event.target.getPlayerState() === YT.PlayerState.UNSTARTED || event.target.getPlayerState() === YT.PlayerState.CUED){
            event.target.mute();
            event.target.playVideo();
        }
    },
    resetVideo: function(player) {
        const videoWrapper = player.getIframe().parentNode;
        const className = videoWrapper.className;

        videoWrapper.className = className.slice(0, className.length - ' is-video-initialized'.length);
        player.destroy();
        YouTubeLoader.players.pop();
    },
    resetVideos: function() {
        YouTubeLoader.players.forEach(YouTubeLoader.resetVideo);
    },
};

YouTubeLoader.registerAjaxNotify();
YouTubeLoader.init();

const CLoader = {
    before: null,
    after: null,
    elementScriptTags: {},
    init: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-cloader')).forEach(CLoader.load);
    },
    registerAjaxNotify: function () {
        typeof AjaxObserver !== 'function' || AjaxObserver.registerObject('CLoader', CLoader.notifyRefresh, 'js-cloader-initialized', 'js-cloader');
    },
    notifyRefresh: function (event) {
        CLoader.init();
    },
    registerEvents: function () {
        if (typeof Event === 'function') {
            CLoader.before = new Event('cloader.before');
            CLoader.after = new Event('cloader.after');
        } else {
            CLoader.before = document.createEvent('Event');
            CLoader.after = document.createEvent('Event');

            CLoader.before.initEvent('cloader.before', false, true);
            CLoader.after.initEvent('cloader.after', false, true);
        }
    },
    load: function (element) {
        if (!element) {
            element = this;
        }

        if (!element.loading) {
            element.loading = true;
            CLoader.request(element.getAttribute('data-src'), element);

            var dataTick = element.getAttribute('data-tick');
            if (dataTick && dataTick > 0) {
                window.setTimeout(CLoader.load, dataTick, element);
            }
        }
        typeof AjaxObserver !== 'function' || AjaxObserver.setInitialized(element, 'CLoader');
    },
    request: function (url, src) {
        const request = new XMLHttpRequest();
        request.url = CLoader.getUrl(url, src);
        request.open('GET', request.url, true);
        request.responseType = 'document';
        request.target = src;
        request.action = src.hasAttribute('data-action') ? src.getAttribute('data-action') : 'replace';
        request.srcClass = src.hasAttribute('data-src-class') ? src.getAttribute('data-src-class') : false;
        request.addEventListener('load', CLoader.success);
        request.addEventListener('error', CLoader.error);
        request.withCredentials = src.getAttribute('data-credentials');
        src.dispatchEvent(CLoader.before);
        request.send();
    },
    getUrl: function (url, element) {
        if (element.hasAttribute('data-cachebreaker')) {
            const tmpLink = document.createElement('a');
            tmpLink.href = url;
            url = url + (tmpLink.search === '' ? '?' : '&') + 'cb=' + Date.now();
        }

        return url;
    },
    success: function (responseData) {
        if (this.status >= 200 && this.status < 400 && this.responseXML) {
            CLoader.addContent(this);

            if (CLoader.transferDocumentMeta(this) === 0) {
                this.target.dispatchEvent(CLoader.after);
            }
            typeof AjaxObserver !== 'function' || document.body.dispatchEvent(AjaxObserver.afterEvent);
        }
        this.target.loading = false;
    },
    transferDocumentMeta: function (response) {
        let newScriptTagsCount = 0;
        if (response.srcClass !== false) {
            if (response.responseXML.title) {
                document.title = response.responseXML.title;
            }

            newScriptTagsCount = CLoader.copyTags(response.responseXML.body, document.body, response.target.id, 'script');

            if (response.responseXML.head) {
                CLoader.copyTags(response.responseXML.head, document.head, response.target.id, 'link');
            }
        }

        return newScriptTagsCount;
    },
    getResponseContent: function (response) {
        if (response.srcClass !== false) {
            const contentArray = response.responseXML.body.getElementsByClassName(response.srcClass);
            return contentArray.length > 0 ? contentArray[0] : null;
        }

        return response.responseXML.body;
    },
    addContent: function (response) {
        switch (response.action) {
            case 'replace':
                response.target.innerHTML = CLoader.getResponseContent(response).innerHTML;
                break;
            case 'add':
                const source = CLoader.getResponseContent(response);
                Array.prototype.slice.call(source.getElementsByClassName('js-cloader-item')).forEach(CLoader.markAsNew);
                if (response.target.firstChild) {
                    Array.prototype.slice.call(response.target.getElementsByClassName('js-cloader-item')).forEach(CLoader.replaceShadowNodeWithTargetNode, source);
                    response.target.firstChild.replaceWith(source.firstChild);
                } else {
                    response.target.appendChild(source.firstChild);
                }
                break;
        }
    },
    markAsNew: function(item) {
        item.className += ' is-new';
    },
    replaceShadowNodeWithTargetNode: function (item) {
        const source = this;
        let targetInSourceReference = source.querySelector('.js-cloader-item[data-id="' + item.getAttribute('data-id') + '"]');
        if (targetInSourceReference && targetInSourceReference.getAttribute('data-tstamp') <= item.getAttribute('data-tstamp')) {
            item.className = item.className.replace(' is-new', '');
            targetInSourceReference.replaceWith(item);
        }
    },
    copyTags: function (source, target, sourceId, tagName) {
        const tagCollection = source.getElementsByTagName(tagName);
        let length = tagCollection.length;
        if (length > 0) {
            const responseTags = Array.prototype.slice.call(tagCollection);
            const tags = Array.prototype.slice.call(document.getElementsByTagName(tagName));
            const newTags = responseTags.filter(CLoader.filterCallbackNewTag, tags);
            if (tagName === 'script') {
                CLoader.elementScriptTags[sourceId] = newTags;
            }
            newTags.forEach(CLoader.copyTag, sourceId);
            responseTags.forEach(CLoader.removeTag);
            length = newTags.length;
        }

        return length;
    },
    filterCallbackNewTag: function (item) {
        if (item.tagName === 'SCRIPT') {
            return CLoader.tagIsNew(this, item.src, 'src');
        } else if (item.tagName === 'LINK') {
            return CLoader.tagIsNew(this, item.href, 'href');
        }
    },
    tagIsNew: function (tags, url, field) {
        let isNew = true;
        for (var i = 0; i < tags.length; i++) {
            if (tags[i][field] === url) {
                isNew = false;
                break;
            }
        }

        return isNew;
    },
    copyTag: function (item) {
        const tag = document.createElement(item.tagName);
        if (item.tagName === 'SCRIPT') {
            tag.src = item.src;
            tag.async = item.async;
            tag.srcId = this;
            tag.addEventListener('load', CLoader.setState);
            tag.readyState = 'loading';
            document.body.appendChild(tag);
        } else if (item.tagName === 'LINK') {
            tag.href = item.href;
            tag.rel = item.rel;
            tag.type = item.type;
            tag.media = item.media;
            document.head.appendChild(tag);
        }
    },
    removeTag: function (tag) {
        tag.parentNode.removeChild(tag);
    },
    setState: function (event) {
        CLoader.elementScriptTags[this.srcId] = CLoader.elementScriptTags[this.srcId].filter(function (item) {
            if (item.src === this.src) {
                item.readyState = 'complete';
            }

            return item.readyState !== 'complete';
        }, this);

        if (CLoader.elementScriptTags[this.srcId].length === 0) {
            document.getElementById(this.srcId).dispatchEvent(CLoader.after);
        }
    },
    error: function () {
        console.log('Error establishing the connection or invalid response');
    },
};

CLoader.registerEvents();
CLoader.registerAjaxNotify();
'use strict';

const Toggler = {
    init: function() {
        Array.prototype.slice.call(document.getElementsByClassName('js-toggle')).forEach(Toggler.attachShowOnClick);
    },
    registerAjaxNotify: function() {
        typeof AjaxObserver !== 'function' || AjaxObserver.registerObject('Toggler', Toggler.notifyRefresh, 'js-toggle-initialized', 'js-toggle');
    },
    notifyRefresh: function(event) {
        Toggler.init();
    },
    attachShowOnClick: function(item) {
        typeof AjaxObserver !== 'function' || AjaxObserver.setInitialized(item, 'Toggler');
        item.addEventListener('click', Toggler.toggleElements);
    },
    toggleElements: function(event) {
        if (this.nodeName === 'A') {
            event.preventDefault();
        }

        const targetClassName = 'js-toggle-' + this.getAttribute('data-toggle');
        const group = this.getAttribute('data-toggle-group');
        const alwaysOn = this.getAttribute('data-always-on');

        if (this.on && group && alwaysOn) {
            return;
        }

        if (this.on !== true && group) {
            Array.prototype.slice.call(document.querySelectorAll('[data-toggle-group="' + group + '"]')).forEach(Toggler.closeGroup);
        }

        Toggler.toggleToggleState(this);
        Array.prototype.slice.call(document.getElementsByClassName(targetClassName)).forEach(Toggler.toggleTarget);
    },
    toggleToggleState: function(element) {
        if (element.on) {
            if (element.getAttribute('data-label-off')) {
                element.textContent = element.getAttribute('data-label-off');
            }

            element.className = element.className.replace(' is-active', '');
            element.on = false;
        } else {
            if (element.getAttribute('data-label-on')) {
                element.textContent = element.getAttribute('data-label-on');
            }

            element.className += ' is-active';
            element.on = true;
        }
    },
    toggleTarget: function(item) {
        const targetClassName = item.className;

        if (targetClassName.indexOf('is-toggled') === -1) {
            item.className += ' is-toggled';
        } else {
            item.className = item.className.replace(' is-toggled', '');
        }
    },
    closeGroup: function(item) {
        Array.prototype.slice.call(document.getElementsByClassName('js-toggle-' + item.getAttribute('data-toggle'))).forEach(function (el) {
            el.className = el.className.replace(' is-toggled', '');
        });
        item.className = item.className.replace(' is-active', '');
        item.on = false;
    },
};

Toggler.registerAjaxNotify();
Toggler.init();
const HistoryBack = {
    init: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-historyback')).forEach(HistoryBack.attachEventListeners);
    },
    attachEventListeners: function (item) {
        item.addEventListener('click', HistoryBack.pageBack);
    },
    pageBack: function (event) {
        if (document.referrer.indexOf(location.origin) === 0) {
            event.preventDefault();

            window.history.back();
        }
    }
};

HistoryBack.init();

const Accordion = {
    init: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-accordion')).forEach(function (el) {
            el.addEventListener('click', Accordion.toggleHandling);
        });
    },
    toggleHandling: function (event) {
        if (this.nodeName === 'A') {
            event.preventDefault();
        }
        const targetClassName = 'js-accordion-target-' + this.getAttribute('data-target');
        const group = this.getAttribute('data-group');
        if (this.on !== true && group) {
            Array.prototype.slice.call(document.querySelectorAll('[data-group="' + group + '"]')).forEach(Accordion.closeGroup);
        }
        if (this.on) {
            this.setAttribute('aria-expanded', false);
            this.classList.remove('is-active');
            this.on = false;
        } else {
            this.setAttribute('aria-expanded', true);
            this.classList.add('is-active');
            this.on = true;
        }
        Array.prototype.slice.call(document.getElementsByClassName(targetClassName)).forEach(Accordion.toggleElement);
        if (this.on === true && this.classList.contains('js-accordion-scroll')) {
            const offsetPosition = document.querySelector('.js-header') ? document.querySelector('.js-header').offsetHeight : 0;
            Accordion.scroll(this.getBoundingClientRect().top - 20 - offsetPosition);
        }
    },
    toggleElement: function (item) {
        if (item.className.indexOf('is-open') === -1) {
            item.classList.add('is-open');
            item.setAttribute('aria-hidden', false);
            item.style.maxHeight = item.scrollHeight + "px";
        } else {
            item.classList.remove('is-open');
            item.setAttribute('aria-hidden', true);
            item.style.maxHeight = "0";
        }
    },
    closeGroup: function (item) {
        const target = document.querySelector('.js-accordion-target-' + item.getAttribute('data-target'));
        item.classList.remove('is-active');
        item.on = false;
        target.classList.remove('is-open');
        target.style.maxHeight = "0";
    },
    scroll: function (positionTop) {
        window.scrollBy({top: positionTop, left: 0, behavior: 'smooth'})
    },
    updateHeight: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-accordion-body')).forEach(function (el) {
            if (el.classList.contains('is-open')) {
                el.style.maxHeight = el.scrollHeight + "px";
            }
        });
    }
};

Accordion.init();
const CheckWrap = {
    init: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-check-wrap')).forEach(CheckWrap.checkItems);
    },
    checkItems: function (item) {
        item.classList.remove('is-loaded');
        Array.prototype.slice.call(item.getElementsByClassName('js-check-wrap-item')).forEach(function (el) {
            let currItem = el;
            let nextItem = el.nextElementSibling;
            currItem.classList.remove('is-last-in-row');
            if (!nextItem) currItem.classList.add('is-last-in-row');
            if (nextItem && nextItem.getBoundingClientRect().top > currItem.getBoundingClientRect().top) {
                currItem.classList.add('is-last-in-row');
            }
        });
        item.classList.add('is-loaded');
    }
};

// CheckWrap.init();
class Cookie {
    static init() {
        // set cookie if not exist for sso-redirect
        Cookie.setCookie('sso-postlogin-redirect', window.location.href, 30, '.zsclions.ch');
    }

    static getCookie(name) {
        // Split cookie string and get all individual name=value pairs in an array
        let cookieArr = document.cookie.split(";");
        // Loop through the array elements
        for (let i = 0; i < cookieArr.length; i++) {
            let cookiePair = cookieArr[i].split("=");
            /* Removing whitespace at the beginning of the cookie name and compare it with the given string */
            if (name === cookiePair[0].trim()) {
                // Decode the cookie value and return
                return decodeURIComponent(cookiePair[1]);
            }
        }
        // Return null if not found
        return null;
    }

    static setCookie(name, value, daysToLive, domain = null) {
        let cookie = name + "=" + value;
        if (domain) cookie += "; domain=" + domain + "; path=/";
        if (typeof daysToLive === "number") {
            /* Sets the max-age attribute so that the cookie expires after the specified number of days */
            cookie += "; expires=" + new Date(Date.now() + daysToLive * 864e5).toUTCString();
            document.cookie = cookie;
        }
    }
}

Cookie.init();
const Countdown = {
    init: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-countdown')).forEach(function (item) {
            let dateEnd = new Date(item.getAttribute('data-enddate'));
            if (!isNaN(dateEnd)) {
                Countdown.calculate(item, dateEnd);
                let timer = setInterval(function () {
                    Countdown.calculate(item, dateEnd);
                }, 1000);
            }
        });
    },
    calculate: function (el, dateEnd) {
        let dateStart = new Date();
        let timeRemaining = parseInt((dateEnd - dateStart) / 1000);
        let hours = 0, minute = 0, sec = 0;
        if (timeRemaining >= 0) {
            hours = parseInt(timeRemaining / 3600);
            timeRemaining = (timeRemaining % 3600);
            minute = parseInt(timeRemaining / 60);
            sec = (timeRemaining % 60);
        }
        el.querySelector('.js-countdown-hours-value').textContent = hours.toString().padStart(2, '0');
        el.querySelector('.js-countdown-minute-value').textContent = minute.toString().padStart(2, '0');
        el.querySelector('.js-countdown-sec-value').textContent = sec.toString().padStart(2, '0');
    }
};

Countdown.init();
const crmForm = {
    init: function() {
        Array.prototype.slice.call(document.getElementsByClassName('js-crm-form')).forEach(function (el) {
            let timer = setInterval(function () {
                if (el.querySelector('style')) {
                    el.querySelector('style').remove();
                    CustomProperties.update(); // us this to update custom properties
                    clearInterval(timer);
                }
            }, 100);
        });
    }
};

crmForm.init();
const CustomProperties = {
    props: [],
    init: function () {
        CustomProperties.props = [
            {element: window, cssVar: '--vh'}, // for viewHeight calc on mobile, e.g. for component hero -> height: calc(var(--vh) * 100)
            {element: window, cssVar: '--ih', type: 'innerHeight'}, // for innerHeight calc on mobile, e.g. for component pusha -> height: calc(var(--ibh) * 100)
            {element: document.querySelector('.js-header'), cssVar: '--hh', type: 'offsetHeight'},
            {element: document.getElementById('js-infobar'), cssVar: '--ibh', type: 'offsetHeight'},
        ];
    },
    update: function () {
        Array.prototype.slice.call(CustomProperties.props).forEach(function (prop) {
            if (prop['element']) {
                switch (prop['type']) {
                    case 'offsetHeight':
                        CustomProperties.setVar(prop['cssVar'], prop['element'].offsetHeight);
                        break;
                    case 'innerHeight':
                        CustomProperties.setVar(prop['cssVar'], prop['element'].innerHeight * 0.01); // for overall browser support
                        break;
                    default:
                        CustomProperties.setVar(prop['cssVar'], prop['element'].document.documentElement.clientHeight * 0.01); // for overall browser support
                        break;
                }
            }
        });
    },
    getVar: function (name) {
        return Number(getComputedStyle(document.documentElement).getPropertyValue(name).replace("px", ""));
    },
    setVar: function (name, value) {
        document.documentElement.style.setProperty(name, "" + value + "px");
    }
};

CustomProperties.init();
CustomProperties.update();

const InfoBar = {
    showDelay: 1000,
    element: document.getElementById('js-infobar'),
    btnClose: document.getElementById('js-infobar-close'),
    init: function () {
        if (!localStorage.infobarClose && !sessionStorage.infobarClose && InfoBar.element) {
            InfoBar.checkCookie();
        }
        if (InfoBar.btnClose) {
            InfoBar.btnClose.addEventListener('click', InfoBar.setCookie);
        }
    },
    checkCookie: function () {
        let timeNow = (new Date()).getTime();
        let lastTimeHidden = localStorage.getItem('infobar_time');
        // 1000 * 60 * 60 * 24 = 24 Hours
        if (timeNow - lastTimeHidden > 1000 * 60 * 60 * 24) {
            localStorage.removeItem('infobar_time');
            InfoBar.element.classList.remove('hidden');
            setTimeout(function () {
                document.body.classList.add('infobar-active');
                CustomProperties.update();
            }.bind(this), InfoBar.showDelay);
        }
    },
    setCookie: function (event) {
        event.preventDefault();
        let timeNow = (new Date()).getTime();
        window.localStorage.setItem('infobar_time', timeNow);
        InfoBar.element.classList.add('hidden');
        document.body.classList.remove('infobar-active');
        CustomProperties.update();
    },
};

InfoBar.init();
const LiveGame = {
    container: document.getElementsByClassName('js-live-game-container')[0],
    init: function () {
        if (LiveGame.container) {
            if (LiveGame.container.childElementCount > 0) {
                document.body.classList.add('game-is-live');
            } else {
                document.body.classList.remove('game-is-live');
            }
        }
        LiveGame.switchElements();
    },
    switchElements: function () {
        if (document.body.classList.contains('game-is-live')) {
            Array.prototype.slice.call(document.getElementsByClassName('js-live-game-hide')).forEach(function (el) {
                el.classList.add('hidden');
            });
            // Array.prototype.slice.call(document.getElementsByClassName('js-live-game-visible')).forEach(function (el) {
            //     el.classList.remove('hidden');
            // });
            document.getElementsByClassName('js-live-game-visible')[0].classList.remove('hidden');
        } else {
            Array.prototype.slice.call(document.getElementsByClassName('js-live-game-hide')).forEach(function (el) {
                el.classList.remove('hidden');
            });
            Array.prototype.slice.call(document.getElementsByClassName('js-live-game-visible')).forEach(function (el) {
                el.classList.add('hidden');
            });
        }
    }
};

// LiveGame.init();
const NavDrilldown = function (el) {
    this.el = el;
    this.main = this.el;
    this.list = this.main.querySelector('.js-nav-list');
    this.panel = this.main.querySelector('.js-nav-panel');
    this.init();
};

NavDrilldown.prototype.init = function () {
    this.animationDuration = 600;
    this.bindInteractions();
};

NavDrilldown.prototype.bindInteractions = function () {
    let obj = this;

    Array.prototype.slice.call(obj.main.getElementsByClassName('js-nav-level-next')).forEach(function (item) {
        obj.attachNextEventListener(item, obj);
    });
    Array.prototype.slice.call(obj.main.getElementsByClassName('js-nav-level-prev')).forEach(function (item) {
        obj.attachPrevEventListener(item, obj);
    });
};

NavDrilldown.prototype.attachNextEventListener = function (item, obj) {
    item.addEventListener('click', obj.onMainLinkClick.bind(this));
};

NavDrilldown.prototype.attachPrevEventListener = function (item, obj) {
    item.addEventListener('click', obj.onBackButtonClick.bind(this));
};

NavDrilldown.prototype.bindClickOutside = function () {
    this.clickOutsideHandler = this.onClickOutside.bind(this);
    document.addEventListener('click', this.clickOutsideHandler);
};

NavDrilldown.prototype.unbindClickOutside = function () {
    document.removeEventListener('click', this.clickOutsideHandler);
};

NavDrilldown.prototype.onMainLinkClick = function (event) {
    event.preventDefault();
    let obj = this;
    let link = event.currentTarget;
    let item = link.closest('li');
    if (!item.classList.contains('has-sub')) {
        return;
    }
    obj.openLevelTwo(item);
};

NavDrilldown.prototype.onBackButtonClick = function () {
    let activeItem = this.main.querySelector('.js-nav-level-first-item.is-open');
    if (!activeItem) return;
    if (!activeItem.classList.contains('has-sub')) return;
    this.closeLevelTwo(activeItem);
};

NavDrilldown.prototype.onClickOutside = function (event) {
    if (!this.panel.contains(event.target)) return; // Do nothing if clicked element is not inside panel.
    this.onBackButtonClick(event);
};

NavDrilldown.prototype.openLevelTwo = function (item) {
    document.documentElement.classList.add('menu-active');
    item.classList.add('is-open');
    item.querySelector('.js-nav-sub-panel').classList.add('is-open');
    this.panel.classList.add('is-open');
    this.bindClickOutside();
};

NavDrilldown.prototype.closeLevelTwo = function (item) {
    setTimeout(function () {
        document.documentElement.classList.remove('menu-active');
    }.bind(this), this.animationDuration);
    item.classList.remove('is-open');
    item.querySelector('.js-nav-sub-panel').classList.remove('is-open');
    this.panel.classList.remove('is-open');
    this.unbindClickOutside();
};

NavDrilldown.prototype.showCurrentLevel = function (container) {
    let isCurrent = container.querySelector('.js-nav-level-first-item.has-sub.is-current') || null;
    if (isCurrent === null) return;
    let target = isCurrent.querySelector('.js-nav-level-next') || null;
    if (target !== null) {
        target.dispatchEvent(new Event('click'));
    }
};

Array.prototype.slice.call(document.getElementsByClassName('js-nav-drilldown')).forEach(function (menu) {
    new NavDrilldown(menu);
});
const NavDropdown = function (el) {
    this.el = el;
    this.main = this.el;
    this.background = this.main.querySelector('.js-nav-panel');
    this.init();
};

NavDropdown.prototype.init = function () {
    this.bindInteractions();
};

NavDropdown.prototype.bindInteractions = function () {
    let obj = this;
    Array.prototype.slice.call(obj.main.getElementsByClassName('js-nav-level-next')).forEach(function (item) {
        obj.attachNextEventListener(item, obj);
    });
};

NavDropdown.prototype.attachNextEventListener = function (item, obj) {
    item.addEventListener('click', obj.onMainLinkClick.bind(this));
};

NavDropdown.prototype.bindClickOutside = function () {
    this.clickOutsideHandler = this.onClickOutside.bind(this);
    document.addEventListener('click', this.clickOutsideHandler);
};

NavDropdown.prototype.unbindClickOutside = function () {
    document.removeEventListener('click', this.clickOutsideHandler);
};

NavDropdown.prototype.onClickOutside = function (event) {
    if (event.defaultPrevented) return;
    if (this.el.contains(event.target)) return; // Do nothing if clicked element is inside navigation.
    let activeItem = this.main.querySelector('.js-nav-level-first-item.is-open');
    if (!activeItem) return;
    if (!activeItem.classList.contains('has-sub')) return;
    let activeList = activeItem.parentElement;
    this.closeLevelTwo(activeList, activeItem);
};

NavDropdown.prototype.onMainLinkClick = function (e) {
    let obj = this;
    let link = e.currentTarget;
    let item = link.closest('li');
    let list = link.closest('ul');
    if (link.classList.contains('js-nav-level-first-link')) {
        if (item.classList.contains('is-open')) {
            obj.closeLevelTwo(list, item);
        } else if (list.classList.contains('is-open')) {
            obj.switchLevelTwo(list, item);
        } else {
            obj.setIntialStateToCurrent();
            obj.openLevelTwo(list, item);
        }
    } else if (link.classList.contains('js-nav-level-sub-link')) {
        if (item.classList.contains('is-open')) {
            obj.closeLevelThree(list, item);
        } else if (list.classList.contains('is-open')) {
            obj.switchLevelThree(list, item);
        } else {
            obj.openLevelThree(list, item);
        }
    }
};

NavDropdown.prototype.openLevelTwo = function (list, item) {
    this.el.classList.add('is-open');
    this.background.classList.add('is-open');
    list.classList.add('is-open');
    item.classList.add('is-open');
    item.querySelector('.js-nav-sub-panel').classList.add('is-open');
    this.updatePanelHeight();
    this.bindClickOutside();
};

NavDropdown.prototype.switchLevelTwo = function (list, item) {
    let activeItem = list.querySelector('.js-nav-level-first-item.is-open');
    activeItem.classList.remove('is-open');
    activeItem.querySelector('.js-nav-sub-panel').classList.remove('is-open');
    item.classList.add('is-open');
    item.querySelector('.js-nav-sub-panel').classList.add('is-open');
    this.updatePanelHeight();
};

NavDropdown.prototype.closeLevelTwo = function (list, item) {
    list.classList.remove('is-open');
    item.classList.remove('is-open');
    item.querySelector('.js-nav-sub-panel').classList.remove('is-open');
    this.el.classList.remove('is-open');
    this.background.classList.remove('is-open');
    this.background.removeAttribute('style');
    this.unbindClickOutside();
};

NavDropdown.prototype.openLevelThree = function (list, item, animated) {
    if (animated === undefined) animated = true;
    list.classList.add('is-open');
    item.classList.add('is-open');
    item.querySelector('.js-nav-level-subsub-list').classList.add('is-open');
    if (animated) this.updatePanelHeight();
};

NavDropdown.prototype.switchLevelThree = function (list, item) {
    let activeItem = list.querySelector('.js-nav-level-sub-item.is-open');
    list.classList.remove('is-open');
    activeItem.classList.remove('is-open');
    activeItem.querySelector('.js-nav-level-subsub-list').classList.remove('is-open');
    this.openLevelThree(list, item);
};

NavDropdown.prototype.closeLevelThree = function (list, item) {
    list.classList.remove('is-open');
    item.classList.remove('is-open');
    item.querySelector('.js-nav-level-subsub-list').classList.remove('is-open');
    this.updatePanelHeight();
};

NavDropdown.prototype.setIntialStateToCurrent = function () {
    let currentItem = this.main.querySelector('.js-nav-level-sub-item.is-current');
    if (!currentItem) return;
    if (!currentItem.classList.contains('has-sub')) return;
    let currentList = currentItem.parentElement;
    this.openLevelThree(currentList, currentItem, false);
};

NavDropdown.prototype.updatePanelHeight = function () {
    let item = this.main.querySelector('.js-nav-level-first-item.is-open');
    let subItem = item.querySelector('.js-nav-level-sub-item.is-open');
    let panel = item.querySelector('.js-nav-sub-panel');
    let panelStyles = window.getComputedStyle(panel);
    let panelHeight = panel.clientHeight;
    let panelPadding = parseFloat(panelStyles.paddingTop) + parseFloat(panelStyles.paddingBottom);
    if (subItem) {
        let subSubItemHeight = subItem.querySelector('.js-nav-level-subsub-list').clientHeight;
        if (subSubItemHeight > (panelHeight - panelPadding)) panelHeight = subSubItemHeight + panelPadding;
    }
    this.background.style.height = panelHeight + 'px';
};

Array.prototype.slice.call(document.getElementsByClassName('js-nav-dropdown')).forEach(function (menu) {
    new NavDropdown(menu);
});
const Panel = {
    init: function () {
        Panel.container = document.getElementById('navigation');
        Panel.burger = document.getElementsByClassName('js-open-panel');

        if (Panel.container) {
            const panel = Panel.container;

            new Pusha(panel, {
                onOpen: function (panel) {
                    Array.prototype.slice.call(document.querySelectorAll('[data-panel="#' + panel.id + '"]')).forEach(function (item) {
                        item.querySelector('.js-hamburger-btn').classList.add('active');
                    });
                    setTimeout(function () {
                        NavDrilldown.prototype.showCurrentLevel(Panel.container);
                    }.bind(this), 500);
                },
                onClose: function (panel) {
                    Array.prototype.slice.call(document.querySelectorAll('[data-panel="#' + panel.id + '"]')).forEach(function (item) {
                        item.querySelector('.js-hamburger-btn').classList.remove('active');
                    });
                }
            });
        }

        Array.prototype.slice.call(Panel.burger).forEach(function (button) {
            const panel = document.querySelector(button.getAttribute('data-panel'));

            button.addEventListener('click', function (e) {
                e.preventDefault();
                ScrollPosition.setPosition();
                panel.pusha.toggle(e);
                ScrollPosition.scrollToPosition(ScrollPosition.currentScroll);
            });
        });
    }
}

Panel.init();
const Progressbar = {
    init: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-progressbar')).forEach(function (item) {
            let percentValue = (item.getAttribute('data-value') / item.getAttribute('data-total') * 100);
            if (percentValue === 0) item.classList.add('hidden');
            item.style.width = percentValue + '%';
        });
    }
};

Progressbar.init();
const Random = {
    init: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-random-container')).forEach(function (container) {
            Random.showElement(container.getElementsByClassName('js-random-element')[Random.getRandom(container.getElementsByClassName('js-random-element').length)]);
        });
    },
    getRandom: function (max) {
        return Math.floor(Math.random() * Math.floor(max));
    },
    showElement: function (el) {
        el.classList.remove('hidden');
        if (el.querySelector('video')) {
            const video = el.querySelector('video'), source = el.querySelector('source');
            source.setAttribute('src', source.getAttribute('data-src'));
            video.load();
            video.play();
        }
    }
};

Random.init();
const ScrollDirection = {
    init: function () {
        ScrollDirection.scrollUp = 'scroll-up';
        ScrollDirection.scrollDown = 'scroll-down';
        ScrollDirection.lastScroll = 0;
    },
    checkDirection: function () {
        let headerHeight = document.getElementsByClassName('js-header')[0] ? document.getElementsByClassName('js-header')[0].offsetHeight : 0;
        let currentScroll = window.pageYOffset | document.body.scrollTop;

        if (currentScroll <= headerHeight) {
            document.body.classList.remove(ScrollDirection.scrollUp, ScrollDirection.scrollDown);
            return;
        }

        if (currentScroll > headerHeight) {
            if (currentScroll > ScrollDirection.lastScroll && !document.body.classList.contains(ScrollDirection.scrollDown)) {
                // down
                document.body.classList.remove(ScrollDirection.scrollUp);
                document.body.classList.add(ScrollDirection.scrollDown);
            } else if (currentScroll < ScrollDirection.lastScroll && document.body.classList.contains(ScrollDirection.scrollDown)) {
                // up
                document.body.classList.remove(ScrollDirection.scrollDown);
                document.body.classList.add(ScrollDirection.scrollUp);
            }
            ScrollDirection.lastScroll = currentScroll;
        }
    },
};

ScrollDirection.init();

const ScrollIntoView = {
    scrolling: false,
    init: function () {
        let el = document.getElementById('js-scroll-into-view');
        if (el !== null && ScrollIntoView.scrolling === false) {
            window.setTimeout(function () {
                window.scrollTo({
                    top: 0,
                    left: 0,
                    behavior: "instant"
                });
                let offsetHeight = document.getElementsByClassName('js-sticky-title')[0] ? document.getElementsByClassName('js-sticky-title')[0].offsetHeight : 0;
                let elementPosition = el.getBoundingClientRect().top;
                let offsetPosition = elementPosition + window.pageYOffset - offsetHeight;
                window.scrollTo({
                    top: offsetPosition,
                    behavior: "smooth"
                });
                ScrollIntoView.scrolling = true;
            }, 1000);
        }
    },
};

// ScrollIntoView.init();
const ScrollPosition = {
    init: function () {
        ScrollPosition.currentScroll = 0;
    },
    getPosition: function () {
        if (window.pageYOffset !== undefined) {
            return window.pageYOffset;
        } else {
            return document.body.scrollTop;
        }
    },
    setPosition: function () {
        ScrollPosition.currentScroll = window.pageYOffset | document.body.scrollTop;
    },
    scrollToPosition: function (pos) {
        document.body.scrollTop = pos;
        window.scrollTo({top: pos});
    },
};

ScrollPosition.init();

const ScrollToAnchor = {
    init: function () {
        if (typeof SmoothScroll !== "undefined") {
            const scroll = new SmoothScroll('a[href*="#"]', {
                updateURL: false,
                speed: 600,
                speedAsDuration: true,
                offset: function () {
                    return document.querySelector('.js-header') ? document.querySelector('.js-header').offsetHeight : 0;
                }
            });
        }
    }
};

ScrollToAnchor.init();
const Swipe = {
    init: function () {
        Swipe.items = document.getElementsByClassName('js-swipe');
        Array.prototype.slice.call(Swipe.items).forEach(function (item) {
            item.closest('.js-swipe-check').addEventListener('scroll', Swipe.checkScrollPosition);
        });
        Swipe.checkScrollable();
    },
    checkScrollable: function () {
        Array.prototype.slice.call(Swipe.items).forEach(function (item) {
            if (Swipe.isInContainer(item) === false) {
                item.parentNode.parentNode.querySelector('.js-swipe-hint').classList.add('is-visible');
            } else {
                item.parentNode.parentNode.querySelector('.js-swipe-hint').classList.remove('is-visible');
            }
        });
    },
    checkScrollPosition: function (e) {
        let scrollRight = e.target.scrollWidth - e.target.clientWidth - e.target.scrollLeft;
        if (e.target.scrollLeft >= 0 && scrollRight <= 5) {
            e.target.parentNode.querySelector('.js-swipe-hint').classList.remove('is-visible');
        } else {
            e.target.parentNode.querySelector('.js-swipe-hint').classList.add('is-visible');
        }
    },
    isInContainer: function (elem) {
        let bounding = elem.getBoundingClientRect();
        return (
            bounding.left >= 0 &&
            bounding.right <= (window.innerWidth || document.documentElement.clientWidth)
        );
    }
};

Swipe.init();
const TableSort = {
    init: function () {
        TableSort.trigger = document.getElementsByClassName('js-table-sort-trigger');
        Array.prototype.slice.call(TableSort.trigger).forEach(TableSort.attachEventListener);
        TableSort.start();
    },
    attachEventListener: function (item) {
        item.addEventListener('click', TableSort.update);
    },
    update: function (event) {
        event.preventDefault();
        TableSort.showResult(this);
        TableSort.setActiveState(this);
    },
    start: function () {
        Array.prototype.slice.call(TableSort.trigger).forEach(function (item) {
            if (item.classList.contains('js-table-sort-start')) item.click();
        });
    },
    showResult: function (el) {
        let table = el.closest('.js-table-sort');
        let tbody = table.querySelector('.js-table-sort-body');
        Array.from(tbody.getElementsByClassName('js-table-sort-row'))
        // .sort(TableSort.comparer(el.dataset.col, el.desc = !el.desc))
            .sort(TableSort.comparer(el.dataset.col, true))
            .forEach(tr => tbody.appendChild(tr));
    },
    setActiveState: function (el) {
        Array.prototype.slice.call(el.closest('.js-table-sort').getElementsByClassName('js-table-sort-trigger')).forEach(function (item) {
            item.classList.remove('is-active');
        });
        el.classList.add('is-active');
    },
    // Returns a function responsible for sorting a specific column index
    // (idx = columnIndex, asc = ascending order?).
    comparer: function (idx, desc) {
        // This is used by the array.sort() function...
        return function (a, b) {
            // This is a transient function, that is called straight away.
            // It allows passing in different order of args, based on
            // the ascending/descending order.
            return function (v1, v2) {
                // sort based on a numeric or localeCompare, based on type...
                if (v1.indexOf('%') !== -1) v1 = v1.replace('%','');
                if (v2.indexOf('%') !== -1) v2 = v2.replace('%','');
                return v1 !== '' && v2 !== '' && !isNaN(v1) && !isNaN(v2) ? v1 - v2 : v1.toString().localeCompare(v2);
            }(TableSort.getCellValue(desc ? b : a, idx), TableSort.getCellValue(desc ? a : b, idx));
        }
    },
    getCellValue: function (tr, idx) {
        return tr.children[idx].innerText || tr.children[idx].textContent;
    },
};

TableSort.init();
const ToggleClose = {
    init: function () {
        document.addEventListener('click', ToggleClose.clickHandler);
    },
    clickHandler: function (e) {
        e.stopPropagation();
        if (e.target.closest('.js-toggle-close') === null) {
            Array.prototype.slice.call(document.getElementsByClassName('js-toggle-close')).forEach(function (item) {
                let toggle = item.getElementsByClassName('js-toggle')[0] || item.getElementsByClassName('js-toggle-initialized')[0];
                if (toggle != null && toggle.classList.contains('is-active')) {
                    toggle.click();
                }
            });
        }
    },
};

ToggleClose.init();
const VideoControl = {
    init: function () {
        VideoControl.mutedElements = document.getElementsByClassName('js-video-muted');
        VideoControl.fullscreenElements = document.getElementsByClassName('js-video-fullscreen');
        Array.prototype.slice.call(VideoControl.mutedElements).forEach(VideoControl.attachMutedEventListener);
        Array.prototype.slice.call(VideoControl.fullscreenElements).forEach(VideoControl.attachFullscreenEventListener);
    },
    attachMutedEventListener: function (item) {
        item.addEventListener('click', VideoControl.mutedElement);
    },
    attachFullscreenEventListener: function (item) {
        item.addEventListener('click', VideoControl.fullscreenElement);
    },
    mutedElement: function () {
        if (this.nodeName === 'A') {
            event.preventDefault();
        }
        if (this.className.indexOf('is-toggled') === -1) {
            this.className += ' is-toggled';
        } else {
            this.classList.remove('is-toggled');
        }
        let targets = document.getElementsByClassName('js-video-target-' + this.getAttribute('data-target'));
        Array.prototype.slice.call(targets).forEach(function (video) {
            video.muted = !video.muted;
        });
    },
    fullscreenElement: function () {
        if (this.nodeName === 'A') {
            event.preventDefault();
        }
        let targets = document.getElementsByClassName('js-video-target-' + this.getAttribute('data-target'));
        Array.prototype.slice.call(targets).forEach(function (video) {
            if (video.requestFullscreen) {
                video.requestFullscreen();
            } else if (video.webkitEnterFullscreen) {
                video.webkitEnterFullscreen();
            } else if (video.msRequestFullscreen) {
                video.msRequestFullscreen();
            } else if (video.webkitRequestFullscreen) {
                video.webkitRequestFullscreen();
            }
        });
    }
};

VideoControl.init();


function scrollEvent() {
    //if (typeof Paginate !== 'undefined') {
    //    Paginate.scrollCheck(); // use this if you want to trigger pagination on scrolling
    //}

    // Put your code here
    ScrollDirection.checkDirection();

    GlobalEventThrottle.throttleScroll = false;
    //console.log(GlobalEventThrottle.scrollEvent);
}


function resizeEvent() {
    //if (typeof Masonry !== 'undefined') {
    //    Masonry.resizeAllMasonryItems();
    //}

    // Put your code here
    CustomProperties.update(); // us this to update custom properties
    Swipe.checkScrollable();
    Accordion.updateHeight();
    CheckWrap.init();

    GlobalEventThrottle.throttleResize = false;
    //console.log(GlobalEventThrottle.resizeEvent);
}


// function loadEvent() {
//     const fontA = new FontFaceObserver('Hurme Geometric Sans 2');
//     Promise.all([fontA.load()]).then(function () {
//         document.querySelectorAll("img").forEach(img => {
//             if (!img.loaded) {
//                 CheckWrap.init();
//             }
//         });
//     });
//     // CheckWrap.init();
//     // CustomProperties.update();
// }


function readyEvent() {
    // init after all fonts are loaded
    const fontA = new FontFaceObserver('Hurme Geometric Sans 2');
    Promise.all([fontA.load()]).then(function () {
        CheckWrap.init();
        CustomProperties.update();
    });

    if (typeof CLoader === 'object' && document.getElementsByClassName('js-cloader').length > 0) {
        CLoader.init();
    }

    Array.prototype.slice.call(document.getElementsByClassName('js-tab-trigger')).forEach(function (el) {
        el.addEventListener('tabby.after', function () {
            Swipe.checkScrollable();
            CheckWrap.init();
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-partial-news')).forEach(function (item) {
        item.addEventListener('ajaxSubmit.after', function () {
            if (typeof Toggler !== 'undefined') Toggler.init();
            if (typeof Paginate !== 'undefined') Paginate.init();
        });

        item.addEventListener('paginate.after', function () {
            if (typeof Toggler !== 'undefined') Toggler.init();
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-partial-stats')).forEach(function (item) {
        item.addEventListener('ajaxSubmit.after', function () {
            if (typeof AjaxSubmit !== 'undefined') AjaxSubmit.init();
            Accordion.init();
            CheckWrap.init();
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-partial-tabs')).forEach(function (item) {
        item.addEventListener('ajaxSubmit.after', function () {
            if (typeof AjaxSubmit !== 'undefined') AjaxSubmit.init();
            if (typeof Tabby !== 'undefined') Tabby.init();
            if (typeof Toggler !== 'undefined') Toggler.init();
            if (typeof CLoader !== 'undefined' && document.getElementsByClassName('js-cloader').length > 0) {
                CLoader.init();
            }
            Accordion.init();
            CheckWrap.init();
            Progressbar.init();
            TableSort.init();
            VimeoLoader.init();
            YouTubeLoader.init();
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-cloader')).forEach(function (item) {
        item.addEventListener('cloader.after', function () {
            if (typeof AjaxSubmit !== 'undefined') AjaxSubmit.init();
            if (typeof ChangeSubmit !== 'undefined') ChangeSubmit.init();
            if (typeof Tabby !== 'undefined') Tabby.init();
            if (typeof Toggler !== 'undefined') Toggler.init();
            Accordion.init();
            CheckWrap.init();
            Countdown.init();
            LiveGame.init();
            Progressbar.init();
            VimeoLoader.init();
            YouTubeLoader.init();
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-cloader-slider')).forEach(function (item) {
        item.addEventListener('cloader.after', function () {
            Slider.init();
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-cloader-paginate')).forEach(function (item) {
        item.addEventListener('cloader.after', function () {
            if (typeof FilterPublication !== 'undefined') FilterPublication.replaceContent();
            if (typeof Toggler !== 'undefined') Toggler.init();
            if (typeof Paginate !== 'undefined') Paginate.init();

            Array.prototype.slice.call(document.getElementsByClassName('js-partial-news')).forEach(function (item) {
                item.addEventListener('ajaxSubmit.after', function () {
                    if (typeof AjaxSubmit !== 'undefined') AjaxSubmit.init();
                    if (typeof ChangeSubmit !== 'undefined') ChangeSubmit.init();
                    if (typeof Toggler !== 'undefined') Toggler.init();
                    if (typeof Paginate !== 'undefined') Paginate.init();
                });

                item.addEventListener('paginate.after', function () {
                    if (typeof Toggler !== 'undefined') Toggler.init();
                });
            });
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-cloader-table')).forEach(function (item) {
        item.addEventListener('cloader.after', function () {
            Swipe.init();
            TableSort.init();
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-cloader-media')).forEach(function (item) {
        item.addEventListener('cloader.after', function () {
            // soocial media embed reload - instagram and twitter
            if (typeof window.instgrm !== 'undefined') {
                window.instgrm.Embeds.process();
            }
            if (typeof twttr !== 'undefined') {
                Array.prototype.slice.call(document.getElementsByClassName('js-cloader-item')).forEach(function (item) {
                    if (item.className.indexOf('is-new') !== -1) {
                        twttr.widgets.load(item);
                    }
                });
            }
        });
    });

    Array.prototype.slice.call(document.getElementsByClassName('js-cloader-scroll-to')).forEach(function (item) {
        item.addEventListener('cloader.after', function () {
            var fontA = new FontFaceObserver('Hurme Geometric Sans 2');
            Promise.all([fontA.load()]).then(function () {
                ScrollIntoView.init();
            });
        });
    });

    // todo: temp until safari has fixed the ajax image loading bug (https://github.com/WebKit/WebKit/pull/4228)
    Array.prototype.slice.call(document.getElementsByClassName('js-cloader-game')).forEach(function (item) {
        item.addEventListener('cloader.after', function () {
            item.querySelectorAll('img').forEach(img => {
                img.outerHTML = img.outerHTML;
            });
        });
    });
}

const YawaveLogin = {
    toCheck: document.getElementById('js-yawave-to-check'),
    content: document.getElementById('js-yawave-content'),
    loading: document.getElementById('js-yawave-loading'),
    redirectUrl: document.getElementById('js-yawave-redirect-url'),
    init: function () {
        Array.prototype.slice.call(document.getElementsByClassName('js-yawave-logout')).forEach(YawaveLogin.attachLogoutHandler);
        YawaveLogin.hideContent();
        YawaveLogin.checkLogin().then(isLoggedIn => {
            if (isLoggedIn) {
                document.body.classList.add('is-logged-in');
                YawaveLogin.showContent();
            } else {
                document.body.classList.add('is-logged-out');
                YawaveLogin.redirectToLogin();
            }
            YawaveLogin.showProfile(isLoggedIn);
            return isLoggedIn;
        }).then(isLoggedIn => {
            if (isLoggedIn) {
                YawaveLogin.setUserToken();
                YawaveLogin.showProfileIcon();
            }
        });
    },
    attachLogoutHandler: function (item) {
        item.addEventListener('click', YawaveLogin.logout);
    },
    checkLogin: function () {
        return new Promise((resolve) => {
            window.addEventListener('YawaveSDK.Loaded', () => {
                YawaveSDK.userIsLoggedIn(loggedIn => {
                    resolve(loggedIn);
                });
            });
        });
    },
    logout: function () {
        // delete cookie
        if (typeof Cookie !== 'undefined') {
            Cookie.setCookie('jwt_azure', '', -1, '.zsclions.ch');
            Cookie.setCookie('fe_typo_user', '', -1, 'businessclub.zsclions.ch');
        }
        // redirect to logout url
        const objectURL = new URL(window.location.href);
        const locationURL = objectURL.origin + objectURL.pathname;
        window.location.replace('https://auth2.zsclions.ch/yawave_app/user/logout?redirect_uri=' + locationURL + '&ssoBaseUrl=https://auth2.zsclions.ch/yawave_sso/auth');
    },
    setUserToken: function () {
        YawaveSDK.getUserToken('oidc', function (token) {
            if (token && typeof Cookie !== 'undefined') {
                const azureCookie = YawaveLogin.parseJwt(Cookie.getCookie('jwt_azure'));
                const yawaveToken = YawaveLogin.parseJwt(token);
                if (azureCookie && yawaveToken['exp'] < azureCookie['exp']) {
                    return;
                }
                Cookie.setCookie('jwt_azure', token, 30, '.zsclions.ch');
            }
        });
    },
    parseJwt: function (token) {
        if (token === null) {
            return false;
        }
        let base64Url = token.split('.')[1];
        let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
        let jsonPayload = decodeURIComponent(window.atob(base64).split('').map(function (c) {
            return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
        }).join(''));
        return JSON.parse(jsonPayload);
    },
    redirectToLogin: function () {
        if (YawaveLogin.toCheck !== null && YawaveLogin.toCheck.value === '1' && typeof YawaveLogin.redirectUrl !== 'undefined') {
            window.location.replace(YawaveLogin.redirectUrl.value);
        }
    },
    showProfile: function (state) {
        Array.prototype.slice.call(document.getElementsByClassName('js-yawave-login-button')).forEach(function (item) {
            item.removeAttribute('disabled');
            item.classList.add('is-enabled');
        });
        if (state === true) {
            Array.prototype.slice.call(document.getElementsByClassName('js-yawave-login-icon-default')).forEach(function (item) {
                item.classList.add('hidden');
            });
            Array.prototype.slice.call(document.getElementsByClassName('js-yawave-login-icon-placeholder')).forEach(function (item) {
                item.classList.remove('hidden');
            });
        }
    },
    showProfileIcon: function () {
        YawaveSDK.api('/users/image', {query: {style: '300x300sc'}}, userImageURL => {
            if (userImageURL !== '') {
                Array.prototype.slice.call(document.getElementsByClassName('js-yawave-login-icon-placeholder')).forEach(function (item) {
                    item.classList.add('hidden');
                });
                Array.prototype.slice.call(document.getElementsByClassName('js-yawave-login-icon-profile')).forEach(function (item) {
                    item.setAttribute('src', userImageURL);
                    item.classList.remove('hidden');
                });
            }
        });
    },
    hideContent: function () {
        if (YawaveLogin.toCheck !== null && YawaveLogin.toCheck.value === '1') {
            document.body.classList.add('u-overflow-hidden');
            if (typeof YawaveLogin.content !== 'undefined') {
                YawaveLogin.content.classList.add('hidden');
            }
        }
    },
    showContent: function () {
        if (YawaveLogin.toCheck !== null && YawaveLogin.toCheck.value === '1') {
            document.body.classList.remove('u-overflow-hidden');
            if (typeof YawaveLogin.content !== 'undefined') {
                YawaveLogin.content.classList.remove('hidden');
            }
            if (typeof YawaveLogin.loading !== 'undefined') {
                YawaveLogin.loading.classList.remove('is-loading');
            }
        }
    },
};

YawaveLogin.init();