I'm building my first plugin for jquery and I'm stuck on a really weird problem. I'm building a lightbox image gallery that turns an xml doc into a gallery with minimal effort. I've got it almost complete and I've ran into a snag. The plugin generates a lightbox with image controls (prev and next methods).
Here is my bug: when the prev method is called after 1 or more next method calls, the obj loops prev the number of times that next was called (or however many images have been view this code execution. If this is unclear let me know and I'll try to explain it better. At any rate, below is the code that is needed. var galleryObj = { getActiveImageIndex: function() { for(x in galleryObj.images) { arrImage = galleryObj.images[x]; if(arrImage.src == galleryObj.currentSrc) { return Number(x); } } return false; }, next: function() { var activeIndex = galleryObj.getActiveImageIndex(); activeIndex++; var nextImage = galleryObj.images[activeIndex]; return galleryObj.getImage(nextImage.src); }, prev: function() { var activeIndex = galleryObj.getActiveImageIndex(); activeIndex--; var prevImage = galleryObj.images[activeIndex]; return galleryObj.getImage(prevImage.src); }, }; And below this I have something like this function setNavControls() { if ( !galleryObj.firstImage() ) { //set prev control only if not first image $("#nav-prev").show().bind('click', function() { galleryObj.prev(); return false; }); }else { //hide prev control $("#nav-prev").hide(); } if ( !galleryObj.lastImage() ) { //set next control only if not last image $("#nav-next").show().bind('click', function(){ galleryObj.next(); return false; }); }else { $("#nav-next").hide(); } } I really hope someone can help out. Thanks in advance