+var g_state = {
+ cache: [],
+ count: 0,
+ mousePos: { // Last known position of the mouse cursor
+ x: undefined,
+ y: undefined
+ },
+ first: 0,
+ ids: [],
+ last: (-1),
+ map: {}, // map from book.Id to index into cache[]
+ pageSize: 48,
+ tooltip: {
+ bookId: undefined,
+ milliSecs: 500, // time to wait before displaying tooltip
+ mousePos: {
+ x: undefined,
+ y: undefined
+ },
+ threshold: 10, // number of pixels that mouse can move before tip is dismissed
+ timer: undefined
+ }
+};
+
+document.onmousemove = onMouseMove;
+
+function adjustPos(setting) {
+ var value = parseInt(setting);
+
+ if (g_state.first === value) {
+ // No change
+ return;
+ }
+
+ var maxFirst = Math.max(0, g_state.count - g_state.pageSize);
+
+ if (value < 0) {
+ g_state.first = 0;
+ } else if (value > maxFirst) {
+ g_state.first = maxFirst;
+ } else {
+ g_state.first = value;
+ }
+
+ g_state.last = g_state.first + g_state.pageSize - 1;
+ if (g_state.last >= g_state.count) {
+ g_state.last = g_state.count - 1;
+ }
+
+ document.getElementById('slider').value = setting;
+
+ refreshData();
+}
+
+function bookHtml(book) {
+ var result = '<div class="book">'
+ + '<table>'
+ + '<tr>'
+ + '<td><a href="/book/' + book.Id + '">';
+ if (0 == book.CoverId) {
+ result += '(No cover available)';
+ } else {
+ result += '<img class="cover-thumb" src="/download/' + book.CoverId + '"/>';
+ }
+ result += '</a></td>'
+ + '<td onclick="displayDetails(' + book.Id + ');" '
+ + ' onmouseover="startTooltipTimer(' + book.Id + ');">'
+ + '<p><b>' + book.Title + '</b></p>'
+ + '<p>'
+ + '<i>' + book.AuthorReading + '</i>';
+ if (typeof(book.SeriesName) !== 'undefined' && book.SeriesName.length > 0) {
+ result += '<br/><i>' + book.SeriesName + ' ' + book.Volume + '</i>';
+ }
+ result += '</p>'
+ + '</td>'
+ + '</tr>'
+ + '</table>'
+ + '</div>';
+ return result;
+}
+
+//ce(s): "clear if empty()"
+//return s, unless it's undefined, in which case return an empty ("clear") string
+function ce(s) {
+ if (typeof s !== 'undefined') {
+ return s;
+ }
+ return '';