Index: documentViewer.py
===================================================================
--- documentViewer.py	(revision 475)
+++ documentViewer.py	(revision 476)
@@ -583,5 +583,5 @@
             
         # odd pages are left
-        docinfo['oddPage'] = texttool.get('odd-scan-orientation', 'left')
+        docinfo['oddPage'] = texttool.get('odd-scan-position', 'left')
             
         # number of title page (0: not defined)
@@ -696,9 +696,8 @@
         grpsize = cols * rows
         pageinfo['groupsize'] = grpsize
-        # what does this do?
+        # is start is empty use one around current
         start = getInt(start, default=(math.ceil(float(current)/float(grpsize))*grpsize-(grpsize-1)))
         # int(current / grpsize) * grpsize +1))
         pageinfo['start'] = start
-        pageinfo['end'] = start + grpsize
         pn = self.REQUEST.get('pn','1')
         pageinfo['pn'] = pn
@@ -711,8 +710,14 @@
                 np = int(docinfo.get('numPages', 0))
                 
-        pageinfo['end'] = min(pageinfo['end'], np)
         pageinfo['numgroups'] = int(np / grpsize)
         if np % grpsize > 0:
             pageinfo['numgroups'] += 1
+
+        pageFlowLtr = docinfo.get('pageFlow', 'ltr') != 'rtl'
+        oddScanLeft = docinfo.get('oddPage', 'left') != 'right'
+        # add zeroth page for two columns
+        pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft))
+        pageinfo['pageZero'] = pageZero
+        pageinfo['pageList'] = self.getPageList(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
                 
         pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
@@ -721,15 +726,13 @@
         pageinfo['querySearch'] =self.REQUEST.get('querySearch', 'fulltext')
         pageinfo['highlightQuery'] = self.REQUEST.get('highlightQuery','')
-        pageinfo['tocPageSize'] = self.REQUEST.get('tocPageSize', '30')
-        pageinfo['queryPageSize'] =self.REQUEST.get('queryPageSize', '10')
-        pageinfo['tocPN'] = self.REQUEST.get('tocPN', '1')
-        # WTF?:
-        toc = int(pageinfo['tocPN'])
-        pageinfo['textPages'] = int(toc)
-        
-        # What does this do?
+        pageinfo['tocPageSize'] = getInt(self.REQUEST.get('tocPageSize', 30))
+        pageinfo['queryPageSize'] = getInt(self.REQUEST.get('queryPageSize', 10))
+        pageinfo['tocPN'] = getInt(self.REQUEST.get('tocPN', '1'))
+        pageinfo['searchPN'] = getInt(self.REQUEST.get('searchPN','1'))
+        
+        # limit tocPN
         if 'tocSize_%s'%tocMode in docinfo:
-            tocSize = int(docinfo['tocSize_%s'%tocMode])
-            tocPageSize = int(pageinfo['tocPageSize'])
+            tocSize = docinfo['tocSize_%s'%tocMode]
+            tocPageSize = pageinfo['tocPageSize']
             # cached toc           
             if tocSize%tocPageSize>0:
@@ -738,9 +741,40 @@
                 tocPages=tocSize/tocPageSize
                 
-            pageinfo['tocPN'] = min(tocPages,toc)
-            
-        pageinfo['searchPN'] =self.REQUEST.get('searchPN','1')
+            pageinfo['tocPN'] = min(tocPages,pageinfo['tocPN'])
+            
         return pageinfo
 
+
+    def getPageList(self, start=None, rows=None, cols=None, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
+        """returns array of page informations for one screenfull of thumbnails"""
+        if maxIdx == 0:
+            maxIdx = start + rows * cols
+
+        pages = []
+        if pageZero and start == 1:
+            # correct beginning
+            idx = 0
+        else:
+            idx = start
+            
+        for r in range(rows):
+            row = []
+            for c in range(cols):
+                if idx < minIdx or idx > maxIdx:
+                    page = {'idx':None}
+                else:
+                    page = {'idx':idx}
+                    
+                idx += 1
+                if pageFlowLtr:
+                    row.append(page)
+                else:
+                    row.insert(0, page) 
+                
+            pages.append(row)
+            
+        logging.debug("getPageList returns=%s"%(pages))
+        return pages
+        
 
     security.declareProtected('View management screens','changeDocumentViewerForm')    
