
//----------------------------------- Story Data -----------------------------------

 var stories = new Array(100);

 stories[0]  = "First Sighting 0001";
 stories[1]  = "";
 stories[2]  = "";
 stories[3]  = "";
 stories[4]  = "";
 stories[5]  = "";
 stories[6]  = "";
 stories[7]  = "";
 stories[8]  = "";
 stories[9]  = "";
 stories[10] = "";
 stories[11] = "";
 stories[12] = "";
 stories[13] = "";
 stories[14] = "";
 stories[15] = "";
 stories[16] = "";
 stories[17] = "";
 stories[18] = "";
 stories[19] = "";
 stories[20] = "";

//-------------------------------------- Setup --------------------------------------

 // Storage variables

 var next_story_URL, previous_story_URL, next_story_ALT, previous_story_ALT, story_title;

 // Temporary and working variables

 var index, filename, comic_num;

 // Find out what comic number we're on

 filename = document.location + "";
 comic_num = parseInt(filename.substr(filename.length-9, 4));

//----------------------------- Find the current chapter ----------------------------

 index = 0;
 complete = 0;

 while (!complete)
 {
   story_start = parseInt(stories[index].substr(stories[index].length-4, 4));
   story_end   = parseInt(stories[index+1].substr(stories[index+1].length-4, 4)) - 1;

   if (story_end == 0 || isNaN (story_end))   // This is just a precaution
     complete = 1;

   if (comic_num >= story_start && comic_num <= story_end)
     complete = 1;

   index++;
 } // of while

 index--;

//------------------------------- Store the title ------------------------------

 story_title = stories[index].substr(0, stories[index].length-5); 

//------------------------------- Store next chapter URL ------------------------------

 // Next story URL, if applicable

 if (stories[index+1] != "")
 {
   next_story_URL = stories[index+1].substr (stories[index+1].length-4, 4) + ".html"
   next_story_ALT = "Next chapter (" + stories[index+1].substr(0, stories[index+1].length-5) + ")";
 } 

 // There is no next story, so direct the URL to the index  

 else 
 {
   next_story_URL = "index.html";
   next_story_ALT = "Latest comic in this chapter";
 } // of if

//------------------------------- Store previous chapter URL ------------------------------

 // "Previous chapter"

 if (comic_num == story_start && index != 0)
 {
    previous_story_URL = stories[index-1].substr (stories[index-1].length-4, 4);
    previous_story_ALT = "Previous chapter (" + stories[index-1].substr(0, stories[index-1].length-5) + ")";
 }

 // "Beginning of this chapter" 

 else
 {
    previous_story_URL = stories[index].substr (stories[index].length-4, 4);
    previous_story_ALT = "Beginning of this chapter";
 } // of if
     
 // Add ".html" 

 previous_story_URL = previous_story_URL + ".html"

 // Report values (for test only)

// alert("Test data:" + '\n' + story_title + '\n' + previous_story_URL + '\n' + next_story_URL);

//------------------------------- Functions ------------------------------

function previous_chapter_button() {
   document.write("<td class='previous'><a href='" + previous_story_URL + "'><img src='images/ltw/previous_chapter.png' width='119' height='20' alt='" + previous_story_ALT + "' /></a></td>");
}

function next_chapter_button() {
   document.write("<td class='next'><a href='" + next_story_URL + "'><img src='images/ltw/next_chapter.png' width='99' height='20' alt='" + next_story_ALT + "' /></a></td>");
}
