(function(b){b.carousel=function(e,d){var f=this,g;f.carousel=b(e);f.blocks=b("> .block",f.carousel);f.currentIndex=0;f.mousePosition;f.interacted=false;f.tracker=false;f.trackingData="";if(f.carousel.hasClass("trackevent")&&f.carousel.data("trackingdata")&&typeof Tracker!=="undefined"){f.tracker=true;f.trackingData=f.carousel.data("trackingdata")}var c=f.carousel.parent();if(c.hasClass("line-inner")){c=c.parent()}f.viewport={el:c,visible:c.width()/(f.blocks.width()+d.blockMargin),pagination:c};f.carousel.data("Carousel",f);f.init=function(){f.carousel.css({"-webkit-user-select":"none","-khtml-user-select":"none","-moz-user-select":"none","-o-user-select":"none","user-select":"none"});if(f.carousel.hasClass("pagination")||d.pagination){f.pagination.init()}if(f.carousel.hasClass("draggable")||d.draggable){f.draggable.init()}if(f.carousel.hasClass("slideshow")||d.slideshow){f.slideshow.init()}if(f.carousel.hasClass("instructions")||d.slideshow){f.instructions.init()}if(f.carousel.hasClass("dynamic")||d.dynamic){f.dynamic.init()}if(f.carousel.hasClass("offset-start")||d.offsetStart){var h=0;if(b(f.blocks).closest(".active").length>0){h=b(f.blocks).closest(".active").index()}f.offset.init(h)}};f.offset={init:function(i){var h=-((i*(f.blocks.width()+d.blockMargin)));if(i==f.blocks.length-1||(f.currentIndex>i&&i<0)){h=h+(f.viewport.el.width()-f.blocks.width())}b(".blog .fixed-block").css({left:"auto",position:"relative"});f.carousel.css({left:h},300,function(){if(f.dynamic.status){f.dynamic.load(i)}if(b(".blog .active .fixed-block").length>0){b(".blog .active .fixed-block").css({top:0+MENU_HEIGHT,left:b(".blog .fixed-block").prev().width()+(GRID_MARGIN*2),position:"fixed"})}});f.pagination.update(i);f.currentIndex=i}};f.dynamic={status:false,menu:"",init:function(){f.dynamic.status=true;f.dynamic.menu=b(".custom-pagination li");f.dynamic.size();var h=b(f.blocks).closest(".active").index();f.dynamic.jumpTo(h);Blog.update(Math.floor(h/7))},load:function(i){if(b(f.blocks[i]).hasClass("active")){return}b("> .block",f.carousel).removeClass("active");var h=b("a",f.dynamic.menu.eq(i)).attr("href");PageNavigation.internal=true;document.location.hash="!"+PageNavigation.stripURL(h);b.get(h,function(j){f.dynamic.add(i,j);Blog.update(Math.floor(i/7))})},size:function(){Grid.refresh();var h=0,i=b("> .block.active",f.carousel);i.each(function(){b(".count > *",this).each(function(){var j=b(this).css("margin-top");var k=b(this).css("margin-bottom");if(j.indexOf("%")>-1||k.indexOf("%")>-1){h+=b(this).height()+(b(this).parent().width()*parseInt(j,10)/100)+(b(this).parent().width()*parseInt(k,10)/100)}else{h+=b(this).height()+parseInt(j,10)+parseInt(k,10)}})});if(h<b(window).height()-103){h=b(window).height()-103}f.carousel.parent().height(h);f.carousel.height(h);b(".blog .fixed-block").height(b(window).height()-103);Grid.refresh()},add:function(i,k){var j=b(f.blocks[i]),h=b(".blog-post.active",b(k));Lazyloader.init(h);j.replaceWith(h);TextHelper.fitTextStoreSize();TextHelper.fitText(j);j.addClass("active");f.dynamic.size();f.dynamic.cleanup();Lazyloader.targetUpdate(h);f.blocks=b("> .block",f.carousel)},cleanup:function(){b("> .block",b(f.blocks).not(".active")).empty()},jumpTo:function(h){f.dynamic.animateTo(h,0)},animateTo:function(i,j){b(".blog .fixed-block").css({position:"relative"});if(!j){j=300}var h=-((i*(f.blocks.width()+d.blockMargin)));if(i==f.blocks.length-1||(f.currentIndex>i&&i<0)){h=h+(f.viewport.el.width()-f.blocks.width())}f.carousel.stop(true,true).animate({left:h},300,function(){b(".blog .active .fixed-block").css({top:0+MENU_HEIGHT,left:b(".blog .fixed-block").prev().width()+(GRID_MARGIN*2),position:"fixed"})});f.currentIndex=i},reset:function(){f.currentIndex=0;f.carousel.css({left:0});f.blocks=b("> .block",f.carousel);var h=f.carousel.parent();if(h.hasClass("line-inner")){h=h.parent()}f.viewport={el:h,visible:h.width()/(f.blocks.width()+d.blockMargin),pagination:h};f.dynamic.menu=b(".custom-pagination li");f.dynamic.size()}};f.instructions={el:"",active:false,init:function(){if(!f.carousel.hasClass("instructions")){return}f.instructions.active=true;var h=document.createElement("div");h.className="mouse-drag";f.viewport.el.append(h);f.instructions.el=b(h);f.instructions.el.css({opacity:0});f.viewport.el.mouseover(function(){Animator.stop(f.instructions.el);f.instructions.show()});f.viewport.el.mouseleave(function(){f.instructions.hide()});f.instructions.el.mouseover(function(){f.instructions.remove()});f.instructions.el.stop(true).animate({opacity:1},300,function(){Animator.animate(f.instructions.el,50,53);setTimeout(function(){f.instructions.el.trigger("mouseleave")},3000)})},show:function(){f.instructions.el.stop(true).animate({opacity:1},300,function(){Animator.animate(f.instructions.el,50,53)})},hide:function(){f.instructions.el.stop(true).animate({opacity:0},300,function(){Animator.stop(f.instructions.el)})},remove:function(){f.viewport.el.unbind("mouseleave");f.viewport.el.unbind("mouseover");Animator.stop(f.instructions.el);f.instructions.el.fadeOut(50,function(){b(this).remove()});f.instructions.active=false}};f.animate={to:function(i){var h=-((i*(f.blocks.width()+d.blockMargin)));if(i==f.blocks.length-1||(f.currentIndex>i&&i<0)){h=h+(f.viewport.el.width()-f.blocks.width())}b(".blog .fixed-block").css({left:"auto",position:"relative"});f.carousel.stop(true).animate({left:h},300,function(){if(f.dynamic.status){f.dynamic.load(i)}if(b(".blog .active .fixed-block").length>0){b(".blog .active .fixed-block").css({top:0+MENU_HEIGHT,left:b(".blog .fixed-block").prev().width()+(GRID_MARGIN*2),position:"fixed"})}});f.currentIndex=i;f.carousel.addClass("stop-dragging")}};f.slideshow={currentPosition:0,interval:0,startTimeout:0,init:function(){if(!f.carousel.hasClass("slideshow")){return}f.slideshow.interval=setInterval(function(){f.slideshow.next()},5000)},next:function(){var h=++f.slideshow.currentPosition;if(h==f.blocks.length-1){f.slideshow.currentPosition=-1}f.animate.to(h);f.pagination.update(h)},stop:function(){if(!f.carousel.hasClass("slideshow")){return}clearTimeout(f.slideshow.startTimeout);clearInterval(f.slideshow.interval);f.slideshow.startTimeout=setTimeout(function(){f.slideshow.currentPosition=-1;f.slideshow.init()},5000)},destroy:function(){if(!f.carousel.hasClass("slideshow")){return}clearTimeout(f.slideshow.startTimeout);clearInterval(f.slideshow.interval)}};f.pagination={init:function(){var j=document.createElement("ul");j.className="pagination";for(var l=0;l<f.blocks.length;l++){var m=document.createElement("li");m.appendChild(document.createTextNode("\u2022"));j.appendChild(m)}if(f.carousel.hasClass("pagination-in-line")){if(f.viewport.el.hasClass("line")){f.viewport.pagination=b(".block",f.viewport.el.first().next())}else{f.viewport.pagination=b(".block",f.viewport.el.parents(".line").first().next())}}f.viewport.pagination.append(j);f.pagination.update(0);var k=b("> ul.pagination",f.viewport.pagination).first();b("li",k).click(function(){f.slideshow.stop();b("li",k).removeClass("active");b(this).addClass("active");if(f.tracker){Tracker.trackEvent(f.trackingData+"Nav")}f.animate.to(b(this).index())});if(!f.carousel.hasClass("pagination-positioned")){var h=0;b("li",k).each(function(){h+=b(this).width()});b(j).css({marginLeft:-(b(j).width()/2)})}},update:function(h){var i=b("> ul.pagination",f.viewport.pagination).first();b("li",i).removeClass("active");b("li",i).eq(h).addClass("active")}};f.draggable={position:"",init:function(){var i=document.createElement("div");i.className="draghand no-count";f.viewport.el.append(i);Animator.animate(b(i),60,28);if(d.isMobile){var h=Math.round(-f.carousel.position().left/parseInt(f.blocks.width()));f.carousel.swipe({swipeLeft:function(){if(f.instructions.active){f.instructions.remove()}f.slideshow.stop();h=f.currentIndex;h++;if(h>f.blocks.length-Math.round(f.viewport.visible)){h=f.currentIndex}f.animate.to(h);f.pagination.update(h)},swipeRight:function(){if(f.instructions.active){f.instructions.remove()}f.slideshow.stop();h=f.currentIndex;h--;if(h<0){h=0}f.animate.to(h);f.pagination.update(h)}})}else{f.carousel.draggable({axis:"x",helper:function(){return b("<div></div>").css("opacity",0)},start:function(j,k){if(f.instructions.active){f.instructions.remove()}f.mousePosition=j.pageX;b(".fixed-block",f.blocks).css({left:"auto",top:SCROLL_TOP,position:"relative"});if(f.tracker){Tracker.trackEvent(f.trackingData+"Drag")}},drag:function(j,k){f.carousel.stop(true);f.draggable.position=k.helper.position();if(f.viewport.visible==f.blocks.length){return}if(f.boundaries.end(f.draggable.position.left)){f.animate.to(f.blocks.length-1);return}if(f.boundaries.start(f.draggable.position.left)){f.animate.to(0);return}f.carousel.css({left:f.draggable.position.left})},stop:function(k,l){if(f.boundaries.start(f.draggable.position.left)||f.boundaries.end(f.carousel.position().left)){return}var j;if(Math.abs(f.mousePosition-k.pageX)<100){j=Math.round(-f.carousel.position().left/parseInt(f.blocks.width()))}if(f.mousePosition>k.pageX){j=Math.ceil(-f.carousel.position().left/parseInt(f.blocks.width()))}if(f.mousePosition<k.pageX){j=Math.floor(-f.carousel.position().left/parseInt(f.blocks.width()))}if(j<0||j>f.blocks.length-Math.round(f.viewport.visible)){j=f.currentIndex}if(f.carousel.hasClass("snappable")||d.snappable){f.animate.to(j)}f.slideshow.stop();f.pagination.update(j)}})}}};f.boundaries={start:function(h){if(h>60){return true}return false},end:function(h){if(h<-(f.carousel.width()-f.viewport.el.width())-60){return true}return false}};f.update=function(){if(f.carousel.hasClass("pagination")||d.pagination){var h=Math.round(-f.carousel.position().left/parseInt(f.blocks.width()));f.pagination.update(h)}}};var a={init:function(c){return this.each(function(){c=b.extend(b.carousel.defaults,c);carousel=new b.carousel(b(this),c);carousel.init()})},update:function(){return this.each(function(){carousel=b(this).data("Carousel");if(carousel){carousel.update()}})},destroy:function(){return this.each(function(){carousel=b(this).data("Carousel");if(carousel){carousel.slideshow.destroy()}})},externalNavigation:function(c){return this.each(function(){carousel=b(this).data("Carousel");if(carousel){carousel.animate.to(c)}})},reset:function(){return this.each(function(){carousel=b(this).data("Carousel");if(carousel){carousel.dynamic.reset()}})}};b.carousel.defaults={blockMargin:10,offsetStart:false,snappable:false,draggable:false,scrollable:false,pagination:false,slideshow:false,isMobile:false};b.fn.carousel=function(c){if(a[c]){return a[c].apply(this,Array.prototype.slice.call(arguments,1))}else{if(typeof c==="object"||!c){return a.init.apply(this,arguments)}else{b.error("Method "+c+" does not exist on jQuery.tooltip")}}}})(jQuery);
