(function(){"use strict";var n,t;n=jQuery;t=function(t,i){var f,r,u;return this.options=n.extend({title:null,footer:null,remote:null},n.fn.ekkoLightbox.defaults,i||{}),this.$element=n(t),f="",this.modal_id=this.options.modal_id?this.options.modal_id:"ekkoLightbox-"+Math.floor(Math.random()*1e3+1),u='<div class="modal-header"'+(this.options.title||this.options.always_show_close?"":' style="display:none"')+'><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;<\/button><h4 class="modal-title">'+(this.options.title||"&nbsp;")+"<\/h4><\/div>",r='<div class="modal-footer"'+(this.options.footer?"":' style="display:none"')+">"+this.options.footer+"<\/div>",n(document.body).append('<div id="'+this.modal_id+'" class="ekko-lightbox modal fade" tabindex="-1"><div class="modal-dialog"><div class="modal-content">'+u+'<div class="modal-body"><div class="ekko-lightbox-container"><div><\/div><\/div><\/div>'+r+"<\/div><\/div><\/div>"),this.modal=n("#"+this.modal_id),this.modal_dialog=this.modal.find(".modal-dialog").first(),this.modal_content=this.modal.find(".modal-content").first(),this.modal_body=this.modal.find(".modal-body").first(),this.modal_header=this.modal.find(".modal-header").first(),this.modal_footer=this.modal.find(".modal-footer").first(),this.lightbox_container=this.modal_body.find(".ekko-lightbox-container").first(),this.lightbox_body=this.lightbox_container.find("> div:first-child").first(),this.showLoading(),this.modal_arrows=null,this.border={top:parseFloat(this.modal_dialog.css("border-top-width"))+parseFloat(this.modal_content.css("border-top-width"))+parseFloat(this.modal_body.css("border-top-width")),right:parseFloat(this.modal_dialog.css("border-right-width"))+parseFloat(this.modal_content.css("border-right-width"))+parseFloat(this.modal_body.css("border-right-width")),bottom:parseFloat(this.modal_dialog.css("border-bottom-width"))+parseFloat(this.modal_content.css("border-bottom-width"))+parseFloat(this.modal_body.css("border-bottom-width")),left:parseFloat(this.modal_dialog.css("border-left-width"))+parseFloat(this.modal_content.css("border-left-width"))+parseFloat(this.modal_body.css("border-left-width"))},this.padding={top:parseFloat(this.modal_dialog.css("padding-top"))+parseFloat(this.modal_content.css("padding-top"))+parseFloat(this.modal_body.css("padding-top")),right:parseFloat(this.modal_dialog.css("padding-right"))+parseFloat(this.modal_content.css("padding-right"))+parseFloat(this.modal_body.css("padding-right")),bottom:parseFloat(this.modal_dialog.css("padding-bottom"))+parseFloat(this.modal_content.css("padding-bottom"))+parseFloat(this.modal_body.css("padding-bottom")),left:parseFloat(this.modal_dialog.css("padding-left"))+parseFloat(this.modal_content.css("padding-left"))+parseFloat(this.modal_body.css("padding-left"))},this.modal.on("show.bs.modal",this.options.onShow.bind(this)).on("shown.bs.modal",function(n){return function(){return n.modal_shown(),n.options.onShown.call(n)}}(this)).on("hide.bs.modal",this.options.onHide.bind(this)).on("hidden.bs.modal",function(t){return function(){return t.gallery&&n(document).off("keydown.ekkoLightbox"),t.modal.remove(),t.options.onHidden.call(t)}}(this)).modal("show",i),this.modal};t.prototype={modal_shown:function(){var t;if(this.options.remote){if(this.gallery=this.$element.data("gallery"),this.gallery){this.gallery_items=this.options.gallery_parent_selector==="document.body"||this.options.gallery_parent_selector===""?n(document.body).find('*[data-gallery="'+this.gallery+'"]'):this.$element.parents(this.options.gallery_parent_selector).first().find('*[data-gallery="'+this.gallery+'"]');this.gallery_index=this.gallery_items.index(this.$element);n(document).on("keydown.ekkoLightbox",this.navigate.bind(this));if(this.options.directional_arrows&&this.gallery_items.length>1){this.lightbox_container.append('<div class="ekko-lightbox-nav-overlay"><a href="#" class="'+this.strip_stops(this.options.left_arrow_class)+'"><\/a><a href="#" class="'+this.strip_stops(this.options.right_arrow_class)+'"><\/a><\/div>');this.modal_arrows=this.lightbox_container.find("div.ekko-lightbox-nav-overlay").first();this.lightbox_container.find("a"+this.strip_spaces(this.options.left_arrow_class)).on("click",function(n){return function(t){return t.preventDefault(),n.navigate_left()}}(this));this.lightbox_container.find("a"+this.strip_spaces(this.options.right_arrow_class)).on("click",function(n){return function(t){return t.preventDefault(),n.navigate_right()}}(this))}}return this.options.type?this.options.type==="image"?this.preloadImage(this.options.remote,!0):this.options.type==="youtube"&&(t=this.getYoutubeId(this.options.remote))?this.showYoutubeVideo(t):this.options.type==="vimeo"?this.showVimeoVideo(this.options.remote):this.options.type==="instagram"?this.showInstagramVideo(this.options.remote):this.options.type==="url"?this.loadRemoteContent(this.options.remote):this.options.type==="video"?this.showVideoIframe(this.options.remote):this.error('Could not detect remote target type. Force the type using data-type="image|youtube|vimeo|instagram|url|video"'):this.detectRemoteType(this.options.remote)}return this.error("No remote target given")},strip_stops:function(n){return n.replace(/\./g,"")},strip_spaces:function(n){return n.replace(/\s/g,"")},isImage:function(n){return n.match(/(^data:image\/.*,)|(\.(jp(e|g|eg)|gif|png|bmp|webp|svg)((\?|#).*)?$)/i)},isSwf:function(n){return n.match(/\.(swf)((\?|#).*)?$/i)},getYoutubeId:function(n){var t;return t=n.match(/^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/),t&&t[2].length===11?t[2]:!1},getVimeoId:function(n){return n.indexOf("vimeo")>0?n:!1},getInstagramId:function(n){return n.indexOf("instagram")>0?n:!1},navigate:function(n){if(n=n||window.event,n.keyCode===39||n.keyCode===37){if(n.keyCode===39)return this.navigate_right();if(n.keyCode===37)return this.navigate_left()}},navigateTo:function(t){var r,i;return t<0||t>this.gallery_items.length-1?this:(this.showLoading(),this.gallery_index=t,this.$element=n(this.gallery_items.get(this.gallery_index)),this.updateTitleAndFooter(),i=this.$element.attr("data-remote")||this.$element.attr("href"),this.detectRemoteType(i,this.$element.attr("data-type")||!1),this.gallery_index+1<this.gallery_items.length&&(r=n(this.gallery_items.get(this.gallery_index+1),!1),i=r.attr("data-remote")||r.attr("href"),r.attr("data-type")==="image"||this.isImage(i))?this.preloadImage(i,!1):void 0)},navigate_left:function(){if(this.gallery_items.length!==1)return this.gallery_index===0?this.gallery_index=this.gallery_items.length-1:this.gallery_index--,this.options.onNavigate.call(this,"left",this.gallery_index),this.navigateTo(this.gallery_index)},navigate_right:function(){if(this.gallery_items.length!==1)return this.gallery_index===this.gallery_items.length-1?this.gallery_index=0:this.gallery_index++,this.options.onNavigate.call(this,"right",this.gallery_index),this.navigateTo(this.gallery_index)},detectRemoteType:function(n,t){var i;return t=t||!1,t==="image"||this.isImage(n)?(this.options.type="image",this.preloadImage(n,!0)):t==="youtube"||(i=this.getYoutubeId(n))?(this.options.type="youtube",this.showYoutubeVideo(i)):t==="vimeo"||(i=this.getVimeoId(n))?(this.options.type="vimeo",this.showVimeoVideo(i)):t==="instagram"||(i=this.getInstagramId(n))?(this.options.type="instagram",this.showInstagramVideo(i)):t==="video"?(this.options.type="video",this.showVideoIframe(n)):(this.options.type="url",this.loadRemoteContent(n))},updateTitleAndFooter:function(){var n,t,i,r;return i=this.modal_content.find(".modal-header"),t=this.modal_content.find(".modal-footer"),r=this.$element.data("title")||"",n=this.$element.data("footer")||"",r||this.options.always_show_close?i.css("display","").find(".modal-title").html(r||"&nbsp;"):i.css("display","none"),n?t.css("display","").html(n):t.css("display","none"),this},showLoading:function(){return this.lightbox_body.html('<div class="modal-loading">'+this.options.loadingMessage+"<\/div>"),this},showYoutubeVideo:function(n){var i,r,t;return r=this.$element.attr("data-norelated")!=null||this.options.no_related?"&rel=0":"",t=this.checkDimensions(this.$element.data("width")||560),i=t/(560/315),this.showVideoIframe("//www.youtube.com/embed/"+n+"?badge=0&autoplay=1&html5=1"+r,t,i)},showVimeoVideo:function(n){var i,t;return t=this.checkDimensions(this.$element.data("width")||560),i=t/(500/281),this.showVideoIframe(n+"?autoplay=1",t,i)},showInstagramVideo:function(n){var i,t;return t=this.checkDimensions(this.$element.data("width")||612),this.resize(t),i=t+80,this.lightbox_body.html('<iframe width="'+t+'" height="'+i+'" src="'+this.addTrailingSlash(n)+'embed/" frameborder="0" allowfullscreen><\/iframe>'),this.options.onContentLoaded.call(this),this.modal_arrows?this.modal_arrows.css("display","none"):void 0},showVideoIframe:function(n,t,i){return i=i||t,this.resize(t),this.lightbox_body.html('<div class="embed-responsive embed-responsive-16by9"><iframe width="'+t+'" height="'+i+'" src="'+n+'" frameborder="0" allowfullscreen class="embed-responsive-item"><\/iframe><\/div>'),this.options.onContentLoaded.call(this),this.modal_arrows&&this.modal_arrows.css("display","none"),this},loadRemoteContent:function(t){var r,i;return i=this.$element.data("width")||560,this.resize(i),r=this.$element.data("disableExternalCheck")||!1,r||this.isExternal(t)?(this.lightbox_body.html('<iframe width="'+i+'" height="'+i+'" src="'+t+'" frameborder="0" allowfullscreen><\/iframe>'),this.options.onContentLoaded.call(this)):this.lightbox_body.load(t,n.proxy(function(n){return function(){return n.$element.trigger("loaded.bs.modal")}}(this))),this.modal_arrows&&this.modal_arrows.css("display","none"),this},isExternal:function(n){var t;return(t=n.match(/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/),typeof t[1]=="string"&&t[1].length>0&&t[1].toLowerCase()!==location.protocol)?!0:typeof t[2]=="string"&&t[2].length>0&&t[2].replace(new RegExp(":("+{"http:":80,"https:":443}[location.protocol]+")?$"),"")!==location.host?!0:!1},error:function(n){return this.lightbox_body.html(n),this},preloadImage:function(t,i){var r;return r=new Image,(i==null||i===!0)&&(r.onload=function(t){return function(){var i;return i=n("<img />"),i.attr("src",r.src),i.addClass("img-responsive"),t.lightbox_body.html(i),t.modal_arrows&&t.modal_arrows.css("display","block"),i.load(function(){return t.options.scale_height?t.scaleHeight(r.height,r.width):t.resize(r.width),t.options.onContentLoaded.call(t)})}}(this),r.onerror=function(n){return function(){return n.error("Failed to load image: "+t)}}(this)),r.src=t,r},scaleHeight:function(t,i){var e,o,r,u,s,f;return u=this.modal_header.outerHeight(!0)||0,r=this.modal_footer.outerHeight(!0)||0,this.modal_footer.is(":visible")||(r=0),this.modal_header.is(":visible")||(u=0),e=this.border.top+this.border.bottom+this.padding.top+this.padding.bottom,s=parseFloat(this.modal_dialog.css("margin-top"))+parseFloat(this.modal_dialog.css("margin-bottom")),f=n(window).height()-e-s-u-r,o=Math.min(f/t,1),this.modal_dialog.css("height","auto").css("max-height",f),this.resize(o*i)},resize:function(t){var i;return i=t+this.border.left+this.padding.left+this.padding.right+this.border.right,this.modal_dialog.css("width","auto").css("max-width",i),this.lightbox_container.find("a").css("line-height",function(){return n(this).parent().height()+"px"}),this},checkDimensions:function(n){var t,i;return i=n+this.border.left+this.padding.left+this.padding.right+this.border.right,t=document.body.clientWidth,i>t&&(n=this.modal_body.width()),n},close:function(){return this.modal.modal("hide")},addTrailingSlash:function(n){return n.substr(-1)!=="/"&&(n+="/"),n}};n.fn.ekkoLightbox=function(i){return this.each(function(){var r;return r=n(this),i=n.extend({remote:r.attr("data-remote")||r.attr("href"),gallery_parent_selector:r.attr("data-parent"),type:r.attr("data-type")},i,r.data()),new t(this,i),this})};n.fn.ekkoLightbox.defaults={gallery_parent_selector:"document.body",left_arrow_class:".glyphicon .glyphicon-chevron-left",right_arrow_class:".glyphicon .glyphicon-chevron-right",directional_arrows:!0,type:null,always_show_close:!0,no_related:!1,scale_height:!0,loadingMessage:"Loading...",onShow:function(){},onShown:function(){},onHide:function(){},onHidden:function(){},onNavigate:function(){},onContentLoaded:function(){}}}).call(this);namespace("atre.ui.components");atre.ui.components.lightbox=function(n){n=n||{};var t=n.parent,i=function(){var n=window.matchMedia("screen and (min-width: 480px)");r(n);u()},r=function(n){n.matches&&f()},u=function(){$(t).delegate('*[data-toggle="lightbox"]',"click",function(n){n.preventDefault();$(this).ekkoLightbox({loadingMessage:'<h4 class="center">Loading image...<\/h4>'})})},f=function(){var n=t.find("img");typeof n!="undefined"&&n.length>0&&n.each(function(n,t){t=$(t);e(t)})},e=function(n){var t=o(n);t=s(t);var i=n.parents(".image-caption")||n.parents(".wp-caption"),r=i.find("p.image-caption-text")||i.find("p.wp-caption-text"),u=r.text();h(n,u,t)},o=function(n){var t=n.attr("src");return typeof t!="undefined"&&(t=t.split("?")[0]),t},s=function(n){return n+"?preset=max"},h=function(n,t,i){t=t?"<p id='lightboxImageCaption'>"+t+"<\/p>":"";n.attr("data-toggle","lightbox");n.attr("data-footer",t);n.attr("href",i)};return i(),{}}