collectionPopup={context:null,genID:null,photoID:null,currentIndex:0,photoCount:0,photoIDs:null,photoLinks:null,photos:null,preloaded:null,captions:null,journalTitles:null,slider:null,sliderSectionName:"",sliderSectionVisible:1,sliderSectionCount:0,photosPerSection:6,isNew:true,init:function(){this.context=null;this.genID=null;this.photoID=null;},loadGallery:function(gID,pID){this.isNew=true;this.genID=gID;if('undefined'!=typeof(pID)){this.photoID=pID;}
var url='/photo/LoadPopUpGallery?modal=true&width=870&genID='+this.genID;if(null!=this.photoID){url+='&photoID='+this.photoID;}
tb_open_new('',url);},closeGallery:function(){self.parent.tb_remove(this);this.init();},scrollToPrevStrip:function(auto){if(1==this.sliderSectionVisible&&"undefined"==typeof(auto)){return false;}
this.sliderSectionVisible--;var name=this.sliderSectionName+"-"+this.sliderSectionVisible;this.slider.slideContent(name);},scrollToNextStrip:function(auto){if(this.sliderSectionCount==this.sliderSectionVisible&&"undefined"==typeof(auto)){return false;}
this.sliderSectionVisible++;var name=this.sliderSectionName+"-"+this.sliderSectionVisible;this.slider.slideContent(name);},scrollToPrevPhoto:function(){var index=this.getCurrentIndex();if(0<index){this.setCurrentIndex(--index);this.setActivePhoto();}
this.checkCurrentSliderSectionVisible();},scrollToNextPhoto:function(){var index=this.getCurrentIndex();if(index<this.getPhotoCount()-1){this.setCurrentIndex(++index);this.setActivePhoto();}
this.checkCurrentSliderSectionVisible();},checkCurrentSliderSectionVisible:function(){var index=this.getCurrentIndex();var curStripVisible=Math.floor(index/this.photosPerSection)+1;if(curStripVisible>this.sliderSectionVisible){this.scrollToNextStrip(true);}else if(curStripVisible<this.sliderSectionVisible){this.scrollToPrevStrip(true);}},setActivePhoto:function(photoID){if('undefined'!=typeof(photoID)){var index=this.getPhotoIndex(photoID);if(-1<index&&this.getCurrentIndex()!=index){this.setCurrentIndex(index);}}
jQuery("#prev_photo").hide();jQuery("#next_photo").hide();var curLink=this.getCurrentPhotoLink();var curCaption=this.getCurrentCaption();var curTitle=this.getCurrentJournalTitle();var curImage=new Image();curImage.onload=function(){collectionPopup.preloaded[collectionPopup.currentIndex]=true;var source=this.src;var width=this.width+237;jQuery("#loading_photo").hide();jQuery("#active_photo").fadeOut("normal",function(){jQuery("#active_photo").attr("src",source);if(collectionPopup.isNew){jQuery("#thickboxs").show();}}).fadeIn("normal",function(){jQuery("#active_photo_caption").html(curCaption);jQuery("#journal_title").html(curTitle);collectionPopup.updateNavOnPhoto();});}
curImage.src=curLink;this.preloadPhotos();},getPhotoIndex:function(photoID){for(var i=0;i<this.photoIDs.length;i++){if(photoID==this.photoIDs[i]){return i;}}
return-1;},setCurrentIndex:function(index){this.currentIndex=index;},getCurrentIndex:function(){return this.currentIndex;},getCurrentCaption:function(){return this.captions[this.getCurrentIndex()];},getCurrentJournalTitle:function(){return this.journalTitles[this.getCurrentIndex()];},getCurrentUploadDate:function(){return this.uploadDates[this.getCurrentIndex()];},getCurrentPhotoLink:function(){return this.photoLinks[this.getCurrentIndex()];},getPhotoCount:function(){return this.photoCount;},setGalleryData:function(defaultIndex,photocount,photoID_array,links_array){this.currentIndex=defaultIndex;this.photoCount=photocount;var ids=photoID_array.split(",");var links=links_array.split(",");this.photoLinks=new Array();this.photoIDs=new Array();this.photos=new Array();this.fullsizelinks=new Array();this.preloaded=new Array();this.captions=new Array();this.journalTitles=new Array();for(var i=0;i<ids.length;i++){if('undefined'==typeof(this.preloaded[i])){this.preloaded[i]=false;}
this.photoIDs[i]=ids[i];this.photoLinks[i]=links[i];this.captions[i]=jQuery("#caption_"+i).html();this.journalTitles[i]=jQuery("#jtitle_"+i).html();}
this.updateNavOnPhoto();},preloadPhotos:function(){for(var i=this.currentIndex-1,j=1;i>0&&j<=3;i--,j++){this.photos[i]=new Image();this.photos[i].onload=function(){collectionPopup.preloaded[i]=true;}
this.photos[i].src=this.photoLinks[i];}
for(var i=this.currentIndex+1,j=1;i<this.photoCount&&j<=3;i++,j++){this.photos[i]=new Image();this.photos[i].onload=function(){collectionPopup.preloaded[i]=true;}
this.photos[i].src=this.photoLinks[i];}},setSlider:function(sliderObj,name,sectionVisible,photosPerSection,sectionCount){this.slider=sliderObj;this.sliderSectionName=name;this.sliderSectionVisible=sectionVisible;this.photosPerSection=photosPerSection;this.sliderSectionCount=sectionCount;if(this.sliderSectionVisible==1){jQuery("#btnPrevStrip").addClass("disabled");}
if(this.sliderSectionVisible==this.sliderSectionCount){jQuery("#btnNextStrip").addClass("disabled");}},getCurrentPhotoWidth:function(){return document.getElementById("active_photo").width;},getCurrentPhotoHeight:function(){return document.getElementById("active_photo").height;},resetNavOnPhoto:function(){if(null!=document.getElementById("navhover")){var width=this.getCurrentPhotoWidth()
var height=this.getCurrentPhotoHeight()+2;jQuery(".active_photo").attr("style","width:"+width+"px;");jQuery(".viewed_holder").attr("style","margin: auto; width: "+width+"px;height:"+height+"px;");jQuery(".navhover").show();this.updateNavOnPhoto();}
if(this.isNew){contentSlider.slideContent(this.sliderSectionName+"-"+this.sliderSectionVisible);this.isNew=false;this.updateNavOnPhoto();}},updateNavOnPhoto:function(){if(2>collectionPopup.getPhotoCount()){return;}
if(0==collectionPopup.getCurrentIndex()){jQuery("#prev_photo").hide();}else{jQuery("#prev_photo").show();}
if(collectionPopup.getCurrentIndex()==collectionPopup.getPhotoCount()-1){jQuery("#next_photo").hide();}else{jQuery("#next_photo").show();}}}
ThumbGridControl={init:function(){},expandGrid:function(){jQuery("#expand_grid").hide();jQuery("#grid_expansion").slideDown("fast");jQuery("#collapse_grid").show();},collapseGrid:function(){jQuery("#collapse_grid").hide();jQuery("#grid_expansion").slideUp("fast");jQuery("#expand_grid").show();},showGallery:function(pID,genID){collectionPopup.loadGallery(genID,pID);}};contentSlider={SLIDETIMER:50,SLIDESPEED:50,SCROLLTIMER:50,SCROLLSPEED:50,STARTINGOPACITY:50,slideContent:function(id,prefix,timer){var div=document.getElementById(id);var slider=div.parentNode;clearInterval(slider.timer);slider.section=parseInt(id.replace(/\D/g,''));slider.target=div.offsetTop;slider.style.top=slider.style.top||'0px';slider.current=slider.style.top.replace('px','');slider.direction=(Math.abs(slider.current)>slider.target)?1:-1;slider.style.filter='alpha(opacity='+contentSlider.STARTINGOPACITY+')';slider.timer=setInterval(function(){contentSlider.slideAnimate(slider,prefix,timer)},contentSlider.SLIDETIMER);},slideAnimate:function(slider,prefix,timer){var curr=Math.abs(slider.current);var tar=Math.abs(slider.target);var dir=slider.direction;if((tar-curr<=contentSlider.SLIDESPEED&&dir==-1)||(curr-tar<=contentSlider.SLIDESPEED&&dir==1)){slider.style.top=(slider.target*-1)+'px';slider.style.opacity=1;slider.style.filter='alpha(opacity=100)';clearInterval(slider.timer);if(slider.autoscroll){setTimeout(function(){contentSlider.autoScroll(slider.id,prefix,timer)},timer*1000);}}else{var pos=(dir==1)?parseInt(slider.current)+contentSlider.SLIDESPEED:slider.current-contentSlider.SLIDESPEED;slider.current=pos;slider.style.top=pos+'px';}},scrollContent:function(id,dir){var div=document.getElementById(id);clearInterval(div.timer);var sections=div.getElementsByTagName('div');var length=sections.length;var limit;if(dir==-1){limit=0;}else{if(length>1){limit=sections[length-1].offsetTop;}else{limit=sections[length-1].offsetHeight-div.parentNode.offsetHeight+20;}}
div.style.opacity=contentSlider.STARTINGOPACITY*.01;div.style.filter='alpha(opacity='+contentSlider.STARTINGOPACITY+')';div.timer=setInterval(function(){contentSlider.scrollAnimate(div,dir,limit)},contentSlider.SCROLLTIMER);},scrollAnimate:function(div,dir,limit){div.style.top=div.style.top||'0px';var top=div.style.top.replace('px','');if(dir==1){if(limit-Math.abs(top)<=contentSlider.SCROLLSPEED){contentSlider.cancelScroll(div.id);div.style.top='-'+limit+'px';}else{div.style.top=top-contentSlider.SCROLLSPEED+'px';}}else{if(Math.abs(top)-limit<=contentSlider.SCROLLSPEED){contentSlider.cancelScroll(div.id);div.style.top=limit+'px';}else{div.style.top=parseInt(top)+contentSlider.SCROLLSPEED+'px';}}},cancelScroll:function(id){var div=document.getElementById(id);div.style.opacity=1;div.style.filter='alpha(opacity=100)';clearTimeout(div.timer);},autoScroll:function(id,prefix,timer,restart){var div=document.getElementById(id);div.autoscroll=(!div.autoscroll&&!restart)?false:true;if(div.autoscroll){var sections=div.getElementsByTagName('div');var length=sections.length;div.section=(div.section&&div.section<length)?div.section+1:1;contentSlider.slideContent(prefix+'-'+div.section,prefix,timer);}},cancelAutoScroll:function(id){var div=document.getElementById(id);div.autoscroll=false;}}
