// An attempt to make a generalized JavaScript comic page viewer
// Created by James Burns 

//global variables
// stick HTML into variables for convenience

var tableStart="<table width='400'><tr>";
var tableEnd="</tr></table>";

// now the functions
// Set up variables and utility routines

// Generalized routine to pad out single digit numbers

function padNum(thingie){
if (thingie < 10) {
	return "0" + thingie;
}else{
	return thingie;
	}
}

function checkIt(){
// If we got here without the page number being set...

if (!location.search){
page= 1;
	}else{
//get page from URL
page=location.search.substr(1).split("?");
}
//check to make sure it isn't a funny number, or not a number...
if ((page > numberOfPages)||(page < 0)||(!Number(page)))
{
page= 1;
}
// turn it into a 0 padded number
//alert(page);
page=padNum(page);
}

function getPage(page){
var filename = imagePath + page + ".jpg";
document.getElementById('comic').innerHTML=("<a href='' onClick='forward(); return false'><img src=" + filename + " border='0' name='strip' alt='comic image' /></a>");

}

// first, make functions to go forward or back

var forward= function(){
page = ++page;
location.href = file + "?" + page;
}

var back= function(){
page = --page;
location.href = file + "?" + page;
}

// Write navigation line

function headerFooter(page){

// these will be used for both header and footer navigation

var goForward = '<td  class="nav" align ="left"><a href="" onClick="forward(); return false" > Next</a></td>';
var goBack = '<td class="nav"><a href="" onClick="back(); return false;"> Back</a></td>';
var backFirst ='<td  class="nav" align="right"><a href=' + file + '> First</a></td>';

if (page == "01"){
bottomRow = goForward + backFirst ;
}
// if page is equal or greater than total number

else if (page == numberOfPages) {
bottomRow= goBack + backFirst;

}else { // if the page number is less than the total number but more than 1
bottomRow = goForward + goBack + backFirst;

}
return (tableStart + bottomRow + tableEnd);
}

// Write the title for the header section

function headerTitle(page) {

title = '<td align ="left"><h2>'+ comicName +"</h2></td>";
title += '<td class="page" align ="right">Page ' + page +  ' of ' + numberOfPages + '</td>';
document.getElementById('header').innerHTML= (tableStart + title +tableEnd);
}

function copyright(){
document.getElementById('copyright').innerHTML="<p class='copyright'>Copyright &copy; 2008 by James Burns, All rights reserved.</p>";
}