var galleriesJS = { photos : [], largeWidth : 130, largeHeight : 130, thumbWidth : 44, thumbHeight : 44, numThumbImages : 6, page : null, gid : 4, init : function() { this.photos.push("DSC_0049.JPG"); this.photos.push("DSC_0047.JPG"); this.photos.push("DSC_0060.JPG"); this.photos.push("DSC_0053.JPG"); if (this.photos.length > 0) { //write main photo var mainPhotoDiv = document.getElementById('mainPhotoDiv'); var mainPhotoImg = document.createElement('img'); mainPhotoImg.id = "mainPhotoImg"; mainPhotoImg.src = "/app/helpers/imgresize.php?w="+this.largeWidth+ "&h="+this.largeHeight+ "&img=/images/gallery_photos/large/"+this.gid+"/"+this.photos[0]; mainPhotoDiv.appendChild(mainPhotoImg); //write thumbnails this.writeThumbnails(); //write pager this.page = 1; if (this.photos.length > this.numThumbImages) this.writePageLinks(); } }, writeThumbnails : function(){ var thumbnailImages = document.getElementById('thumbnailImages'); while (thumbnailImages.hasChildNodes()) thumbnailImages.removeChild(thumbnailImages.firstChild); if (this.page > 1) var index = this.page * this.numThumbImages - (this.numThumbImages); else var index = 0; if (index+this.numThumbImages >= this.photos.length) var numThumbs = this.photos.length - index; else var numThumbs = index+this.numThumbImages; for (var i=index;i 1){ var prevSpan = document.createElement("span"); prevSpan.id = "prevSpan"; prevSpan.style.cssText = "float:left"; thumbnailPager.appendChild(prevSpan); var prevLink = document.createElement("a"); prevLink.href="#"; prevLink.appendChild(document.createTextNode("Previous")); prevLink.onclick = function() { galleriesJS.turnPage('prev'); }; prevSpan.appendChild(prevLink); } if (this.page * this.numThumbImages < this.photos.length){ var nextSpan = document.createElement("span"); nextSpan.id = "nextSpan"; nextSpan.style.cssText = "float:right"; thumbnailPager.appendChild(nextSpan); var nextLink = document.createElement("a"); nextLink.href="#"; nextLink.appendChild(document.createTextNode("Next")); nextLink.onclick = function() { galleriesJS.turnPage('next'); }; nextSpan.appendChild(nextLink); } }, showThumb : function(index) { var mainPhotoImg = document.getElementById('mainPhotoImg'); mainPhotoImg.src = "/app/helpers/imgresize.php?w="+this.largeWidth+ "&h="+this.largeHeight+ "&img=/images/gallery_photos/large/"+this.gid+"/"+this.photos[index]; }, turnPage : function(prevNext) { if (prevNext == "next") this.page++; else if (prevNext == "prev") this.page--; this.writeThumbnails(); this.writePageLinks(); return false; } }