// Copyright (c) 2001 Christopher M. Albrecht, Draigsffau Software
// P.O. Box 1007, Felton, California, USA, 95018
// http://draigsffau.com
// All rights reserved.

// Constants.
var pairFrame1;
var pairFrame2;

// Constructor for PagePair.
function PagePair( name, source1, source2 )
{
  this.name = name
  this.source1 = source1;
  this.source2 = source2;
}

// Page Sets.
var pageSet = new Array;
var pageSequence = new Array;

// State Variables.  Set to first PagePair in the pageSet.
var currentPairIndex = 0;
var currentPairSequence = false;

// Set frames to display pairs in.
function SetFramePair( frame1, frame2 )
{
  pairFrame1 = frame1;
  pairFrame2 = frame2;
}

// Add PagePair to pageSet or pageSequence.
function AddPagePair( pair, sequence )
{
  if( sequence == true )
    pageSequence[ pageSequence.length ] = pair;
  else
    pageSet[ pageSet.length ] = pair;
}

// Display a PagePair.
function ShowPagePair( pairName )
{
  var foundPair = false;

  // Determine which PagePair to show.
  if( pairName == "Reload" )
  {
      foundPair = true;
  }
  else if( currentPairSequence && pairName == "Next" )
  {
    if( currentPairIndex < pageSequence.length - 1 )
    {
      currentPairIndex++;
      foundPair = true;
    }
  }
  else if( currentPairSequence && pairName == "Previous" )
  {
    if( currentPairIndex > 1 )
    {
      currentPairIndex--;
      foundPair = true;
    }
  }
  else
  {
    for( i = 0; i < pageSet.length && !foundPair; i++ )
    {
      if( pageSet[i].name == pairName )
      {
        currentPairIndex = i;
        currentPairSequence = false;
        foundPair = true;
      }
    }
    for( i = 0; i < pageSequence.length && !foundPair; i++ )
    {
      if( pageSequence[i].name == pairName )
      {
        currentPairIndex = i;
        currentPairSequence = true;
        foundPair = true;
      }
    }
  }

  if( foundPair == true )
  {
    // Determine source locations.
    var location1;
    var location2;

    if( currentPairSequence )
    {
      location1 = pageSequence[ currentPairIndex ].source1;
      location2 = pageSequence[ currentPairIndex ].source2;
    }
    else
    {
      location1 = pageSet[ currentPairIndex ].source1;
      location2 = pageSet[ currentPairIndex ].source2;
    }

    // Show the PagePair.
    pairFrame1.location = location1;
    pairFrame2.location = location2;
  }
  return false; // Don't follow link, if any.
}
