// Copyright 2007-2012, Lorelle Ann Bell

// ISSUES:
//   Internationalization


var nMaxNavMain = 5;
var navArrayMain = [
   ['Home', 'The Glenburnie United Church home page'],
   ['Site Map', 'Map of entire web site'],
   ['Contact Us', 'Office hours, contact information, directions and About Us'],
   ['FAQ', 'Information about life, worship and the facilities at Glenburnie United Church'],
   ['Dates to Remember', 'Schedule of meetings and events for the next few weeks']]

//var nMaxNavSub = 12;
var nMaxNavSub = 11;
var navArraySub = [
   ['Bible Study', 'Study is guided by the lectionary readings'],
   ['Calling a New Minister', 'Describes the process leading to the call of a new minister'],
   ['External Pages', 'Links to websites for charities and church organizations'],
   ['History', 'History of the church in Glenburnie from the 18th century to the present'],
   ['Mission and Service', 'A brief description of the M&amp;S Fund and its support by the Bay of Quinte Conference'],
   ['Outreach', 'Describes Glenburnie United Church&#x27;s Outreach to the surrounding communities'],
   ['Pastoral Care', 'Information about pastoral care at Glenburnie United Church'],
   ['Pictures', 'Pictures of Glenburnie United Church, inside and out'],
   ['Special Events', 'Special events and fund raising'],
   ['UCW', 'General information for and about Glenburnie&#x27;s United Church Women'],
//   ['Weddings at GUC', 'Information about getting married at Glenburnie United Church'],
   ['Youth', 'General information for and about youth in Glenburnie'] ]


