"use strict";(function(b){var a=function(c,d){return{currentItem:0,gallery:c,galleryTitle:c.find(".photo-gallery-title .content"),galleryCounter:c.find(".photo-gallery-counter"),thumbSlider:c.find(".thumbnails"),thumbs:c.find(".thumbnails .item"),thumbsTemplate:undefined,galleryArea:c.find(".gallery-area"),gallerySelector:c.find(".gallery-selector"),gallerySelectorWrapper:c.find(".gallery-selector .gallery-selector-wrapper"),gallerySelectorTpl:c.find(".gallery-selector [data-template]"),isVertical:c.is('[data-gallery-position="vertical"]'),slides:undefined,templates:c.find("[data-template]",".slide-container"),slideContainer:c.find(".slide-container"),controllers:c.find(".gallery-area [data-controller]"),timeout:c.data("gallery-timeout"),timer:undefined,maxHeightEl:undefined,data:d,enableTimeout:!0,defaultThumb:c.data("default-thumbnail")||"http://placehold.it/135x75",fixedHeight:!1,hasThumbnails:function(){var e=!!this.thumbSlider.length;if(e){e=e&&!!this.data[this.currentGallery||0].media.length;if(!e){this.thumbSlider.empty()}}return e},hasSlides:function(){return!!this.slideContainer.length},hasGallerySelector:function(){return!!this.gallerySelector.length&&this.data.length>1},resizeAfterLoad:function(){var g=this,i=this.activeSlide.find("img, iframe, object, .jwplayer");if(i.length){try{var f=i[0].contentDocument||(i[0].contentWindow&&i[0].contentWindow.document);if(i[0].complete||(f&&f.readyState==="complete")||i.is("object")||i.hasClass("jwplayer")){g.updateMaxHeight()}else{i.on("load",function(){g.updateMaxHeight()})}}catch(h){g.updateMaxHeight()}}},setMaxHeight:function(){if(!this.hasSlides()){return}var e=0,f=this;if(this.fixedHeight){this.slides.each(function(){var g=b(this).outerHeight();if(g>e){e=g;f.maxHeightEl=b(this)}});this.updateMaxHeight()}else{if(this.activeSlide.length){this.maxHeightEl=this.activeSlide;this.resizeAfterLoad()}}},updateMaxHeight:function(){if(!this.maxHeightEl){return}var f=this;this.maxHeightEl.css({height:"auto","min-height":0});var e=this.maxHeightEl.outerHeight();this.slideContainer.css({height:e});this.slides.each(function(){b(this).css({height:e})});if(this.hasGallerySelector()){setTimeout(function(){f.setSelectorSliderWidth();f.slideToCurrentGallery();f.setMaxHeight()},250)}else{setTimeout(function(){f.setMaxHeight()},250)}},setTimeout:function(){if(!this.timeout){return}var e=this;this.clearTimeout();this.timer=setInterval(function(){e.next()},this.timeout)},setSliderWidth:function(i,f,g){if(!g){var h=0;i.each(function(){h+=b(this).outerWidth()});f.css({width:h})}else{var e=0;i.each(function(){e+=b(this).outerHeight(!0)});f.css({height:e})}},clearTimeout:function(){clearInterval(this.timer)},attachGalleryEvents:function(){var f=this;this.gallery.on("gallery:next",function(){f.haveToClear=!1;f.next()}).on("gallery:next-gallery",function(){f.nextGallery()}).on("gallery:prev-gallery",function(){f.prevGallery()}).on("gallery:prev",function(){f.haveToClear=!1;f.prev()}).on("gallery:rebuild",function(){f.buildGallery()}).on("mouseenter",function(){f.resetViewport();if(f.timeout&&f.enableTimeout){f.clearTimeout()}}).on("mouseleave",function(){f.cleanViewport();if(f.timeout&&f.enableTimeout){f.setTimeout()}}).on("click",".thumbnails .item",function(g){g.preventDefault();g.stopPropagation();f.moveTo(b(this).index())}).on("click","[data-controller]",function(g){g.preventDefault();g.stopPropagation();var h=b(this).data("controller");if(h){f.gallery.trigger("gallery:"+h)}}).on("click",".gallery-selector-item",function(g){g.preventDefault();g.stopPropagation();f.loadGallery(b(this).data("gallery-index"))}).on("jwplayer:playing",".jwplayer",function(){f.clearTimeout();f.enableTimeout=!1;f.haveToClear=!0;return!0}).on("jwplayer:stoped",".jwplayer",function(){f.enableTimeout=!0;f.haveToClear=!1;f.setTimeout();f.resetViewport();return!0});if(window.Hammer){var e=new Hammer(this.gallery[0]);e.on("swipeleft",function(){f.prev()}).on("swiperight",function(){f.next()})}},cleanViewport:function(){if(this.haveToClear){this.gallery.addClass("clear-viewport");this.gallery.addClass("clear-viewport-full")}else{this.resetViewport()}},resetViewport:function(){this.gallery.removeClass("clear-viewport");if(!this.haveToClear){this.gallery.removeClass("clear-viewport-full")}},showInMain:function(e){this.mainView.empty().append(this.thumbs[e].clone())},slideTo:function(h,k,l,g){var f=k.filter(":eq("+h+")"),j;if(!g){var e=l.parent().width();j=(e)-(f.position().left+f.outerWidth());if(j<0){l.css({left:j})}else{l.css({left:0})}}else{var i=l.parent().outerHeight();j=(i)-(f.position().top+f.outerHeight(!0));if(j<0){l.css({top:j})}else{l.css({top:0})}}},makeActive:function(e){if(this.hasThumbnails()){this.thumbs.removeClass("active").filter(":eq("+e+")").addClass("active")}if(this.hasSlides()){var f=0;if(this.activeSlide){f=this.activeSlide.outerHeight()}this.activeSlide=this.slides.removeClass("active").filter(":eq("+e+")").addClass("active");if(!this.fixedHeight){this.activeSlide.css({"min-height":f});this.setMaxHeight()}}if(this.hasThumbnails()){this.slideTo(e,this.thumbs,this.thumbSlider)}},next:function(){this.currentItem+=1;if(this.currentItem>=this.slides.length){this.currentItem=0}this.activePlayers.each(function(){var e=b(this).data("jwplayer");if(e){e.stop()}});this.makeActive(this.currentItem)},prev:function(){this.currentItem-=1;if(this.currentItem<0){this.currentItem=this.slides.length-1}this.activePlayers.each(function(){var e=b(this).data("jwplayer");if(e){e.stop()}});this.makeActive(this.currentItem)},nextGallery:function(){this.currentGallery+=1;if(this.currentGallery>=this.data.length){this.currentGallery=0}this.loadGallery(this.currentGallery,!0)},prevGallery:function(){this.currentGallery-=1;if(this.currentGallery<0){this.currentGallery=this.data.length-1}this.loadGallery(this.currentGallery,!0)},moveTo:function(e){this.currentItem=e;this.makeActive(this.currentItem)},parseTemplate:function(f,g){var e=f.replace(/x-src/g,"src").replace('data-template=""',"").replace(/x-srcset/g,"srcset");b.each(g,function(h,i){e=e.replace(new RegExp("\\{\\[\\s*"+h+"\\s*\\]\\}","g"),i)});return e},loadSlides:function(e,g){if(!this.hasSlides()){return}var f=this;this.slideContainer.find("[data-slide]").remove();b.each(g.media,function(){var i=f.parseTemplate(e.templates[this.type],this);var h=b(i);e.slideContainer.append(h)});e.slides=this.slideContainer.children("[data-slide]")},loadThumbs:function(f,h){if(!this.hasThumbnails()){return}var g=this,e=f.thumbSlider;e.empty();b.each(h.media,function(){var i=g.parseTemplate(f.thumbsTemplate,this);e.append(i)});f.thumbs=e.children();if(h.media.length>1){e.show()}else{e.hide()}},loadGalleryTitle:function(e){if(this.galleryTitle.length){this.galleryTitle.text(e.title);this.galleryTitle.parent().attr({href:e.link,target:e.linkTarget})}if(this.galleryCounter.length){this.galleryCounter.text(e.media.length)}},slideToCurrentGallery:function(){this.slideTo(this.currentGallery,this.gallerySelectorWrapper.children(),this.gallerySelectorWrapper,this.isVertical)},loadGallery:function(e,g){if(e===this.currentGallery&&!g){return}var f=this.data[e];this.currentGallery=e;this.currentItem=0;this.loadGalleryTitle(f);if(f.media.length<2){this.controllers.hide()}else{this.controllers.show()}this.loadSlides(this,f);this.loadThumbs(this,f);if(this.hasThumbnails()){this.setSliderWidth(this.thumbs,this.thumbSlider)}this.makeActive(this.currentItem);this.currentItem=0;if(this.slides){this.activePlayers=this.slides.find("[data-player]").mediaPlayer()}},loadTemplate:function(f){var e=b("
"),g;e.append(f);g=e.html();e.empty();return g},loadGallerySelectorTemplate:function(){if(!this.hasGallerySelector()||this.gallerySelectorTplLoaded){if(!this.gallery.is(".hide-gallery-selector")){this.gallery.addClass("hide-gallery-selector")}return}this.gallery.addClass("has-gallery-selector");this.gallerySelectorTpl=this.loadTemplate(this.gallerySelectorTpl);this.gallerySelectorTplLoaded=!0},loadGallerySelectorItems:function(){if(!this.hasGallerySelector()){return}var e=this;this.gallerySelectorWrapper.children().not(".keep").remove();b.each(this.data,function(g){var h=e.parseTemplate(e.gallerySelectorTpl,this);var f=b(e.parseTemplate(h,this.media[0]));f.data("gallery-index",g);e.gallerySelectorWrapper.append(f)})},loadSlideTemplates:function(){if(!this.hasSlides()||this.templatesLoaded){return}var e={},f=this;this.templates.each(function(){var g=b(this).data("type");e[g]=f.loadTemplate(this)});this.templates=e;this.templatesLoaded=!0},loadThumbsTemplate:function(){if(!this.hasThumbnails()||this.thumbTemplateLoaded){return}this.thumbsTemplate=this.loadTemplate(this.thumbs.filter("[data-template]"));this.thumbTemplateLoaded=!0},setSelectorSliderWidth:function(){this.setSliderWidth(this.gallerySelectorWrapper.children(),this.gallerySelectorWrapper,this.isVertical)},buildGallery:function(){this.loadGallerySelectorTemplate();this.loadGallerySelectorItems();if(this.hasGallerySelector()){this.setSelectorSliderWidth()}this.loadSlideTemplates();this.loadThumbsTemplate();this.loadGallery(0)},init:function(){var e=this;if(!this.data.length){this.gallery.hide();return!1}this.buildGallery();b(window).on("resize",function(){e.updateMaxHeight.call(e)});this.attachGalleryEvents()}}};window.loadGallery=function(c){b(c).each(function(){var d=b(this),f=this.id,g=window[f+"Content"];if(!g){d.hide();return}var e=new a(d,g);e.init()})};b(document).ready(function(){window.loadGallery("[data-gallery]")})})(jQuery)