!function(t,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof module&&module.exports?module.exports=e():t.SimpleLightbox=e()}(this,(function(){function t(t){for(var e=1;e=this.items.length?t=0:t<0&&(t=this.items.length-1),t},showPosition:function(t){var e=this.normalizePosition(t);return void 0!==this.currentPosition&&(this.direction=e>this.currentPosition?"next":"prev"),this.currentPosition=e,this.setupLightboxHtml().prepareItem(this.currentPosition,this.setContent).show()},loading:function(t){var n=this,s=this.options;t?this.loadingTimeout=setTimeout((function(){e(n.$el,s.elementLoadingClass),n.$content.innerHTML='

'+s.loadingCaption+"

",n.show()}),s.loadingTimeout):(i(this.$el,s.elementLoadingClass),clearTimeout(this.loadingTimeout))},getVideoURL:function(t){for(var e="//_URL_",i=[{rx:/^(?:https?:)?\/\/(?:www\.)?vimeo\.com\/([^\?&"]+).*$/g,tmpl:e.replace("_URL_","player.vimeo.com/video/$1")},{rx:/^.*(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=|embed\/|v\/|user\/.+\/)?([^\?&"]+).*$/g,tmpl:e.replace("_URL_","www.youtube.com/embed/$1")},{rx:/^.*(?:https?:\/\/)?(?:www\.)?(?:youtube-nocookie\.com)\/(?:watch\?v=|embed\/|v\/|user\/.+\/)?([^\?&"]+).*$/g,tmpl:e.replace("_URL_","www.youtube-nocookie.com/embed/$1")}],n=0;n'))}else{var r=n('
');this.$currentImage=r.querySelector(".slbImage"),this.options.showCaptions&&this.captions[t]&&r.appendChild(n('
'+this.captions[t]+"
")),this.loadImage(s,(function(){i.setImageDimensions(),e.call(i,r),i.loadImage(i.items[i.normalizePosition(i.currentPosition+1)])}))}return this},loadImage:function(t,e){if(!this.options.videoRegex.test(t)){var i=new Image;e&&(i.onload=e),i.src=t}},setupLightboxHtml:function(){var t=this.options;return this.$el||(this.$el=n('
'+(this.items.length>1?'
":"")+"
"),this.$content=this.$el.querySelector(".slbContent")),this.$content.innerHTML="",this},show:function(){return this.modalInDom||(document.querySelector(this.options.appendTarget).appendChild(this.$el),e(document.documentElement,this.options.htmlClass),this.setupLightboxEvents(),this.modalInDom=!0),this},setContent:function(t){var s="string"==typeof t?n(t):t;return this.loading(!1),this.setupLightboxHtml(),i(this.$content,"slbDirectionNext"),i(this.$content,"slbDirectionPrev"),this.direction&&e(this.$content,"next"===this.direction?"slbDirectionNext":"slbDirectionPrev"),this.options.beforeSetContent&&this.options.beforeSetContent(s,this),this.$content.appendChild(s),this},setImageDimensions:function(){this.$currentImage&&(this.$currentImage.style.maxHeight=("innerHeight"in window?window.innerHeight:document.documentElement.offsetHeight)+"px")},setupLightboxEvents:function(){var t=this;return this.eventRegistry.lightbox.length?this:(this.addEvent(this.$el,"click",(function(e){var i=e.target;s(i,".slbCloseBtn")||t.options.closeOnOverlayClick&&s(i,".slbWrap")?t.close():s(i,".slbArrow")?s(i,".next")?t.next():t.prev():t.options.nextOnImageClick&&t.items.length>1&&s(i,".slbImage")&&t.next()})).addEvent(document,"keyup",(function(e){t.options.closeOnEscapeKey&&27===e.keyCode&&t.close(),t.items.length>1&&((39===e.keyCode||68===e.keyCode)&&t.next(),(37===e.keyCode||65===e.keyCode)&&t.prev())})).addEvent(window,"resize",(function(){t.setImageDimensions()})),this)},close:function(){this.modalInDom&&(this.runHook("beforeClose"),this.removeEvents("lightbox"),this.$el&&this.$el.parentNode.removeChild(this.$el),i(document.documentElement,this.options.htmlClass),this.modalInDom=!1,this.runHook("afterClose")),this.direction=void 0,this.currentPosition=this.options.startAt},destroy:function(){this.close(),this.runHook("beforeDestroy"),this.removeEvents("thumbnails"),this.runHook("afterDestroy")},runHook:function(t){this.options[t]&&this.options[t](this)}}),o.open=function(t){var e=new o(t);return t.content?e.setContent(t.content).show():e.showPosition(e.options.startAt)},o.registerAsJqueryPlugin=function(t){t.fn.simpleLightbox=function(e){var i,n=this;return this.each((function(){t.data(this,"simpleLightbox")||(i=i||new o(t.extend({},e,{$items:n})),t.data(this,"simpleLightbox",i))}))},t.SimpleLightbox=o},"undefined"!=typeof window&&window.jQuery&&o.registerAsJqueryPlugin(window.jQuery),o}));