!function(e){if("object"==typeof module&&"object"==typeof module.exports){var t=e(require,exports);void 0!==t&&(module.exports=t)}else"function"==typeof define&&define.amd&&define(["require","exports","page","stApp","angular","cookie-helper"],e)}(function(e,t){var n=e("angular"),s=n.element;return{ExpertsInitialize:function(e,t){function a(t,n){e.expertsData={expert_full:p[t],has_experts:!0},e.live_experts_status="",setTimeout(function(){var e=p[t].HASHTAG;window.location.hash!==e&&(window.location.hash="expert="+e.replace(/^#/,"")),n&&n.call()})}var o=t.get("$http"),r=t.get("$timeout"),l=t.get("$url");e.ques_select=window["page-default-question"];var i;if(e.questionSelect=function(t,n){i=n,window.innerWidth<=640?e.ques_select==n&&(n=!1):e.ques_select||(n=i),r(function(){e.ques_select=n,e.ques_select_scroll=n},100),t&&(t.preventDefault(),window.location.hash="#"+n)},e.questionSelectBad=function(t,s){i=s,r(function(){n.element(t.target.parentNode).toggleClass("content-show"),n.element(t.target).toggleClass("af-icon-down-open"),n.element(t.target).toggleClass("af-icon-up-open"),e.ques_select=s,e.ques_select_scroll=s},100),t&&(t.preventDefault(),window.location.hash="#"+s)},e.all_questions=!1,e.showAllQuestions=function(t){e.all_questions=!0},e.expertsData={experts:[],has_experts:!0},e.back_to_all_experts=!1,e.live_experts_status="",e.fetching_more=!1,e.focus_on_expert=null,s().cssSelect("script#experts-gallery-data").length>0)try{e.expertsData=JSON.parse(s().cssSelect("script#experts-gallery-data").prop("innerHTML"))}catch(e){console.warn("cannot parse experts gallery, could be empty or invalid format")}for(var c=e.expertsData,p={},u=1,d=0;d<c.experts.length;d++){var f=c.experts[d];p[f.EID]=f}e.ExpFull=function(t,s,r,l,i){t&&n.element(t.element).parent().hasClass("loading")||(i&&(e.live_experts_status="Loading answers from "+i),r in p&&"CONTENT"in p[r]?a(r,l):(t&&n.element(t.element).parent().addClass("loading"),o.get("/ajax.php?action=Posts.GetExpertsPosts&ids[]="+r).then(function(e){"data"in e&&"data"in e.data&&e.data.data.length>0&&(p[r]=e.data.data.shift(),a(r,l))})),t&&t.preventDefault())},e.ExpMore=function(t){var n=Math.ceil(c.ids.length/6);u+1>n?u=1:u++;for(var s=6*(u-1),a=c.ids.slice(s,s+6),l=[],i=[],d=0;d<a.length;d++){var f=a[d];f in p?i[d]=p[f]:l.push("ids[]="+f)}e.fetching_more=!0,0==l.length&&i.length>0?(e.expertsData.experts=i,e.fetching_more=!1,e.focus_on_expert=e.expertsData.experts[0].EID.toString(),r(function(){e.focus_on_expert=null},300)):(e.live_experts_status="Loading more experts",o.get("/ajax.php?action=Posts.GetExpertsPosts&"+l.join("&")+"&c=0",{cache:!1}).then(function(t){if(e.live_experts_status="","data"in t&&"data"in t.data&&t.data.data.length>0){for(var n=(i=t.data.data).length,s=0;s<n;s++)i[s].EID in p||(p[i[s].EID]=i[s]);e.expertsData.experts=i,e.fetching_more=!1,e.focus_on_expert=e.expertsData.experts[0].EID.toString(),e.live_experts_status="Loaded "+n+" more expert"+(1!=n?"s":""),r(function(){e.live_experts_status=""},1e3),r(function(){e.focus_on_expert=null},300)}})),t&&t.preventDefault()},e.ExpAll=function(t){e.expertsData={experts:c.experts,expert_intro:c.expert_intro,expert_header:c.expert_header,has_experts:!0,more:c.more},setTimeout(function(){var e=s().cssSelect(".experts-gallery #gallery-1").offset().top-100;window.history&&window.history.pushState?(window.history.scrollRestoration="manual",window.history.pushState({scrollTop:e},document.title,location.href.replace(location.hash,""))):window.location.hash="";var t=s().cssSelect(".experts-gallery .header-part h2");t.trigger("focus"),setTimeout(function(){t.trigger("focus")},100)})},e.expert_scroll=function(e){var t=n.element().cssSelect(".experts-answers.editors-picks");0==t.length&&(t=n.element().cssSelect(".experts-answers")),0!=t.length&&(n.element(document).duScrollToElementAnimated(t,80,300),t.find(".header-part h2").trigger("focus"),setTimeout(function(){t.find(".header-part h2").trigger("focus")}),e.preventDefault())};var x=e.$watch("initialized_cards",function(t){if(t){x();var a=null,o=function(){var t=window.location.hash;if("#ask-the-experts"==t)setTimeout(function(){n.element(document).duScrollToElementAnimated(n.element().cssSelect("#ask-the-experts"),80,300)});else if("#compare"==t)e.cards_scroll(null);else if("#best"==t)e.expert_scroll(null);else if("#faq"==t)e.comqa_scroll(null);else if("#survey"==t)setTimeout(function(){n.element(document).duScrollToElementAnimated(n.element().cssSelect(".experts-answers.survey"),80,300)});else if(t.length>1&&t!==a){if(a=t,0===t.indexOf("#expert=")){t=decodeURIComponent(t.substr(8));var s=c.urls.indexOf(t);s>-1&&e.$applyAsync(function(){e.ExpFull(null,s,c.ids[s],function(){n.element(document).duScrollToElementAnimated(n.element().cssSelect(".experts-gallery #gallery-1"),80,300)})})}}else a=null};setTimeout(function(){s(window).on("hashchange",o),o()})}});e.$on("$url:changed",function(){l.expert&&l.expert&&n.element().cssSelect("section.experts-answers").length>0&&function(){var t=l.expert;e.questionSelect(!1,t)}()})}}});