(function($){lightbox2=function(o){this.currentImage=1;this.options=$.extend({restrictedImage:{photoID:0,url:"http://images.starnow.com/images/restricted_500.jpg",width:500,height:500,column:0,restricted:false,caption:""},treatAsMinor:false,minWidth:245,needsRestrictedPlaceholder:true,photoContainerSelector:null,photoColumnSelector:null},o||{});var lb2Ref=this;var photoIndex=0;if(this.options.photoContainerSelector){$(this.options.photoContainerSelector).each(function(){var currentPhotoIndex=photoIndex;$(this).click(function(e){e.preventDefault();return lb2Ref.switchPhoto(currentPhotoIndex);});photoIndex++;});}};lightbox2.prototype.f_filterResults=function(n_win,n_docel,n_body){var n_result=n_win?n_win:0;if(n_docel&&(!n_result||(n_result>n_docel))){n_result=n_docel;}return n_body&&(!n_result||(n_result>n_body))?n_body:n_result;};lightbox2.prototype.f_clientWidth=function(){return this.f_filterResults(window.innerWidth?window.innerWidth:0,document.documentElement?document.documentElement.clientWidth:0,document.body?document.body.clientWidth:0);};lightbox2.prototype.f_clientHeight=function(){return this.f_filterResults(window.innerHeight?window.innerHeight:0,document.documentElement?document.documentElement.clientHeight:0,document.body?document.body.clientHeight:0);};lightbox2.prototype.f_scrollLeft=function(){return this.f_filterResults(window.pageXOffset?window.pageXOffset:0,document.documentElement?document.documentElement.scrollLeft:0,document.body?document.body.scrollLeft:0);};lightbox2.prototype.f_scrollTop=function(){return this.f_filterResults(window.pageYOffset?window.pageYOffset:0,document.documentElement?document.documentElement.scrollTop:0,document.body?document.body.scrollTop:0);};lightbox2.prototype.showPhoto=function(photoObj){var hideRestrictedPhoto=photoObj.restricted&&this.options.treatAsMinor;var showRestrictedPlaceholder=this.options.needsRestrictedPlaceholder&&photoObj.restricted;var minWidth=this.options.minWidth;if(hideRestrictedPhoto){photoObj=this.options.restrictedImage;}var imageSidePadding=15;var topHeight=50;var width=showRestrictedPlaceholder?324:photoObj.width;var height=showRestrictedPlaceholder?375:photoObj.height;var clientWidth=this.f_clientWidth();var clientHeight=this.f_clientHeight();var container=document.getElementById("light");var photo=$("#light a.photo img");var photoLink=$("#light a.photo");var restrictedPlaceholder=$("#light .restrictedContent");var fade=document.getElementById("fade");var captionSpan=$("#light .caption");var countSpan=document.getElementById("currentImage");var video=document.getElementById("videoPlayer");var audio=document.getElementById("audioPlayer");var printLink=$("#light a.printLink");photo.attr("src","http://images.starnow.com/images/1pixel.gif");if(!showRestrictedPlaceholder){if(height>0&&width>0){if(height>clientHeight-200){width=((width/height)*(clientHeight-200));height=clientHeight-200;}container.style.top=this.f_scrollTop()+((clientHeight-(height+100))/2)+"px";photo.css("height",height+"px");}else{width=500;container.style.top=this.f_scrollTop()+50+"px";photo.css("height","auto");}}else{container.style.top=this.f_scrollTop()+((clientHeight-(height+100))/2)+"px";}var totalWidth=width+imageSidePadding*2;if(totalWidth<minWidth){totalWidth=minWidth;}container.style.width=totalWidth+"px";container.style.left=(clientWidth-totalWidth)/2+"px";container.style.right=(clientWidth-totalWidth)/2+"px";container.style.display="block";if(showRestrictedPlaceholder){photoLink.css("display","none");printLink.css("display","none");restrictedPlaceholder.css("display","block");}else{restrictedPlaceholder.css("display","none");photo.attr("src",photoObj.url);photo.attr("alt",photoObj.caption);photo.css("width",width+"px");photoLink.css("display","inline");printLink.css("display",hideRestrictedPhoto?"none":"inline");}captionSpan.html(photoObj.caption);countSpan.innerHTML=this.currentImage+1;printLink.attr("href","/profile/PrintProfileHandler.ashx?pdf=head&m_id="+memberID+"&application_id="+applicationID+"&photo_id="+photoObj.photoID);fade.style.display="block";if(video){video.innerHTML='<div style="width:500px;height:340px;background:#eee"></div>';}if(audio){audio.innerHTML='<div style="width:400px;height:40px;"></div>';}if(!(showRestrictedPlaceholder||hideRestrictedPhoto)){doXMLHTTPRequest("/profile/PhotosTrackView.aspx?photo_id="+photoObj.photoID);}};lightbox2.prototype.switchPhoto=function(value){if(value==-1&&this.currentImage<totalPhotos){this.currentImage++;}else{if(value==-1){this.currentImage=0;}else{if(value==-2&&this.currentImage>0){this.currentImage--;}else{if(value==-2){this.currentImage=totalPhotos;}else{if(value<=totalPhotos){this.currentImage=value;}}}}}this.showPhoto(photos[this.currentImage]);return false;};lightbox2.prototype.hidePhoto=function(){document.getElementById("light").style.display="none";document.getElementById("fade").style.display="none";return false;};lightbox2.prototype.refreshPhotoGallery=function(photoColumnSelector){var columns=$(photoColumnSelector);var currentScrollPosition=$(window).scrollTop();$(columns[0]).empty();$(columns[1]).empty();$(columns[2]).empty();var lb2Ref=this;var photoIndex=0;for(var numPhotos=photos.length;photoIndex<numPhotos;photoIndex++){addAndBindPhoto=function(){var currentPhoto=photos[photoIndex];if(currentPhoto.column>0){var currentColumn=$(columns[currentPhoto.column-1]);var currentPhotoIndex=photoIndex;var sourceAttribute='src2="';if(currentColumn.children().length<2){sourceAttribute='src="';}currentColumn.append('<a href="'+location.pathname+"/photo/"+currentPhoto.photoID+'/"><img '+sourceAttribute+currentPhoto.url+'" border="0" style="width: 280px; height: '+currentPhoto.mediumHeight+'px"/></a>');currentColumn.children().last().click(function(e){e.preventDefault();return lb2Ref.switchPhoto(currentPhotoIndex);});}};addAndBindPhoto();}$("#photosDiv .photoTable img").lazyload({placeholder:"http://images.starnow.com/images/1pixel.gif",effect:"fadeIn",failurelimit:30});$(window).scrollTop(currentScrollPosition);};lightbox2.prototype.enableRestrictedContent=function(){this.options.needsRestrictedPlaceholder=false;this.options.treatAsMinor=false;var lb2Ref=this;$.ajax({type:"POST",contentType:"application/json; charset=utf-8",url:"/services/MembershipService.asmx/EnableRestrictedContent",data:"{}",dataType:"json",success:function(data,status){lb2Ref.showPhoto(photos[lb2Ref.currentImage]);lb2Ref.refreshPhotoGallery(lb2Ref.options.photoColumnSelector);}});return false;};lightbox2.prototype.blockRestrictedContent=function(){this.options.needsRestrictedPlaceholder=false;this.options.treatAsMinor=true;this.showPhoto(photos[this.currentImage]);return false;};})(jQuery);
