CDQ.component.Timeline=Class.extend({init:function(n){var t=this;this.settings=this.getSettings(n);this.$timelineWrapper=jQuery(this.settings.timelineWrapper);this.$timeline=jQuery(this.settings.timeline);this.$template=jQuery(this.settings.template);this.$line=this.$timeline.find(".timeline__line");this.animationTimmer=0;this.loadData().success(function(n){t.data=n;t.maxViewport=t.getMaxViewport();t.build();jQuery(t.bind.bind(t))})},getSettings:function(n){return jQuery.extend({},{method:"GET",timeline:"[data-timeline]",item:".timeline__container",visible:"timeline__item--animate",initialized:"timeline--initialized",timelineWrapper:".timeline__wrapper"},n)},bind:function(){this.maxViewport=this.getMaxViewport();jQuery(window).on("resize",this.onResize.bind(this));jQuery(window).on("scroll",this.onScroll.bind(this))},loadData:function(){return jQuery.ajax({url:this.settings.url,method:this.settings.method,dataType:"json"})},getTemplate:function(n){var t='[data-timeline-template="'+n+'"]',i=jQuery(t);return jQuery(i.html())},createItem:function(n){var t=this.getTemplate(n.type),i="",r;return n.type==="text-box"&&(i=t.find("a"),t.find(".teaser__title").text(n.title),t.find("p").text(n.text),n.link?i.attr("href",n.link).text(n.linkText):i.remove()),n.type==="note"&&t.find("p").text(n.text),n.type==="fact"&&(r=t.find(".facts__text-container"),t.find("img").attr("src",n.icon),r.empty(),n.content.forEach(function(n){var t=jQuery.extend({},n);t.html=t.text;delete t.text;delete t.tag;jQuery("<"+n.tag+">",t).appendTo(r)})),n.type==="teaser"&&(t.find(".teaser__title-cover").text(n.title),t.find(".teaser__copy-cover").text(n.text),t.find(".teaser__media").css("background-image","url("+n.img+")")),t},createRow:function(n){var i=this.getTemplate("row"),r=this,t=0,u,f;return u=n.filter(function(n){return n.pos==="left"}),f=n.filter(function(n){return n.pos==="right"}),jQuery.each([u,f],function(n,u){var f=i.find(".timeline__item").eq(t);if(jQuery.isEmptyObject(u))return t--,f.remove();jQuery.isArray(u)?u.map(function(n){r.createItem(n).appendTo(f)}):r.createItem(u).appendTo(f);t++}),i},createNewSection:function(n){var t=this.getTemplate("section");return t.find("time").html(n.date),t},buildProgress:function(){var n=this.$progressBarDate.eq(0);$lastDate=this.$progressBarDate.eq(1);n.text(this.data[0].date);$lastDate.text(this.data[this.data.length-1].date)},buildTimeline:function(){var n=this;jQuery.map(this.data,function(t){return n.createNewSection(t)}).map(function(t,i){var r=n.data[i].itens;return n.createRow(r).appendTo(t),t}).map(function(t){n.$timeline.append(t)});this.$timeline.addClass(n.settings.initialized)},getItemPropsList:function(){return this.$items.map(function(){var n=jQuery(this);return{item:n,top:n.offset().top}})},getDateOffset:function(){return this.$dates.map(function(){return jQuery(this).offset().top})},animate:function(){var n=this,t=0;this.itemPropList.filter(function(t,i){return i.top>n.maxViewport}).each(function(t,i){i.item.removeClass(n.settings.visible)});this.itemPropList.filter(function(t,i){return i.top<=n.maxViewport&&!i.item.hasClass(n.settings.visible)}).each(function(i,r){var u=100*t;setTimeout(function(){r.item.addClass(n.settings.visible)},u);t++})},doAnimation:function(){clearTimeout(this.animationTimmer);this.animationTimmer=setTimeout(this.animate.bind(this),50)},getMaxViewport:function(){return jQuery(window).scrollTop()+jQuery(window).height()},animateLine:function(){jQuery(".timeline__line").each(function(){var n=jQuery(this),t=n.parents(".timeline__container").height();n.animate({height:t-50},800)})},animateProgressBar:function(){var i=jQuery(".timeline__progress-bar"),n=jQuery(window).scrollTop(),u=jQuery(window).height()/2,r=this.$timeline.height(),t=this.$timeline.offset().top;return n<t||n>t+r-u?i.removeClass("timeline--animate-right").addClass("hide"):(n>=t||n<t+r&&t>=n)&&i.addClass("timeline--animate-right").removeClass("hide"),i.css("top",top)},getTimelineDateProp:function(){return this.$timeline.find(".timeline__time").map(function(){var n=jQuery(this),t=n.text(),i=n.parent().offset().top;return{$e:n,date:t,offsetTop:i}}).toArray()},updateCurrentDatesActive:function(){var t=jQuery(window).scrollTop(),i=this,r=this.dates.map(function(n){if(t>=n.offsetTop)return n}).filter(function(n){return n}).map(function(n){return n.date}),n=i.$progressBarDate.map(function(){var n=jQuery(this);return{$element:n,date:n.text()}}).toArray();n.forEach(function(n){return n.$element.removeClass("active")});n.filter(function(n){return r.indexOf(n.date)>-1}).forEach(function(n){n.$element.addClass("active")})},build:function(){var n=this;n.buildTimeline();n.$progressBarDate=this.$timelineWrapper.find(".timeline__progress-bar-text");n.buildProgress();n.animateLine();setTimeout(function(){n.$items=n.$timeline.find(".timeline__item");n.itemPropList=n.getItemPropsList();n.dates=n.getTimelineDateProp();n.updateCurrentDatesActive();n.$progressBarDate.first().addClass("active");n.doAnimation()},300);new CDQ.component.ProgressBar},onScroll:function(){this.maxViewport=this.getMaxViewport();this.animateProgressBar();this.updateCurrentDatesActive();this.doAnimation()},onResize:function(){this.maxViewport=this.getMaxViewport();this.itemPropList=this.getItemPropsList();this.dates=this.getTimelineDateProp();this.animateLine();this.doAnimation();this.$progressBarDate.first().addClass("active");this.updateCurrentDatesActive()}})