var VM=VM||{};VM.sw_version=12;VM.Widgets={wordCount:0,noinject:!1,injects:[],container:null,init:function(){this.initProperties();this.detailsInjects();this.categoryInjects()},initProperties:function(){this.container===null&&(this.container=document.getElementById("details-body"),this.container&&(this.noinject=this.container.classList.contains("noinject"),this.wordCount=parseInt(this.container.getAttribute("data-words"),10)))},detailsInjects:function(){if(this.container){var n=document.querySelectorAll("#details-body > p");document.querySelectorAll("aside .widget-inject").forEach(function(t){VM.Widgets.inject(t,n)})}},categoryInjects:function(){if(!this.container&&(this.container=document.getElementById("category-items"),this.container)){var n=this.container.children;document.querySelectorAll("section .widget-inject").forEach(function(t){VM.Widgets.inject(t,n)})}},inject:function(n,t,i){var u,e,o,h;if(!t||t.length===0||n.classList.contains("widget-injected")||(u=VM.Widgets,e=parseInt(n.getAttribute("data-min")||0,10),e>0&&u.wordCount>0&&e>u.wordCount)||u.noinject&&!n.classList.contains("widget-inject-override"))return!0;var s=parseInt(n.getAttribute("data-per"),10)/100,c=Math.max(Math.round(s*t.length)-1,0),r=n.cloneNode(!0),f=document.createElement("div");return f.classList.add("widget","injected"),f.setAttribute("data-id",n.getAttribute("data-id")),r.classList.add("widget-injected"),n.replaceWith(f),r.data_placeholder=f,s===1?(o=document.getElementById("widget-inject-100"),o?o.appendChild(r):u.container.appendChild(r)):(h=t[c],h.insertAdjacentElement("afterend",r)),u.injects.push(r),f.data_injected=r,typeof i=="function"?i(r):void 0}};VM.Slots={requestedSlotKeys:[],hasHeaderBidding:!1,outOfPage:null,init:function(){typeof googletag!="undefined"&&(this.hasHeaderBidding=document.body.classList.contains("has-hb"),this.loadSlots(),googletag.cmd.push(function(){googletag.pubads().addEventListener("slotRenderEnded",function(n){var i=document.getElementById(n.slot.getSlotElementId()),t;i&&(t=i.parentNode,n.isEmpty?t.classList.add("slot-is-empty"):(t.classList.add("slot-show"),t.classList.contains("slot-alert")?(document.body.classList.add("has-slot-alert"),i.querySelector("iframe").height="28"):t.classList.contains("slot-leaderboard")?VM.Scroll.initLeaderboard(i):t.classList.contains("slot-footer")&&VM.Slots.processFooter(t)),t.classList.contains("slot-widget")&&VM.Slots.processWidget(t,n.isEmpty,n.size))});googletag.pubads().addEventListener("impressionViewable",function(n){document.getElementById(n.slot.getSlotElementId()).parentNode.classList.add("slot-viewed")});googletag.pubads().addEventListener("slotVisibilityChanged",function(n){n.slot.getOutOfPage()&&VM.Slots.outOfPage==="INTERSTITIAL"&&window.setTimeout(function(){googletag.destroySlots([n.slot])},15e3)})}))},processWidget:function(n,t,i){var r=n.parentNode;t?r.classList.contains("widget-inject")&&r.classList.remove("widget-injected"):i[0]===0&&r.classList.contains("widget-inject")&&r.classList.add("widget-dfp-fluid")},processFooter:function(n){n.classList.add("slot-fixed");var t=document.createElement("div");t.classList.add("slot-close");t.setAttribute("aria-label","close");t.innerHTML="&times;";n.appendChild(t);t.addEventListener("click",function(){n.parentNode.removeChild(n)})},loadSlots:function(){if(!document.body.classList.contains("noads")&&googletag){var n=this;document.querySelectorAll(".gam").forEach(function(t){n.loadSlot(t)});googletag.cmd.push(function(){googletag.enableServices();n.refreshSlots(VM.slots)})}},loadSlot:function(n,t){if(!n.classList.contains("widget-inject")||n.classList.contains("widget-injected")){var r=n.classList.contains("widget"),i=null;i=n.hasAttribute("data-dim")?n.getAttribute("data-dim"):window.innerWidth>767?window.innerWidth>991&&(r||window.innerWidth>1049)?n.getAttribute("data-dim-d"):n.getAttribute("data-dim-t"):n.getAttribute("data-dim-m");i?(n.setAttribute("data-size",i),n.innerHTML=r?'<div class="slot slot-widget"><span id="'+this.getSlotId(n)+'"><\/span><\/div>':'<span id="'+this.getSlotId(n)+'"><\/span>',this.hasHeaderBidding&&n.getAttribute("data-lazy")==="true"?n.classList.add("lazyad"):this.buildSlotFromElement(n,function(n){typeof t=="function"?t(n):VM.slots.push(n)})):n.removeAttribute("style")}},buildSlotFromElement:function(n,t){var u=this,i={path:n.getAttribute("data-path"),slotid:this.getSlotId(n),mapping:n.getAttribute("data-mapping"),size:n.getAttribute("data-size").replace(/'/g,'"'),targeting:n.getAttribute("data-targeting")||"[]"};try{i.size=JSON.parse(i.size)}catch(r){console.error("Error parsing props.size",i.size,r);return}try{i.targeting=JSON.parse(i.targeting)}catch(r){console.error("Error parsing props.targeting",i.targeting,r);return}googletag.cmd.push(function(){var r,e,f;if(n.hasAttribute("data-oop"))if(e=n.getAttribute("data-oop"),r=googletag.defineOutOfPageSlot(i.path,e==="CUSTOM_INTERSTITIAL"?i.slotid:googletag.enums.OutOfPageFormat[e]),r)r.addService(googletag.pubads()),u.outOfPage=e;else return;else r=googletag.defineSlot(i.path,i.size,i.slotid).addService(googletag.pubads()),i.mapping&&i.mapping!=="null"&&r.defineSizeMapping(window[i.mapping]);if(i.targeting&&i.targeting.length>0)for(f=0;f<i.targeting.length;f++)r.setTargeting(i.targeting[f].Key,i.targeting[f].Values);t(r)})},getSlotId:function(n){return(n.classList.contains("widget")?"slot_w_":"slot_")+n.getAttribute("data-id")},refreshSlots:function(n){n.length&&(this.hasHeaderBidding?this.requestBids(n):googletag.pubads().refresh(n,{changeCorrelator:!1}))},requestBids:function(n){pbjs.que.push(function(){pbjs.rp.requestBids({callback:VM.Slots.callAdserver,gptSlotObjects:n})});setTimeout(function(){VM.Slots.callAdserver(n)},3500)},callAdserver:function(n){for(var i=n.map(function(n){return n.getSlotElementId()}).join("_"),t=0;t<VM.Slots.requestedSlotKeys.length;t++)if(VM.Slots.requestedSlotKeys[t]===i)return;VM.Slots.requestedSlotKeys.push(i);googletag.pubads().refresh(n)}};VM.Me={init:function(){var n=new XMLHttpRequest;n.addEventListener("load",function(){this.status===200?VM.Me.load(JSON.parse(this.responseText)):VM.Me.load({id:0})});n.open("POST","/account/me");n.send()},load:function(n){this.user=n;this.setTargeting();this.setLoggedIn();this.updateAntiforgery();this.removeBodyClasses()},user:null,getUser:function(n){var t=0,i=window.setInterval(function(){return VM.Me.user?(window.clearInterval(i),n(VM.Me.user)):(t++,t===20?(window.clearInterval(i),n({id:0})):void 0)},150)},setTargeting:function(){var n=this;typeof googletag!="undefined"&&googletag.cmd.push(function(){if(window.URLSearchParams!=="undefined"){var t=new URLSearchParams(window.location.search);t.forEach(function(n,t){var i=t.split("_");i.length===2&&i[0]==="utm"&&googletag.pubads().setTargeting(i[1],n)})}googletag.pubads().setTargeting("LoggedIn",n.toBoolString(n.user.id!==0)).setTargeting("User",n.user.id.toString()).setTargeting("Member",n.toBoolString(n.user.member)).setTargeting("Subscriber",n.toBoolString(n.user.subscriber))})},setLoggedIn:function(){if(this.user.id!==0){var t=document.getElementById("welcome"),n=document.querySelector("header .avatar");t&&(t.parentNode.setAttribute("aria-controls","hd-account"),t.setAttribute("data-user",this.user.id),t.innerHTML=(t.getAttribute("data-default")||"").replace("{0}",this.user.username)+' <span class="caret" aria-hidden="true"><\/span>');n&&(n.setAttribute("data-initials",this.user.initials),this.user.photo&&this.user.photo.length>0?(n.innerHTML='<img alt="" class="avatar-img" src="'+this.user.photo+'">',n.className="avatar-sm avatar"):(n.innerHTML=this.user.initials,n.className="theme-bg avatar-sm avatar"))}},removeBodyClasses:function(){this.user.cms&&(document.body.classList.remove("staged"),document.body.classList.remove("noads"))},updateAntiforgery:function(n){var f=document.createElement("div"),t,e,r,u;if(f.innerHTML=n||this.user.af,t=f.firstChild,t)for(e=t.getAttribute("name"),r=document.querySelectorAll('form[method="post"]'),i=0;i<r.length;++i)u=r[i].querySelector('input[name="'+e+'"]'),u?u.value=t.value:r[i].appendChild(t.cloneNode())},toBoolString:function(n){return n?"True":"False"}};VM.Scroll={bodyEl:null,fixedEl:null,scrollPos:0,lastWidgetOffset:0,headerOffset:60,depthCache:[],depthCallback:null,maxDepth:0,maxHeight:0,leaderboard:{el:null,pos:null,timer:null,maxScrollPos:null},details:{title:"",bodyEl:null,widgetsEl:null},init:function(){document.body.classList.contains("staged")||(this.bodyEl=document.getElementById("body"),this.scrollPos=window.pageYOffset,this.fixedEl=document.querySelector(".widget-fixed-override"),window.addEventListener("scroll",this.debounce(this.onScroll,30)))},initStory:function(){this.details.bodyEl=document.getElementById("details-body");this.details.widgetsEl=document.getElementById("details-widgets");this.details.title=this.details.bodyEl.parentNode.getAttribute("data-title")},initLeaderboard:function(n){this.leaderboard.el=n;this.leaderboard.pos=this.headerOffset+this.leaderboard.el.offsetTop;this.leaderboard.maxScrollPos=Math.max(window.innerHeight/2,500);this.leaderboard.alertDetected=document.body.classList.contains("has-slot-alert");document.body.classList.add("has-slot-leaderboard")},debounce:function(n,t,i){var r;return function(){var u=this,f=arguments,e=function(){r=null;i||n.apply(u,f)},o=i&&!r;clearTimeout(r);r=setTimeout(e,t);o&&n.apply(u,f)}},calculateDepthMarks:function(n){return{"25%":parseInt(n*.25,10),"50%":parseInt(n*.5,10),"75%":parseInt(n*.75,10),"100%":n-5}},checkDepthMarks:function(n,t,i){var r,u,f,e;this.maxDepth=Math.max(this.maxDepth,t);this.maxHeight=Math.max(this.maxHeight,i);r=this;for(u in n)f=n[u],r.depthCache.indexOf(u)===-1&&t>=f&&(r.depthCache.push(u),typeof r.depthCallback=="function"&&(e=parseInt(key,10),r.depthCallback(e)))},onScroll:function(){var n=VM.Scroll,t=window.pageYOffset;if(n.details.bodyEl){var f=n.details.bodyEl.parentNode.offsetHeight,u=f-(n.details.widgetsEl?n.details.widgetsEl.offsetHeight:0),e=t-(n.details.bodyEl.parentNode.getBoundingClientRect().top+window.pageYOffset),o=e+window.innerHeight,s=n.calculateDepthMarks(u);n.checkDepthMarks(s,o,u)}if(document.body.classList.add("scrolled"),document.body.classList.toggle("scroll",t>0),document.body.classList.toggle("scrollup",t<n.scrollPos),n.scrollPos=t,n.fixedEl){var i=n.bodyEl.offsetHeight,r=n.fixedEl.offsetHeight,h=i-r;n.fixedEl.classList.contains("widget-fixed")||n.lastWidgetOffset!==0||(n.lastWidgetOffset=n.fixedEl.getBoundingClientRect().top+window.pageYOffset-n.headerOffset);t<=n.lastWidgetOffset||t+r>i?(n.fixedEl.classList.remove("widget-fixed"),t+r>i&&n.fixedEl.setAttribute("style","position:absolute;top:"+h+"px;max-width:300px;margin:0")):(n.fixedEl.classList.add("widget-fixed"),n.fixedEl.removeAttribute("style"))}!document.body.classList.contains("has-slot-leaderboard")||document.body.classList.contains("scrollup")||n.leaderboard.el.parentNode.classList.contains("slot-is-empty")||n.leaderboard.el.parentNode.classList.contains("slot-viewed")||(clearTimeout(n.leaderboard.timer),n.leaderboard.timer=setTimeout(function(){n.hideLeaderboard()},3e3),n.scrollPos<n.leaderboard.maxScrollPos?n.scrollPos>n.leaderboard.pos?n.leaderboard.el.classList.add("slot-fixed"):n.hideLeaderboard():n.hideLeaderboard())},hideLeaderboard:function(){var t,i,n;this.leaderboard.el.classList.contains("slot-fixed")&&(t=window.scrollY-this.leaderboard.pos+(!this.leaderboard.alertDetected&&document.body.classList.contains("has-slot-alert")?28:0),i=Math.min(t*3,500),this.leaderboard.el.style.transition="transform "+i+"ms ease",this.leaderboard.el.style.transform="translateY(-"+t+"px)",n=this,window.setTimeout(function(){n.leaderboard.el.classList.remove("slot-fixed");n.leaderboard.el.style.transition="none";n.leaderboard.el.style.transform="translateY(0)";document.body.classList.remove("has-slot-leaderboard")},i))}};VM.Widgets.init();VM.Slots.init();VM.Me.init();VM.Scroll.init()