
//The Microsoft IE hack.  IE won't respond properly to 'hover' rules, so
//we add this code to use the same rule in another way.
function startList() {
  if (document.all&&document.getElementsById) {
    navRoot = document.getElementsById("nav");
    for (i=0; i<navRoot.childNodes.length; i++) {
      node = navRoot.childNodes[i];
      if (node.nodeName=="li") {
        node.onmouseover=function() {
          this.className+=" over";
        }
        node.onmouseout=function() {
          this.className=this.className.replace	(" over", "");
        }
      }
    }
  }
}




//generate the previous ... page n ... next links for a set of
//pages, given the parameters are predefined:
//myUrls should be an array of URL strings, with valid strings for elements 1 through pageCount
//pageCount should be the highest page number in the set
//pageNumber should be the current page number
//

function generateLinks()
{
  //Start with the next section link.
  var nextsectionTD = document.getElementById("nextsectionlink");
  if( nextsectionTD )
  {
    nextsectionTD.innerHTML = '<a class="next-section" href="'+nextSectionURL+'">'+nextSectionCaption+'</a>';
  }


  //Generate the string with the links, including the previous, current page, and next.
  var pageLinkString = "";

  //Make a previous link if this is not page 1, or even if it is and we are on a subpage (eg 1b).
  if( (pageNumber != 1) || (subpageNumber != 0) )
  {
    if( subpageNumber > 1 )
    {
      //Subpage b,c,e,etc, previous link is to the previous subpage.
      pageLinkString += '          <a href="'+mySubUrls[pageNumber][subpageNumber-1]+'" title="Go to previous page" class="active prevLink">&lt; Previous</a>\n';
    }
    else if( subpageNumber == 1 )
    {
      //Subpage a, previous link is to the current page, off the subpage
      pageLinkString += '          <a href="'+myUrls[pageNumber]+'" title="Go to previous page" class="active prevLink">&lt; Previous</a>\n';
    }
    else
    {
      //No subpage, we are on the page.
      if( mySubpageCounts[pageNumber-1] > 0 )
      {
        //Previous page has subpages, previous link is to last subpage of previous page.
        pageLinkString += '          <a href="'+mySubUrls[pageNumber-1][mySubpageCounts[pageNumber-1]]+'" title="Go to previous page" class="active prevLink">&lt; Previous</a>\n';
      }
      else
      {
        //Previous page has no subpages, previous link is to previous page.
        pageLinkString += '          <a href="'+myUrls[pageNumber-1]+'" title="Go to previous page" class="active prevLink">&lt; Previous</a>\n';
      }
    }
  }

  //Make all the page links, exclude a link for the current page.
  for( var i=1; i<=pageCount; i++ )
  {
    if( (i == pageNumber) && (subpageNumber == 0) )
    {
      //This page is not a link, just a number, if it is the current page.
      pageLinkString += '          <b>&nbsp;' + i + '&nbsp;</b>\n';
    }
    else
    {
      //This page is a link.
      pageLinkString += '          <a href="'+myUrls[i]+'" title="Go to page '+i+'" class="active">'+i+'</a>\n';
    }
  }

  //Make a next link if this is not the last page, or it is, and the last page has subpages.
  if( (pageNumber != pageCount) || ((mySubpageCounts[pageNumber] > 0) && (subpageNumber != mySubpageCounts[pageNumber])) )
  {
    if( subpageNumber > 0 )
    {
      //We are on a subpage.
      if( subpageNumber == mySubpageCounts[pageNumber] )
      {
        //We are on the last subpage of this page, next is the next page.
        pageLinkString += '          <a href="'+myUrls[pageNumber+1]+'" title="Go to next page" class="active nextLink">Next &gt;</a>\n';
      }
      else
      {
        //We are on a subpage and there are further subpages, next is next subpage.
        pageLinkString += '          <a href="'+mySubUrls[pageNumber][subpageNumber+1]+'" title="Go to next page" class="active nextLink">Next &gt;</a>\n';
      }
    }
    else
    {
      //We are on a main page.
      if( mySubpageCounts[pageNumber] > 0 )
      {
        //There are subpages on this page, next is first subpage.
        pageLinkString += '          <a href="'+mySubUrls[pageNumber][1]+'" title="Go to next page" class="active nextLink">Next &gt;</a>\n';
      }
      else
      {
        //There are no subpages on this page, next is next page.
        pageLinkString += '          <a href="'+myUrls[pageNumber+1]+'" title="Go to next page" class="active nextLink">Next &gt;</a>\n';
      }
    }
  }
  else
  {
        pageLinkString += '          <a class="prev-next" href="'+nextSectionURL+'">'+nextSectionCaption+'</a>';
  }

  //Emit the HTML for the above links, into the right Div element.
  var pageDiv = document.getElementById("pagelinks");
  pageDiv.innerHTML = pageLinkString;

  ///////this section generates the subpage links
  pageLinkString = "";
  for( var i=1; i<=mySubpageCounts[pageNumber]; i++ )
  {
    if( i == subpageNumber )
    {
      //This subpage is not a link, just a number, if it is the current page.
      pageLinkString += '          <b style="position: relative; left: '+((pageNumber+i)*4-15)+'px; top: 10px;">&nbsp;' + pageNumber+String.fromCharCode(97-1+i) + '&nbsp;</b>\n';
    }
    else
    {
      //Make the link to this subpage.
      pageLinkString += '          <a style="position: relative; left: '+((pageNumber+i)*4-15)+'px; top: 10px;" href="'+mySubUrls[pageNumber][i]+'" title="Go to subpage '+pageNumber+String.fromCharCode(97-1+i)+'" class="active">'+pageNumber+String.fromCharCode(97-1+i)+'</a>\n';
    }
  }

  //Emit the HTML for the above links, into the right Div element.
  pageDiv = document.getElementById("pagesublinks");
  pageDiv.innerHTML = pageLinkString;

  //This whole function is run during window.onload, so include the IE hack.
//  if (window.attachEvent) window.attachEvent("onload", startList);
  startList();
}

window.onload=generateLinks;



