Index: /extensions/rv_tscroller/main.inc.php
===================================================================
--- /extensions/rv_tscroller/main.inc.php	(revision 13193)
+++ /extensions/rv_tscroller/main.inc.php	(revision 13194)
@@ -1,5 +1,5 @@
 <?php /*
 Plugin Name: RV Thumb Scroller
-Version: 2.3.d
+Version: 2.4.a
 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=493
 Description: Loads async using ajax thumbnails on index page as you scroll down the page
@@ -7,5 +7,5 @@
 Author URI: http://www.modusoptimus.com
 */
-define('RVTS_VERSION', '2.3.d');
+define('RVTS_VERSION', '24a');
 
 class RVTS
@@ -14,9 +14,8 @@
 {
 	global $page;
-	if (!@$page['start'])
+	$page['nb_image_page'] *= pwg_get_session_var('rvts_mult', 1);
+	if (count($page['items'])<$page['nb_image_page']+3)
 	{
-		if (script_basename()!='picture')
-			$page['nb_image_page'] *= pwg_get_session_var('rvts_mult', 1);
-		if (count($page['items'])<$page['nb_image_page']+3)
+		if (!@$page['start'] || script_basename()=='picture')
 			$page['nb_image_page'] = max($page['nb_image_page'], count($page['items']));
 	}
@@ -30,5 +29,5 @@
 	if (!$is_ajax)
 	{
-		if (empty($page['items']) || @$page['start']>0)
+		if (empty($page['items']))
 			add_event_handler('loc_end_index', array('RVTS','on_end_index'));
 		else
@@ -63,5 +62,4 @@
 		return $thumbs;
 	}
-	$per_page = $page['nb_image_page'];
 	$url_model = str_replace('123456789', '%start%', duplicate_index_url( array('start'=>123456789) ) );
 	$ajax_url_model = add_url_params($url_model, array( 'rvts'=>'%per%' ) );
@@ -84,4 +82,6 @@
 			'version' => RVTS_VERSION,
 		), $template->smarty);
+  $start = (int)$page['start'];
+	$per_page = $page['nb_image_page'];
 	$moreMsg = 'See the remaining %d photos';
 	if ('en' != $GLOBALS['lang_info']['code'])
@@ -95,9 +95,11 @@
 		"var RVTS = {
 ajaxUrlModel: String.fromCharCode(".ord($ajax_url_model[0]).")+'".substr($ajax_url_model,1)."',
-start: $per_page,
+start: $start,
+perPage: $per_page,
+next: ".($start+$per_page).",
 total: $total,
-perPage: $per_page,
 moreUrlModel: String.fromCharCode(".ord($url_model[0]).")+'".substr($url_model,1)."',
 moreMsg: '$moreMsg',
+prevMsg: '".l10n("Previous")."',
 ajaxLoaderImage: '$ajax_loader_image'
 };",
@@ -140,4 +142,3 @@
 
 add_event_handler('loc_end_section_init', array('RVTS','on_end_section_init'));
-
 ?>
