function ThumbNails(){initImagesArr();this.dissolve=true;this.NextLgImage=null;this.OldImage=null;this.nextImgTimer=0;this.progressBarTimer=0;this.curIndex=-1;this.tnRemainingTN=0;this.TopImage=null;this.imgWidOld=0;this.imgHgtOld=0;this.checkTnDim=checkTnDim;this.displayThumbnails=displayThumbnails;this.enlarge=enlarge;this.getCount=getCount;this.getNewIndex=getNewIndex;this.getThumbnails=getThumbnails;this.imgBorder=imgBorder;this.init=init;this.init();this.initTN=initTN;this.kill=kill;this.nextImage=nextImage;this.preloadNext=preloadNext;this.showDownloadProgress=showDownloadProgress;this.showNumImages=showNumImages;this.updateProgressBar=updateProgressBar;function displayThumbnails(showProgressBar){gId("ThumbnailsGUI").innerHTML=TN.getThumbnails();if( desktopComputer && showProgressBar && ( /^thumbnails\./i.test(fileName ) || /^tn\./i.test(fileName))){DW.createWindow(["<div class=\"ProgressBarTitle\">Loading Thumbnails</div>","<div id='ThumbnailsProgressBar' class='ThumbnailsProgressBar' align='center'></div>"],[0,340,0],null,null,0,[4,0,0],"",1,0,1);TN.updateProgressBar();}}
function init(){this.nImages=Images.length;this.maxIndex=this.nImages-1;this.ImagesOriginal=Images;this.folderOriginal=Settings.folder;this.defaultCaption=Settings.defaultCaption;}
function initTN(){this.showNumImages();this.checkTnDim();}
function getNewIndex(movingForward){if(movingForward)return(this.curIndex<this.maxIndex)?this.curIndex+1:0;else
return(this.curIndex>0)?this.curIndex-1:this.maxIndex;}
function preloadNext(){var newIndex=this.getNewIndex(1);var PreLoadImage=new Image();PreLoadImage.src=Settings.folder+Images[newIndex][0];var nOldImg=(newIndex==0)?Images.length-1:newIndex-1;this.OldImage=new Image();this.OldImage.src=Settings.folder+Images[nOldImg][0];}
function imgBorder(Img,color){if(Img.complete)Img.style.borderColor=color;}
function showNumImages(){var ThumbnailsProgressBar=gId("ThumbnailsProgressBar");if(ThumbnailsProgressBar&&this.nImages>-1){if(Settings.TN.ProgressBar.hideOnSuccess)DW.removeWin();}}
function updateProgressBar(){var ThumbnailsProgressBar=gId("ThumbnailsProgressBar");try{if(this.tnRemainingTN>=0){var dBarWid=(this.nImages-this.tnRemainingTN)*(Settings.TN.ProgressBar.width/this.nImages);var percentLoaded=parseInt(((this.nImages-this.tnRemainingTN)/this.nImages)*100);if(!Settings.TN.ProgressBar.hideOnSuccess){dBarWid=this.nImages/2*(Settings.TN.ProgressBar.width/this.nImages);percentLoaded=50;}
var Pbar=new Array();Pbar.push("<div class='ProgressBar' style='width:");Pbar.push(Settings.TN.ProgressBar.width);Pbar.push("px;'>");Pbar.push("<div class='ProgressBarLoaded' style='width:");Pbar.push(dBarWid);Pbar.push("px;'>&nbsp;</div>");Pbar.push("</div>");Pbar.push("<div class='ProgressBarPercent' style='width:");Pbar.push(Settings.TN.ProgressBar.width);Pbar.push("px;'>");Pbar.push(percentLoaded);Pbar.push("%");Pbar.push("</div>");ThumbnailsProgressBar.innerHTML=Pbar.join("");if(!Settings.TN.ProgressBar.hideOnSuccess)clearTimeout(TN.progressBarTimer);else if(this.tnRemainingTN>0)TN.progressBarTimer=setTimeout("TN.updateProgressBar()",200);else if(Settings.TN.ProgressBar.hideOnSuccess)ThumbnailsProgressBar.style.visibility="hidden";}}
catch(Err){TN.progressBarTimer=setTimeout("TN.updateProgressBar()",250);}}
function getCount(newIndex){return(newIndex+1)+"/"+(this.maxIndex+1);}
function kill(){this.NextLgImage=null;clearInterval(this.nextImgTimer);this.nextImgTimer=0;if(this.TopImage){rCh(this.TopImage);this.TopImage=null;}}
function nextImage(movingForward,evt){var ImageDW=gId("ImageDW");if(ImageDW){var newIndex=this.getNewIndex(movingForward);if(!this.NextLgImage){this.NextLgImage=new Image();this.NextLgImage.src=Settings.folder+Images[newIndex][0];}
if(this.NextLgImage.complete&&this.OldImage.complete){if(!evt)evt=window.event;if(userWithWritePrivileges||(evt&&evt.shiftKey))this.dissolve=false;if(!gId("dwOverlay"))DW.addOverlay(0,"TN");ImageDW.onload=null;var imgWidNew=this.NextLgImage.width;var imgHgtNew=this.NextLgImage.height;var WinDim=DW.getScaledSize(imgWidNew,imgHgtNew,Images[newIndex][1]);var fullSize=(WinDim[0]==imgWidNew&&WinDim[1]==imgHgtNew);imgWidNew=WinDim[0];imgHgtNew=WinDim[1];if(!TN.TopImage){TN.TopImage=gEl("IMG");TN.TopImage.id="TopImage";TN.TopImage.style.top=(imgHgtNew*-2)+"px";TN.TopImage.style.left=(imgWidNew*-2)+"px";TN.TopImage.style.zIndex=10001;TN.TopImage.style.position="absolute";TN.TopImage.style.cursor="pointer";TN.TopImage.oncontextmenu=function(){return(Settings.preventImageTheft)?false:true;}
TN.TopImage.onmouseover=function(){DW.overImg=true;}
TN.TopImage.onmouseout=function(){DW.overImg=false;}
TN.TopImage.onclick=function(event){TN.nextImage(1,event);this.title="Next enlargement";gId("ImageDW").title="";}
aCh(TN.TopImage);}
TN.TopImage.title="Next enlargement";(IE)?TN.TopImage.style.visibility="hidden":TN.TopImage.style.opacity=0;TN.TopImage.src=this.NextLgImage.src;TN.TopImage.style.height=imgHgtNew+"px";TN.TopImage.style.width=imgWidNew+"px";var Win=gId("dWinID");gId("SsTnCount").innerHTML=this.getCount(newIndex);var photoCaption=getPhotoCaption(Images[newIndex][1]);gId("SsTnTitle").innerHTML=photoCaption;var marLeft=Math.round((imgWidNew-this.imgWidOld)/2);var marTop=Math.round((imgHgtNew-this.imgHgtOld)/2);ImageDW.parentNode.style.marginLeft=marLeft+"px";ImageDW.parentNode.style.marginTop=marTop+"px";ImageDW.parentNode.parentNode.style.overflow="hidden";ImageDW.src=this.OldImage.src;ImageDW.style.width=this.imgWidOld+"px";ImageDW.style.height=this.imgHgtOld+"px";this.imgWidOld=imgWidNew;this.imgHgtOld=imgHgtNew;ImageDW.parentNode.parentNode.style.height=imgHgtNew+"px";Win.style.width=imgWidNew+"px";DW.reCenter(Win);DW.moveTopImage();this.NextLgImage=null;clearInterval(this.nextImgTimer);this.nextImgTimer=0;this.curIndex=(movingForward)?this.curIndex+1:this.curIndex-1;if(this.curIndex>this.maxIndex)this.curIndex=0;else if(this.curIndex<0)this.curIndex=this.maxIndex;this.preloadNext();if(this.dissolve&&fullSize)startFade(TN.TopImage,Settings.transDur,0);else(IE)?TN.TopImage.style.visibility="visible":TN.TopImage.style.opacity=1;this.dissolve=true;}
else{if(this.nextImgTimer==0){eval("this.nextImgTimer = setInterval( 'TN.nextImage( "+movingForward+" )', 250 );");gId("SsTnTitle").innerHTML="Downloading Image<span id='dot1'>.</span><span id='dot2'>.</span><span id='dot3'>.</span><span id='dot4'>.</span>";this.showDownloadProgress();}}}
else
this.kill();}
var nDotsVisible=4;function showDownloadProgress(){var Dot1=gId("dot1");var Dot2=gId("dot2");var Dot3=gId("dot3");var Dot4=gId("dot4");if(Dot1&&Dot2&&Dot3&&Dot4){for(var i=1;i<=4;i++)gId("dot"+i).style.visibility=(i<=nDotsVisible)?"visible":"hidden";nDotsVisible++;if(nDotsVisible==5)nDotsVisible=0;setTimeout("TN.showDownloadProgress();",500);}}
function enlarge(cap,imageNum){if(window.SS)SS.kill();if(window.Images==null){window.Images=this.ImagesOriginal;Settings.folder=this.folderOriginal;Settings.defaultCaption=this.defaultCaption;}
DW.photoCaption=Images[imageNum][1];DW.photoCount=TN.getCount(imageNum);DW.createEnlargement("TN",Settings.folder+Images[imageNum][0]);return false;}
function getThumbnails(){this.tnRemainingTN=this.nImages;var H=new Array();var tnNum=0;thePageTitle=Settings.TN.pageTitle;thePageTitle=thePageTitle.replace(/\^\^/g, "&#39;" );
thePageTitle=thePageTitle.replace(/\^/g, "&#34;" );
thePageTitle=thePageTitle.replace(/<>/g, "<span class='tnTitleBullet'>&#149;</span>" );
if(thePageTitle){H.push("<div class='tnTitle' align='center'>");H.push(thePageTitle);H.push("</div>");}
var cls = ( /^thumbnails\./i.test(fileName ) || /^tn\./i.test(fileName))?"tnPage":"tnOther";var clsOn=cls+"On";H.push("<table align='center'>");var nRows=Math.floor(this.nImages/Settings.TN.nImagesRow)+1;for(var row=0;row<nRows;row++){H.push("<tr align='");H.push(Settings.TN.align);H.push("' valign='middle'><td align='center' style='white-space:nowrap;'>");H.push("<table align='center'>");H.push("<tr>");for(var i=0;i<Settings.TN.nImagesRow;i++){var writeTN=(tnNum<this.nImages)?true:false;if(writeTN){var lgImageName=Images[tnNum][0],tnImageName="";lastDotPos=lgImageName.lastIndexOf(".");var fileExt="TN"+lgImageName.substring(lastDotPos,lgImageName.length);tnImageName=(Images[tnNum][2])?Images[tnNum][2]:lgImageName.split(".")[0]+fileExt;var imgTitle=Images[tnNum][1].trim();imgTitle=imgTitle.replace(/'/g, "&#39;" );
imgTitle=imgTitle.replace(/"/g, "\\\"" );
var toolTip=imgTitle;if(toolTip=="_")toolTip="";else if(!toolTip)toolTip=Settings.defaultCaption;toolTip=toolTip.replace(/ *\[ */g, "[" ).replace(/ *\] */g, "]" );
toolTip=toolTip.replace(/\]\[/g, "<br/>" );
toolTip=toolTip.replace(/\[/, "<div class=\\\"ToolTipMore\\\">" ).replace(/]/, "</div>" );
var tn=Settings.folder+tnImageName;tnNum++;}
var imageNum=row*Settings.TN.nImagesRow+i+1;if(userWithWritePrivileges){var toolTipColon=(toolTip)?": ":"";toolTip=imageNum+toolTipColon+toolTip;}
if(writeTN){var lgImgName=Images[tnNum-1][0];H.push("<td class='");H.push(cls);H.push("'>");H.push("<a href='javascript:void(0);' onClick='if( window.DW ) { TN.curIndex = ");H.push(imageNum-1);H.push("; this.blur(); return TN.enlarge( \"");H.push(imgTitle);H.push("\", ");H.push(imageNum-1);H.push(" ); }'>");H.push("<img src='");H.push(tn);H.push("' ");H.push("class='");H.push(cls);H.push("' style='");H.push("width:");H.push(Settings.TN.width);H.push("px;");H.push(" height:");H.push(Settings.TN.height);H.push("px;");H.push("'");H.push(" onMouseover='if( window.TN ) this.className=\"");H.push(cls);H.push(" ");H.push(clsOn);H.push("\";");if(toolTip){H.push(" Tip.showIt( \"");H.push(toolTip);H.push("\", event );' onMousemove='Tip.setPosition( event );'");}
else
H.push("'");H.push(" onMouseout='if( window.TN ) this.className=\"");H.push(cls);H.push("\"; Tip.removeAll();' onAbort='this.src=this.src;' onLoad='TN.tnRemainingTN--;' onContextMenu='");H.push(((Settings.preventImageTheft)?"return false;":"return true;"));H.push("' id='TN_");H.push(imageNum);H.push("'>");H.push("</a>");H.push("</td>");}}
H.push("</tr>");H.push("</table>");H.push("</td></tr>");}
H.push("</table>");if( Settings.TN.AppendSlideShowLink && ( /^thumbnails\./i.test(fileName ) || /^tn\./i.test(fileName))){H.push("<div align='center' class='SlideShowLink'>");H.push("<a href='javascript:void(0);' onClick='return launchSS( null, this );' class='SlideShowLink' title='View these photos in a slide-show'>Slide-Show</a>");H.push("</div>");}
var htm=H.join("");return htm;}
this.checkTN=1;this.checkTnTimer=0;this.TnReal=null;this.TnSizeErr="";function checkTnDim(){if(userWithWritePrivileges||local){if(this.TnReal==null){var TN=gId("TN_"+this.checkTN);if(TN){TnReal=new Image();TnReal.src=TN.src;}
else{TnReal=null;clearTimeout(this.checkTnTimer);if(this.TnSizeErr){var msgOut=this.TnSizeErr;if(IE)msgOut+="<br/><br/>We see you are using Internet Explorer. It suffers from a peculiar bug such that even if you correct the dimensions, it may continue to report this error! If so, then change the file name too, for example:<br/>1. beachTN.jpg &rArr; beach1TN.jpg<br/>2. beach.jpg &rArr; beach1.jpg";DW.createWindow(["Thumbnail Dimension Error","<div style='margin:0px 0px 4px 0px;' class='dwText'>Thumbnails must be "+Settings.TN.width+" x "+Settings.TN.height+" pixels, and:</div>"+msgOut],[1,450,300],null,null,6,[4,0,0]);}}}
if(TnReal&&TnReal.complete){var realWid=TnReal.width,realHgt=TnReal.height;if(realWid>1&&realHgt>1&&(realWid!=Settings.TN.width||realHgt!=Settings.TN.height)){var FileComponents=TnReal.src.split("/");var imgFileName=FileComponents[FileComponents.length-1];this.TnSizeErr+="<div style='margin:0px 0px 0px 8px;'>#"+this.checkTN+" "+imgFileName+" is "+realWid+" x "+realHgt+"</div>";}
this.checkTN++;this.checkTnTimer=setTimeout("TN.checkTnDim();",100);}}}}
