From af79398598673c42fbb2d792d3767e5799b7e67d Mon Sep 17 00:00:00 2001
From: Liem Khuu <liem@imagewks.com>
Date: Tue, 21 Aug 2012 13:26:07 -0400
Subject: [PATCH 2/2] fixed next button does not always work with certain
 numbers of thumbnails. Also simplified some of the
 showNext and showPrevious selector.

---
 theme/galleryformatter.js |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/theme/galleryformatter.js b/theme/galleryformatter.js
index c28248e..6b6cbf8 100644
--- a/theme/galleryformatter.js
+++ b/theme/galleryformatter.js
@@ -77,7 +77,7 @@ Drupal.galleryformatter.prepare = function(el) {
 
     function showFirstSlide(){
       // Activate the first slide
-      $('a', $thumbsLi.filter('.slide-0:not("cloned")')).trigger('click');
+      $('a', $thumbsLi.filter('.slide-0:not(".cloned")')).trigger('click');
      }
 
     // if we have a hash in the url
@@ -106,7 +106,7 @@ Drupal.galleryformatter.prepare = function(el) {
     // Shows the previous slide and scrolls to the previous page if necessary
     $thumbs.bind('showPrev', function (event) {
       var currentScroll = $wrapper.get(0).scrollLeft;
-      var $prevThumbLi = $thumbsLi.filter('.active').prevAll().not('.cloned, .empty, .active').filter(':first');
+      var $prevThumbLi = $thumbsLi.filter('.active').prev(':not(".cloned, .empty, .active")');
       // if no results we are on the first element
       if(!$prevThumbLi.size()) {
         // select the last one
@@ -126,7 +126,7 @@ Drupal.galleryformatter.prepare = function(el) {
     $thumbs.bind('showNext', function (event) {
       var currentScroll = $wrapper.get(0).scrollLeft;
       // this selector could be optimized perhaps, but
-      var $nextThumbLi = $thumbsLi.filter('.active').nextAll().not('.cloned, .empty, .active').filter(':first');
+      var $nextThumbLi = $thumbsLi.filter('.active').next(':not(".cloned, .empty, .active")');
       // if no results we are on the last element
       if(!$nextThumbLi.size()) {
         // select the first one
-- 
1.7.5.4