Index: /extensions/rv_tscroller/rv_tscroller.js
===================================================================
--- /extensions/rv_tscroller/rv_tscroller.js	(revision 13193)
+++ /extensions/rv_tscroller/rv_tscroller.js	(revision 13194)
@@ -5,12 +5,46 @@
 (function($){
 $('.navigationBar').hide();
+if (RVTS.start>0) {
+	var $f = $('.navigationBar A[rel=first]');
+	var f = '<a href="'+$f.attr("href")+'">'+$f.html()+'</a> | ';
+	$('#thumbnails').before( '<div id=rvtsUp style="text-align:center;font-size:120%;margin:10px">'+f+'<a href="javascript:RVTS.loadUp()">'+RVTS.prevMsg+"</a></div>" );
+}
 
 RVTS = $.fn.extend( RVTS, {
 loading: 0,
+loadingUp: 0,
 adjust: 0,
 
+loadUp: function() {
+	if (RVTS.loadingUp || RVTS.start <= 0) return;
+	var newStart = RVTS.start-RVTS.perPage,
+		reqCount = RVTS.perPage;
+	if (newStart<0)
+	{
+		reqCount += newStart;
+		newStart = 0;
+	}
+	var url = RVTS.ajaxUrlModel.replace('%start%', newStart).replace('%per%', reqCount);
+	$('#ajaxLoader').show();
+	RVTS.loadingUp = 1;
+	$.ajax({
+		type:'GET', dataType:'html', 'url': url,
+		success: function(htm) {
+			RVTS.start = newStart;
+			RVTS.$thumbs.prepend(htm);
+			if (RVTS.start<=0)
+				$("#rvtsUp").remove();
+		},
+		complete: function() {
+			RVTS.loadingUp = 0;
+			RVTS.loading || $('#ajaxLoader').hide();
+			$(window).trigger('RVTS_loaded');
+			}
+		});
+},
+
 doAutoScroll: function() {
-	if (RVTS.loading || RVTS.start >= RVTS.total) return;
-	var url = RVTS.ajaxUrlModel.replace('%start%', RVTS.start).replace('%per%', RVTS.perPage);
+	if (RVTS.loading || RVTS.next >= RVTS.total) return;
+	var url = RVTS.ajaxUrlModel.replace('%start%', RVTS.next).replace('%per%', RVTS.perPage);
 	if (RVTS.adjust) {
 		url += '&adj=' + RVTS.adjust;
@@ -22,11 +56,11 @@
 		type:'GET', dataType:'html', 'url': url,
 		success: function(htm) {
-			RVTS.start+=RVTS.perPage;
+			RVTS.next+=RVTS.perPage;
 			RVTS.$thumbs.append(htm);
-			if (RVTS.start>500 && RVTS.total>550) {
+			if (RVTS.next-RVTS.start>500 && RVTS.total-RVTS.next>50) {
 				RVTS.$thumbs.after(
 					'<div style="text-align:center;font-size:180%;margin:0 0 20px"><a href="'
-					+RVTS.moreUrlModel.replace('%start%', RVTS.start)+'">'
-					+RVTS.moreMsg.replace('%d', RVTS.total-RVTS.start)
+					+RVTS.moreUrlModel.replace('%start%', RVTS.next)+'">'
+					+RVTS.moreMsg.replace('%d', RVTS.total-RVTS.next)
 					+'</a></div>');
 				RVTS.total = 0;
@@ -35,5 +69,5 @@
 		complete: function() {
 			RVTS.loading = 0;
-			$('#ajaxLoader').hide();
+			RVTS.loadingUp || $('#ajaxLoader').hide();
 			$(window).trigger('RVTS_loaded');
 			}
@@ -51,5 +85,5 @@
 	var $w = $(window);
 	RVTS.$thumbs = $('#thumbnails');
-	RVTS.$thumbs.append('<div id="ajaxLoader" style="display:none;position:fixed;bottom:32px;right:1%;z-index:999"><img src="'+ RVTS.ajaxLoaderImage + '" width="128" height="15" alt="~"></div>');
+	RVTS.$thumbs.after('<div id="ajaxLoader" style="display:none;position:fixed;bottom:32px;right:1%;z-index:999"><img src="'+ RVTS.ajaxLoaderImage + '" width="128" height="15" alt="~"></div>');
 
 	$w.scrollTop(0);
Index: /extensions/rv_tscroller/rv_tscroller.min.js
===================================================================
--- /extensions/rv_tscroller/rv_tscroller.min.js	(revision 13193)
+++ /extensions/rv_tscroller/rv_tscroller.min.js	(revision 13194)
@@ -1,2 +1,2 @@
-window.jQuery&&window.RVTS&&function(a){a(".navigationBar").hide();RVTS=a.fn.extend(RVTS,{loading:0,adjust:0,doAutoScroll:function(){if(!(RVTS.loading||RVTS.start>=RVTS.total)){var b=RVTS.ajaxUrlModel.replace("%start%",RVTS.start).replace("%per%",RVTS.perPage);if(RVTS.adjust)b+="&adj="+RVTS.adjust,RVTS.adjust=0;a("#ajaxLoader").show();RVTS.loading=1;a.ajax({type:"GET",dataType:"html",url:b,success:function(a){RVTS.start+=RVTS.perPage;RVTS.$thumbs.append(a);if(500<RVTS.start&&550<RVTS.total)RVTS.$thumbs.after('<div style="text-align:center;font-size:180%;margin:0 0 20px"><a href="'+ RVTS.moreUrlModel.replace("%start%",RVTS.start)+'">'+RVTS.moreMsg.replace("%d",RVTS.total-RVTS.start)+"</a></div>"),RVTS.total=0},complete:function(){RVTS.loading=0;a("#ajaxLoader").hide();a(window).trigger("RVTS_loaded")}})}},
-checkAutoScroll:function(b){var c=RVTS.$thumbs.position().top+RVTS.$thumbs.outerHeight(),d=a(window).scrollTop()+a(window).height();return c-(!b?0:100)<=d?(RVTS.doAutoScroll(),1):0},engage:function(){var b=a(window);RVTS.$thumbs=a("#thumbnails");RVTS.$thumbs.append('<div id="ajaxLoader" style="display:none;position:fixed;bottom:32px;right:1%;z-index:999"><img src="'+ RVTS.ajaxLoaderImage+'" width="128" height="15" alt="~"></div>');b.scrollTop(0);if(RVTS.$thumbs.outerHeight()<b.height())RVTS.adjust=1;else if(RVTS.$thumbs.height()>2*b.height())RVTS.adjust=-1;b.bind("scroll resize",RVTS.checkAutoScroll);RVTS.checkAutoScroll()&&window.setTimeout(RVTS.checkAutoScroll,1500)}});a(document).ready(function(){window.setTimeout(RVTS.engage,250)})}(jQuery);
+window.jQuery&&window.RVTS&&function(a){a(".navigationBar").hide();if(0<RVTS.start){var d=a(".navigationBar A[rel=first]"),d='<a href="'+d.attr("href")+'">'+d.html()+"</a> | ";a("#thumbnails").before('<div id=rvtsUp style="text-align:center;font-size:120%;margin:10px">'+d+'<a href="javascript:RVTS.loadUp()">'+RVTS.prevMsg+"</a></div>")}RVTS=a.fn.extend(RVTS,{loading:0,loadingUp:0,adjust:0,loadUp:function(){if(!(RVTS.loadingUp||0>=RVTS.start)){var b=RVTS.start-RVTS.perPage,c=RVTS.perPage;0>b&&(c+= b,b=0);c=RVTS.ajaxUrlModel.replace("%start%",b).replace("%per%",c);a("#ajaxLoader").show();RVTS.loadingUp=1;a.ajax({type:"GET",dataType:"html",url:c,success:function(c){RVTS.start=b;RVTS.$thumbs.prepend(c);0>=RVTS.start&&a("#rvtsUp").remove()},complete:function(){RVTS.loadingUp=0;RVTS.loading||a("#ajaxLoader").hide();a(window).trigger("RVTS_loaded")}})}},
+doAutoScroll:function(){if(!(RVTS.loading||RVTS.next>=RVTS.total)){var b=RVTS.ajaxUrlModel.replace("%start%",RVTS.next).replace("%per%",RVTS.perPage); RVTS.adjust&&(b+="&adj="+RVTS.adjust,RVTS.adjust=0);a("#ajaxLoader").show();RVTS.loading=1;a.ajax({type:"GET",dataType:"html",url:b,success:function(a){RVTS.next+=RVTS.perPage;RVTS.$thumbs.append(a);500<RVTS.next-RVTS.start&&50<RVTS.total-RVTS.next&&(RVTS.$thumbs.after('<div style="text-align:center;font-size:180%;margin:0 0 20px"><a href="'+RVTS.moreUrlModel.replace("%start%",RVTS.next)+'">'+RVTS.moreMsg.replace("%d",RVTS.total-RVTS.next)+"</a></div>"),RVTS.total=0)},complete:function(){RVTS.loading= 0;RVTS.loadingUp||a("#ajaxLoader").hide();a(window).trigger("RVTS_loaded")}})}},checkAutoScroll:function(b){var c=RVTS.$thumbs.position().top+RVTS.$thumbs.outerHeight(),d=a(window).scrollTop()+a(window).height();return c-(!b?0:100)<=d?(RVTS.doAutoScroll(),1):0},engage:function(){var b=a(window);RVTS.$thumbs=a("#thumbnails");RVTS.$thumbs.after('<div id="ajaxLoader" style="display:none;position:fixed;bottom:32px;right:1%;z-index:999"><img src="'+RVTS.ajaxLoaderImage+'" width="128" height="15" alt="~"></div>'); b.scrollTop(0);RVTS.$thumbs.outerHeight()<b.height()?RVTS.adjust=1:RVTS.$thumbs.height()>2*b.height()&&(RVTS.adjust=-1);b.bind("scroll resize",RVTS.checkAutoScroll);RVTS.checkAutoScroll()&&window.setTimeout(RVTS.checkAutoScroll,1500)}});a(document).ready(function(){window.setTimeout(RVTS.engage,250)})}(jQuery);
