var MAX_COMIC_ID = 24;
var filePrefix = "/images/comics/comic";
var extension = ".gif";

var pageURL = document.location.href;

var comicsPics = new Array( MAX_COMIC_ID );
var comicsTexts = new Array( MAX_COMIC_ID );
var comicsChapter = new Array( 1 );
comicsChapter[ 0 ] = MAX_COMIC_ID;

var comicID = MAX_COMIC_ID;

window.onload=loadComic;

function initArray( setComicID )
{
  var currComicChp = 1;
  var currComicIssue = 1;
  for( i = 0; i < MAX_COMIC_ID; i++ ){
    if( comicsChapter[ currComicChp - 1 ] == i ){
      currComicChp = currComicChp + 1;
      currComicIssue = 1;
    }
    comicsTexts[ i ] = "Chapter ".concat( currComicChp );
    comicsTexts[ i ] = comicsTexts[ i ].concat( ", Issue #" );
    comicsTexts[ i ] = comicsTexts[ i ].concat( currComicIssue );
    currComicIssue = currComicIssue + 1;
  }
  if( setComicID > 0 ){
    comicID = setComicID;
  }
}

function loadComic( )
{
  initArray;
  document.comicImage.src = getCurrComicPicURL( );
}

function getCurrComicPicURL( )
{
  return filePrefix.concat( comicID ).concat( extension );
}

function updateNextPrevImage( )
{
  document.comicImage.src = getCurrComicPicURL( );
  document.getElementById("archivesMenu").selectedIndex = comicID - 1;
}

function prevComic( )
{
  if( comicID > 1 ){
    comicID = comicID - 1;
  }
  else{
    comicID = MAX_COMIC_ID;
  }
  updateNextPrevImage( );
}

function nextComic( )
{
  if( comicID < MAX_COMIC_ID ){
    comicID = comicID + 1;
  }
  else{
    comicID = 1;
  }
  updateNextPrevImage( );
}

function displayMenuSelectedComic( )
{
  comicID = document.getElementById("archivesMenu").selectedIndex + 1;
  document.comicImage.src = getCurrComicPicURL( );
}

function loadDropMenu()
{
  this.document.write( '<select id="archivesMenu" onchange="displayMenuSelectedComic()">' );
  var str;
  for( i = 0; i < MAX_COMIC_ID; i++ ){
    str = '<option value="' + i + '"';
    if( i == 0 ){
      str = str + 'selected';
    }
    str = str + '>' + comicsTexts[ i ] + '</option>';
    this.document.write( str );
  }
  this.document.write( '</select>' );
}

function writeLine( string )
{
  this.document.writeln( string );
}

function write( string )
{
  this.document.write( string );
}


