$chapter){
    /* first store the chapter's full folder name */
    $chapter_list[$key]['folder']=$chapter;
    /* then parse the chapter name and number */
    parse_chapter_info($chapter,$chapter_list[$key]['name'],$chapter_list[$key]['number']);
  }
}
/* This function builds a list of the pages
   in the currently selected chapter. It is global
   just like the chapter list. */
function get_page_list($chapter){
  global $chapter_list,$page_list;
  /* all pages are files with the prefix "page-"
     followed by alphabetically correct numbers that
     ensure the pages will be sorted into the correct
     order. */
  $page_list=list_files($chapter_list[$chapter]['folder'],'/page-.*\.'.PAGE_FILE_TYPE.'/');
  sort($page_list);
}
/* This function examines a chapter folder name and
   extracts the chapter number and the chapter title */
function parse_chapter_info($file,&$name,&$number){
  /* strip the prefix and substitute spaces for
     underscores to generate the chapter name */
  $name=str_replace('_',' ',substr($file,4));
  /* convert the prefix into an integer to
     generate the chapter number */
  $number=(int)substr($file,0,3);
}
/* This function returns a string with the URL for
   a specified page and chapter */
function page_link($chapter,$page=0){
  return(sprintf('%s?chapter=%s&page=%s',$_SERVER['SCRIPT_NAME'],urlencode($chapter),urlencode($page)));
}
/* This function imports the chapter variable and
   ensures that it has a legal numeric value */
function sanity_check_chapter(&$chapter){
  if(isset($_REQUEST['chapter'])) $chapter=(int)$_REQUEST['chapter'];
  if(!is_numeric($chapter)) unset($chapter);
}
/* This function imports the page number variable
   and ensures that it has a legal numeric value */
function sanity_check_page(&$page){
  if(isset($_REQUEST['page'])) $page=(int)$_REQUEST['page'];
  if(!is_numeric($page)) $page=0;
}
/* This function returns a link to the next page, or an empty string if this is the last page */
function next_page_url($page, $chapter){
  global $chapter_list,$page_list;
  /* pre-calculate the last page and chapter */
  $last_chapter=sizeof($chapter_list)-1;
  $last_page=sizeof($page_list)-1;
  if($page<$last_page){
    /* when looking at any page except the last
       page, the link points to $page+1 */
    return page_link($chapter,$page+1);
  }else{
    /* when looking at the last page... */
    if($chapter<$last_chapter){
      /* when looking at the last page of any
         chapter except the last one, the link
         points to the first page of the next
         chapter */
      return page_link($chapter+1,0);
    }else{
      /* when looking at the last page of the last
         chapter, the link is not a link at all */
      return '';
    }
  }
}
/*-----------------------------------------------------*/
/* Output Functions                                    */
/* This function outputs a list of thumbnail images
   that link to the first page of each chapter */
function list_thumbnails(){
  global $chapter_list;
  foreach($chapter_list as $chapter_ID=>$chapter){
    printf(' '."\n"
           ,page_link($chapter_ID)
           ,$chapter['folder']
           ,THUMB_FILE_TYPE
           ,$chapter['number']
           ,$chapter['name']
           ,$chapter['number']
           ,$chapter['name'])
           ;
  }
}
/* this function outputs the index navigation */
function output_index_navigation(){
?>
Hamster Republic -> Bob's Graphic Novel
';
  $link_prev_disabled='
';
  $link_next='
';
  $link_next_disabled='
';
  /* now the previous-page link */
  if($page>0){
    /* when looking at any page but the first,
       the link points to $page-1 */
    printf('%s'."\n",page_link($chapter,$page-1),$link_prev);
  }else{
    /* when looking at the first page... */
    if($chapter>0){
      /* when looking at the first page of any
         chapter other than the first one, the
         link points to the last page of the
         previous chapter */
      printf('%s'."\n",page_link($chapter-1,-1),$link_prev);
    }else{
      /* when looking at the first page of the
         first chapter, the link is not a link
         at all */
      printf('%s'."\n",$link_prev_disabled);
    }
  }
  /* The index link is easy. It never changes. */
  printf('%s'."\n",$_SERVER['SCRIPT_NAME'],$link_index);
  /* output the next-page link */
  if($page<$last_page){
    /* when looking at any page except the last
       page, the link points to $page+1 */
    printf('%s'."\n",page_link($chapter,$page+1),$link_next);
  }else{
    /* when looking at the last page... */
    if($chapter<$last_chapter){
      /* when looking at the last page of any
         chapter except the last one, the link
         points to the first page of the next
         chapter */
      printf('%s'."\n",page_link($chapter+1,0),$link_next);
    }else{
      /* when looking at the last page of the last
         chapter, the link is not a link at all */
      printf('%s'."\n",$link_next_disabled);
    }
  }
  printf('%s
Once upon a time, there was a Hamster named Bob. He was the eldest of 144 siblings, all of whom were also named Bob (yes, even his sisters). He grew up a happy hamster child, starred in a few obscure computer games, started a revolution and founded his own country, saved the world from unspeakable evil once or twice, and finally decided to settle down and get a real job. Sound mundane? Well, nothing stays simple long in Bob's life.
New chapters are uploaded on a strict schedule of whenever-I-feel-like-it.