+// drawLeafsThumbnail()
+//______________________________________________________________________________
+GnuBook.prototype.drawLeafsThumbnail = function() {
+ //alert('drawing leafs!');
+ this.timer = null;
+
+
+ var scrollTop = $('#GBcontainer').attr('scrollTop');
+ var scrollBottom = scrollTop + $('#GBcontainer').height();
+ //console.log('top=' + scrollTop + ' bottom='+scrollBottom);
+
+ var indicesToDisplay = [];
+
+ var i;
+ var leafTop = 0;
+ var leafBottom = 0;
+ var viewHeight = 0;
+ var width = 0;
+ for (i=0; i<this.numLeafs; i++) {
+ var height = parseInt(this.getPageHeight(i)/this.thumbScale);
+
+ leafBottom += height;
+ //console.log('leafTop = '+leafTop+ ' pageH = ' + this.pageH[i] + 'leafTop>=scrollTop=' + (leafTop>=scrollTop));
+ var topInView = (leafTop >= scrollTop) && (leafTop <= scrollBottom);
+ var bottomInView = (leafBottom >= scrollTop) && (leafBottom <= scrollBottom);
+ var middleInView = (leafTop <=scrollTop) && (leafBottom>=scrollBottom);
+ if (topInView | bottomInView | middleInView) {
+ //console.log('displayed: ' + this.displayedIndices);
+ //console.log('to display: ' + i);
+ indicesToDisplay.push(i);
+ }
+ leafTop += height +10;
+ leafBottom += 10;
+ }
+
+ var firstIndexToDraw = indicesToDisplay[0];
+ this.firstIndex = firstIndexToDraw;
+
+ // Update hash, but only if we're currently displaying a leaf
+ // Hack that fixes #365790
+ if (this.displayedIndices.length > 0) {
+ this.updateLocationHash();
+ }
+
+ if ((0 != firstIndexToDraw) && (1 < this.reduce)) {
+ firstIndexToDraw--;
+ indicesToDisplay.unshift(firstIndexToDraw);
+ }
+
+ var lastIndexToDraw = indicesToDisplay[indicesToDisplay.length-1];
+ if ( ((this.numLeafs-1) != lastIndexToDraw) && (1 < this.reduce) ) {
+ indicesToDisplay.push(lastIndexToDraw+1);
+ }
+
+ leafTop = 0;
+ var i;
+ for (i=0; i<firstIndexToDraw; i++) {
+ leafTop += parseInt(this.getPageHeight(i)/this.thumbScale) +10;
+ }
+
+ //var viewWidth = $('#GBpageview').width(); //includes scroll bar width
+ var viewWidth = $('#GBcontainer').attr('scrollWidth');
+
+
+ for (i=0; i<indicesToDisplay.length; i++) {
+ var index = indicesToDisplay[i];
+ var height = parseInt(this.getPageHeight(index)/this.thumbScale);
+
+ if(-1 == jQuery.inArray(indicesToDisplay[i], this.displayedIndices)) {
+ var width = parseInt(this.getPageWidth(index)/this.thumbScale);
+ //console.log("displaying leaf " + indicesToDisplay[i] + ' leafTop=' +leafTop);
+ var div = document.createElement("div");
+ div.className = 'GBpagediv1up';
+ div.id = 'pagediv'+index;
+ div.style.position = "absolute";
+ $(div).css('top', leafTop + 'px');
+ var left = (viewWidth-width)>>1;
+ if (left<0) left = 0;
+ $(div).css('left', left+'px');
+ $(div).css('width', width+'px');
+ $(div).css('height', height+'px');
+ //$(div).text('loading...');
+
+ // thumbnails are hyperlinked, do not need drag handler
+ //this.setDragHandler(div);
+
+ // link to page in single page mode
+ var link = document.createElement("a");
+ link.href = '#page/' + (this.getPageNum(index)) +'/mode/1up' ;
+ $(div).append(link);
+
+ $('#GBpageview').append(div);
+
+ var img = document.createElement("img");
+ img.src = this.getPageURI(index);
+ $(img).css('width', width+'px');
+ $(img).css('height', height+'px');
+ img.style.border = "0";
+ $(link).append(img);
+
+
+ } else {
+ //console.log("not displaying " + indicesToDisplay[i] + ' score=' + jQuery.inArray(indicesToDisplay[i], this.displayedIndices));
+ }
+
+ leafTop += height +10;
+
+ }
+
+ for (i=0; i<this.displayedIndices.length; i++) {
+ if (-1 == jQuery.inArray(this.displayedIndices[i], indicesToDisplay)) {
+ var index = this.displayedIndices[i];
+ //console.log('Removing leaf ' + index);
+ //console.log('id='+'#pagediv'+index+ ' top = ' +$('#pagediv'+index).css('top'));
+ $('#pagediv'+index).remove();
+ } else {
+ //console.log('NOT Removing leaf ' + this.displayedIndices[i]);
+ }
+ }
+
+ this.displayedIndices = indicesToDisplay.slice();
+ this.updateSearchHilites();
+
+ if (null != this.getPageNum(firstIndexToDraw)) {
+ $("#GBpagenum").val(this.getPageNum(this.currentIndex()));
+ } else {
+ $("#GBpagenum").val('');
+ }
+
+ this.updateToolbarZoom(this.reduce);
+
+}
+