// Write a navigation array as a list.  The list is formatted with CSS.
// Parameters:  strArrayName:  the name of the appropriate navigation array
//              nThisPage:  the index in strArrayName of the page calling this function.
//              strClassForLastItem:  CSS class for last <li> element.
function writeNavArray(strArrayName, nThisPage, strClassForLastItem)
{
   var arrNav = new Array(nMaxNavSub);
   var nIndex = -1;
   var nMaxNav = -1;
   var nCount = 0;
   var strUpOneDir = "";
   var strSkipTo;
   var strPageName;
   var strFileName;
   var nLen = -1;
   var strTemp;
   var arrIndices = new Array();
   var nIdxIndices = -1;

   if (nThisPage == -2)
   {
      strUpOneDir = "../";
   }

   if(strArrayName.match('navArrayMain'))
   {
      for(nIndex = 0; nIndex < nMaxNavMain; nIndex++)
      {
         arrNav[nIndex] = new Array(2);
         arrNav[nIndex][0] = navArrayMain[nIndex][0];
         arrNav[nIndex][1] = navArrayMain[nIndex][1];
      }
      nMaxNav = nMaxNavMain;
      document.write('<ul><li><a href="#startDoc" title="Skip the main menu and go to the main content">Skip Navigation Links</a></li></ul>');
      document.write('<h4>Main Navigation Menu:</h4>');
   }
   else if(strArrayName.match('navArraySub'))
   {
      for(nIndex = 0; nIndex < nMaxNavSub; nIndex++)
      {
         arrNav[nIndex] = new Array(2);
         arrNav[nIndex][0] = navArraySub[nIndex][0];
         arrNav[nIndex][1] = navArraySub[nIndex][1];
      }
      nMaxNav = nMaxNavSub;
      document.write('<h4>Sub Navigation Menu</h4>');
      document.write('<ul>');
      document.write('<li>');
      document.write('<a href="#startDoc" title="Skip the submenu and go to the main content">Skip to content</a>');
      document.write('</li>');
      document.write('<li>');
      document.write('<a href="#combinedNav" title="Skip the submenu and go to the combined navigation menu at the bottom of the page">Skip to combined menu</a>');
      document.write('</li>');
      document.write('</ul>');
   }

   document.write('<ol>');

   for(nIndex = 0; nIndex < nMaxNav; nIndex++)
   {
      // Keep count so we know when we come to the last list item to be displayed.
      nCount++;

      // Write the displayed page's name in plain text to show it is not a link.
      if(nIndex == nThisPage)
      {
         if(nCount == nMaxNav)
         {
            // The last item in the list may need different formatting.
            // First check whether we have to add a space after the page name.
            if(arrIndices[nIdxIndices] == nIndex)
            {
               document.write('<li class="' + strClassForLastItem + '">' + arrNav[nIndex][0] + ' </li>');
            }
            else
            {
            document.write('<li class="' + strClassForLastItem + '">' + arrNav[nIndex][0] + '</li>');
            }
         }
         else
         {
            // First check whether we have to add a space after the page name.
            if(arrIndices[nIdxIndices] == nIndex)
            {
               document.write('<li>' + arrNav[nIndex][0] + ' </li>');
               nIdxIndices++;
            }
            else
            {
               // The first item in the combined navigation menu needs different treatment because it is the target of the jump to "combinedNav."
               if((strArrayName.match('navArrayCombined')) && (nIndex == 0))
               {
                  document.write('<li><a id="combinedNav" name="combinedNav">' + arrNav[nIndex][0] + '</a></li>');
               }
               else
               {
                  document.write('<li>' + arrNav[nIndex][0] + '</li>');
               }
            }
         }
      }
      else
      {
         // The Home page needs different treatment because it's file name is different than its title.
         if(arrNav[nIndex][0].match('Home'))
         {
            // The Home page's file name is different than its title.
            document.write('<li><a href="' + strUpOneDir + 'index.htm" title="' + arrNav[nIndex][1] + '">Home</a></li>');
         }
         else
         {
            // Create the the page's filename from the page title recorded in the navigation array.
            strPageName = arrNav[nIndex][0];
            strFileName = strPageName.replace(' ', '_');

            while(strFileName.search(/ /) != -1)
            {
               strFileName = strFileName.replace(' ', '_');
            }

            strPageName = strFileName.toLowerCase();
            strFileName = strUpOneDir + strPageName + '.htm';
            strPageName = arrNav[nIndex][0];

            if ((nCount == nMaxNav) && (strClassForLastItem != ''))
            {
               // The last item in the list may need different formatting.
               // First check whether we have to add a space after the page name.
               if(arrIndices[nIdxIndices] == nIndex)
               {
                  document.write('<li class="' + strClassForLastItem + '"><a href="' + strFileName + '" title="' + arrNav[nIndex][1] + '">' + strPageName + '</a> </li>');
                  nIdxIndices++;
               }
               else
               {
                  document.write('<li class="' + strClassForLastItem + '"><a href="' + strFileName + '" title="' + arrNav[nIndex][1] + '">' + strPageName + '</a></li>');
               }
            }
            else
            {
               // The first item in the combined navigation menu is also the target of the jump to "combinedNav."
               if((strArrayName.match('navArrayCombined')) && (nIndex == 0))
               {
                  document.write('<li><a id="combinedNav" name="combinedNav" href="' + strFileName + '" title="' + arrNav[nIndex][1] + '">' + strPageName + '</a></li>');
               }
               else
               {
                  // First check whether we have to add a space after the page name.
                  if(arrIndices[nIdxIndices] == nIndex)
                  {
                     document.write('<li><a href="' + strFileName + '" title="' + arrNav[nIndex][1] + '">' + strPageName + '</a> </li>');
                     nIdxIndices++;
                  }
                  else
                  {
                     document.write('<li><a href="' + strFileName + '" title="' + arrNav[nIndex][1] + '">' + strPageName + '</a></li>');
                  }
               }
            }
         }
      }
   } // end for loop

   document.write('</ol>');
}

function jumpToTopOrEnd()
{
   document.write('<ul>');

   document.write('<li>');
   document.write('<a href="#top" title="">Top of Page</a>');
   document.write('</li>');

   document.write('<li>');
   document.write('<a href="#combinedNav" title="">Combined Menu at End of Page</a>');
   document.write('</li>');

   document.write('</ul>');
}

