Index: extensions/akBookStyle/trunk/js/ak_jquery-load.js
===================================================================
--- extensions/akBookStyle/trunk/js/ak_jquery-load.js	(revision 10853)
+++ extensions/akBookStyle/trunk/js/ak_jquery-load.js	(revision 10863)
@@ -1,53 +1,62 @@
-$(function () {
+$(function() {
     next_link = $('table.thumbnails div.navbar a[rel=next]');
-    if (next_link.length != 0) {
-        $('#akNextPicture').css('visibility', 'visible')
+    if (next_link.length!=0) {
+      $('#akNextPicture').css('visibility', 'visible');
     }
     previous_link = $('table.thumbnails div.navbar a[rel=previous]');
-    if (previous_link.length != 0) {
-        $('#akPreviousPicture').css('visibility', 'visible')
+    if (previous_link.length!=0) {
+      $('#akPreviousPicture').css('visibility', 'visible');
     }
-    $("a.load").bind(ak_mouse_event, function () {
-        $('table.thumbnails tr td.ncol').each(function () {
-            if ($(this).hasClass('selected')) {
-                $(this).removeClass('selected')
+    
+    $("a.load")
+      .bind(ak_mouse_event, function() {
+          $('table.thumbnails tr td.ncol').each(function() {
+              if ($(this).hasClass('selected')) {
+                $(this).removeClass('selected');
+              }
+            });
+
+	  $a = $(this);
+          next_thumbnail = $('table.thumbnails a[href='+$(this).attr('href')+']');          
+          if (next_thumbnail.length==0) {
+	    if ($a.attr('id')=='akNextPicture') {
+	      rel = 'next';
+	    } else {
+	      rel = 'previous';
+	    }
+            next_link = $('table.thumbnails div.navbar a[rel='+rel+']');
+            if (next_link.length!=0) {
+              window.location = next_link.attr('href');
             }
-        });
-        $a = $(this);
-        //next_thumbnail = $('table.thumbnails a[href=' + $(this).attr('href') + ']');
-        next_thumbnail = $('table.thumbnails a');
-        if (next_thumbnail.length == 0) {
-            if ($a.attr('id') == 'akNextPicture') {
-                rel = 'next'
-            } else {
-                rel = 'previous'
-            }
-            next_link = $('table.thumbnails div.navbar a[rel=' + rel + ']');
-            if (next_link.length != 0) {
-                window.location = next_link.attr('href')
-            }
-        } else {
+          } else {
             next_thumbnail.parent().parent().parent().addClass('selected');
-            try {
-                $.get($a.attr('href'), {}, function success(data) {
-											$('#akPicture').attr('src', data.AK_PIC_SRC).attr('alt', data.AK_PIC_ALT).attr('title', data.AK_PIC_TITLE);
-											$('.ak_pic a').attr('href', data.AK_PIC_URL);
-                    if (data.AK_PREVIOUS) {
-                        $('#akPreviousPicture').removeClass('hide').attr('href', data.AK_PREVIOUS)
-                    } else {
-                        $('#akPreviousPicture').addClass('hide')
-                    }
-                    if (data.AK_NEXT) {
-                        $('#akNextPicture').removeClass('hide').attr('href', data.AK_NEXT)
-                    } else {
-                        $('#akNextPicture').addClass('hide')
-                    }
-                    $a.click(function (e) {
-                        e.preventDefault()
-                    })
-                }, 'json')
-            } catch (e) {}
-        }
-        return false
-    })
-});
+	    try {
+	      $.get($a.attr('href'),{},
+		    function success(data) { 		    
+		      $('#akPicture')
+			.attr('src', data.AK_PIC_SRC)
+			.attr('alt', data.AK_PIC_ALT)
+			.attr('title', data.AK_PIC_TITLE);
+
+		      if (data.AK_PREVIOUS) {
+			$('#akPreviousPicture')
+			  .removeClass('hide')
+			  .attr('href', data.AK_PREVIOUS);
+		      } else {
+			$('#akPreviousPicture').addClass('hide');
+		      }
+		      if (data.AK_NEXT) {
+			$('#akNextPicture')
+			  .removeClass('hide')
+			  .attr('href', data.AK_NEXT);
+		      } else {
+			$('#akNextPicture').addClass('hide');
+		      }
+		      $a.click(function(e) { e.preventDefault();}); 
+		    },
+		    'json');	    
+	    } catch (e) {}
+          }
+	  return false;
+	});
+  });
