var VM=VM||{};VM.PhotoViewer={photos:[],photoCount:0,baseUrl:"",siteId:null,notrack:!1,slider:null,$galleryContainer:null,$galleryContents:null,$galleryClose:null,$galleryCloseBg:null,$galleryExpand:null,$galleryStats:null,$galleryAdCaption:null,$container:null,$imgContainer:null,$sliderCurrent:null,$caption:null,$byline:null,$mask:null,onPopupGalleryClosed:null,init:function(){this.$container=$("#slider");this.$container.length&&(this.notrack=this.$container.data("notrack")||!1,this.$galleryContainer=$("#gallery-c"),this.$galleryContents=this.$galleryContainer.children(),this.siteId=this.$container.data("site").toString(),this.baseUrl=window.location.pathname+(window.location.search?"&":"?"),this.reset(),this.$container.removeClass("nojs"),this.$imgContainer=$("#sliderImgs"),this.$sliderCurrent=$("#galleryStatsCurrent"),this.populatePhotos(),this.sliderInit(),this.photos.length>1&&(this.$galleryStats=$("#galleryStats"),this.$galleryAdCaption=$("#galleryAdCaption"),this.$caption=$("#galleryCaption"),this.$byline=$("#galleryByline"),$("#sliderPrev").removeClass("hidden").click(this.onPrevClick),$("#sliderNext").removeClass("hidden").click(this.onNextClick),this.$galleryExpand=$("#galleryExpand").removeClass("hidden").click(this.onExpandClick)),$(document).keyup(function(n){switch(n.keyCode){case 27:VM.PhotoViewer.onClose();break;case 37:VM.PhotoViewer.swipe.prev();break;case 39:VM.PhotoViewer.swipe.next()}}))},reset:function(){this.photos=[];this.photoCount=0},populatePhotos:function(){var n=this,t=n.$container.data("width"),i=n.$container.data("height"),u=t+"/"+i,r=0;this.$imgContainer.find(".galleryWrap").each(function(f){var e=$(this),o;if(e.hasClass("ad"))o=e.find(".slot span").attr("id"),n.photos.push({ad:!0,slot:o}),r++;else{var s={ad:!1,src:e.data("src"),thumb:e.data("thumb"),isvideo:e.hasClass("video"),title:this.title,byline:e.data("byline")},h=e.data("width"),c=e.data("height");n.photos.push(s);f>0&&e.append('')}});this.photoCount=this.photos.length;$("#galleryStatsOf").text(this.photoCount-r);this.preload(1);this.preload(this.photoCount-1)},sliderInit:function(){var n=this;this.swipe=new Carousel(this.$container.get(0),{callback:function(t){n.onSwipe.call(n,t.index,t.seats[t.index])}})},onPrevClick:function(n){n.preventDefault();VM.PhotoViewer.swipe.prev()},onNextClick:function(n){n.preventDefault();VM.PhotoViewer.swipe.next()},onSwipe:function(n,t){var r=this.getThumbIndex(n),i=$(t).children("div");!VM.PhotoViewer.notrack&&VM.Track.isTracking()&&(i.hasClass("viewed")||i.hasClass("ad")||(i.addClass("viewed"),VM.Track.trackPageview({page_path:VM.PhotoViewer.baseUrl+"pic="+(r+1),page_title:i.attr("title")||i.data("src").split(";")[0]})));this.setCurrentIndex(n);this.preload(n-1);this.preload(n);this.preload(n+1)},setCurrentIndex:function(n){var r=this.getThumbIndex(n),t=r+1,i;this.photoCount===2&&(t===3&&(t=1),t===4&&(t=2));i=this.photos[n];i.ad?(this.$galleryStats.addClass("hidden"),this.$caption.text("").addClass("hidden"),this.$byline.text("").toggleClass("caption-byline",!1),this.$galleryAdCaption.removeClass("hidden")):(this.$galleryAdCaption.addClass("hidden"),this.$byline.length&&this.$byline.text(i.byline).toggleClass("caption-byline",i.byline.length>0),this.$caption.text(i.title).removeClass("hidden"),this.$galleryStats.removeClass("hidden"),this.$sliderCurrent.text(t))},preload:function(n){var t,i,r;n>=this.photoCount&&(n=0);n===-1&&(n=this.photoCount-1);t=this.$imgContainer.find("li").eq(n).children(".galleryWrap");t.hasClass("preloaded")||t.hasClass("ad")?t.hasClass("ad")&&t.children("div").hasClass("gam-lazy")&&(r=t.children("div"),r.removeClass("gam-lazy").addClass("gam"),VM.Slots.loadSlot(r[0],function(n){VM.Slots.refreshSlots([n])})):(i=this.photos[n],t.children("img").attr("src",i.src).attr("alt",i.title),t.addClass("preloaded"))},onExpandClick:function(n){n&&n.preventDefault();VM.PhotoViewer.$galleryContainer.addClass("vm-modal").css("display","block");$("header").addClass("hidden");$("#body").css("z-index",19);VM.PhotoViewer.$mask?(VM.PhotoViewer.$galleryClose.removeClass("hidden"),VM.PhotoViewer.$galleryCloseBg.removeClass("hidden")):(VM.PhotoViewer.$mask=$('