/* --------------- STUDIO CONNECTIONS EXTERNAL JAVASCRIPT FILE -------------- */
/*                                                                            */
/*    Description: Navigation Bar generator                                   */
/*         Author: Colin Abrahams - colin@studioconnections.net.au            */
/*      Copyright: Colin Abrahams, Studio Connections                         */
/*       Location: Central Coast, NSW, Australia                              */
/*        Version: SC-5.8                                                     */
/*   Last Updated: 03-11-2010                                                 */


if (document.links && top.BSFind) {
  PageAd = document.location.href;
  SubMenu = null;

  // Look through frames
  for (var f = 0; f < top.frames.length && !SubMenu; f++) {

    // By-pass Main frame to save time
    if (top.frames[f].name == "Main") {
      continue;
    }

    // Check links within current frame
    BTList = top.frames[f].document.links;
    for (var i = 0; i < BTList.length; i++) {

      if (BTList[i].target == "Main" &&
        escape(PageAd).indexOf(escape(BTList[i].href)) != -1) {
        CurrPg = BTList[i];

        // Find submenu for current page
        SubMenu = top.BSFind(BTList[i]);
        if (!SubMenu) {
          break;
        }

        // Find contents page
        for (var j = 0; j <= i && top.BSFind(BTList[i - j]) == SubMenu; j++) {
          ContPg = BTList[i - j];
          ContNo = i - j;
        }

        // Find previous page
        if (i > ContNo + 1) {
          PrevPg = BTList[i - 1];
        }

        // Find next page
        if (i < BTList.length - 1 && top.BSFind(BTList[i + 1]) == SubMenu) {
          NextPg = BTList[i + 1];
        }

        document.write('<div class="NavBar"><div class="NavGuts">');

        // Navigation info generated for top NavBar only
        if (window.ContPg && !window.PgName) {

          // Extract page title from document title.  Standard SC format:
          // websitename +  " - " + sectionname +  " - " + pagename
          h = document.title.lastIndexOf(" - ");
          PgName = h > 0 ? document.title.substr(h + 3) : document.title;

          // Generate link to contents page and display page title
          document.write('<div class="NavInfo"><small>'
            + '<a href="' + ContPg.href + '" '
            + 'title="Go to ' + ContPg.title + ' Contents Page" '
            + 'onmouseout ="window.BTOut ? BTOut(this) : null" '
            + 'onmouseover="window.BTSel ? BTSel(this) : null" '
            + 'onmousedown="window.BTDep ? BTDep(this) : null" '
            + 'onclick="a = window.BTClick ? BTClick(this) : null; '
            + 'this.className=\'Act\'; return a"');
          if (ContPg == CurrPg) {
            document.write(' class="Act"');
          }
          document.write('><span>' + ContPg.title + '</span></a>'
            + '<span class="NavArrow">&nbsp;&#187;&nbsp;</span>'
            + '<span class="NavPage">' + PgName + '</span>'
            + '</small></div><hr>');
        }
        
        // Navigation menu
        document.write('<div align="right" class="NavMenu"><small>'
          + '<div class="NavFill">&nbsp;</div>');

        // Link to previous page
        if (window.PrevPg) {
          document.write('<span class="NavButton"><a href="'
            + PrevPg.href + '" ' + 'title="' + PrevPg.title + '" '
            + 'onmouseout ="window.BTOut ? BTOut(this) : null" '
            + 'onmouseover="window.BTSel ? BTSel(this) : null" '
            + 'onmousedown="window.BTDep ? BTDep(this) : null" '
            + 'onclick="return window.BTClick ? BTClick(this) : true">'
            + '<span class="Span1"><span class="Span2">'
            + 'Prev</span></span></a></span>'
            + '<span class="NavSep"> | </span>');
        }

        // Link to contents page
        if (window.ContPg) {
          document.write('<span class="NavItem"><a href="'
            + ContPg.href + '" '
            + 'title="Go to ' + ContPg.title + ' Contents Page" '
            + 'onmouseout ="window.BTOut ? BTOut(this) : null" '
            + 'onmouseover="window.BTSel ? BTSel(this) : null" '
            + 'onmousedown="window.BTDep ? BTDep(this) : null" '
            + 'onclick="a = window.BTClick ? BTClick(this) : null; '
            + 'this.className=\'Act\'; return a"');
          if (ContPg == CurrPg) {
            document.write(' class="Act"');
          }
          document.write('><span class="Span1">'
            + '<span class="Span2">Intro</span></span></a></span>'
            + '<span class="NavSep"> | </span>');
        }

        // Links to individual pages
        for (var k = ContNo + 1; top.BSFind(BTList[k]) == SubMenu; k++) {
          if (k > ContNo + 1) {
            document.write('<span class="NavSep"> | </span>');
          }
          PageNo = k - ContNo;
          document.write('<span class="NavItem"><a href="'
            + BTList[k].href  + '" ' + 'title="' + BTList[k].title + '" '
            + 'onmouseout ="window.BTOut ? BTOut(this) : null" '
            + 'onmouseover="window.BTSel ? BTSel(this) : null" '
            + 'onmousedown="window.BTDep ? BTDep(this) : null" '
            + 'onclick="a = window.BTClick ? BTClick(this) : null; '
            + 'this.className=\'Act\'; return a"');
          if (BTList[k] == CurrPg) {
            document.write(' class="Act"');
          }
          document.write('><span class="Span1"><span class="Span2">'
            + PageNo + '</span></span></a></span>');
        }

        // Link to next page
        if (window.NextPg) {
          document.write('<span class="NavSep"> | </span>'
            + '<span class="NavButton"><a href="'
            + NextPg.href + '" ' + 'title="' + NextPg.title + '" '
            + 'onmouseout ="window.BTOut ? BTOut(this) : null" '
            + 'onmouseover="window.BTSel ? BTSel(this) : null" '
            + 'onmousedown="window.BTDep ? BTDep(this) : null" '
            + 'onclick="return window.BTClick ? BTClick(this) : true">'
            + '<span class="Span1"><span class="Span2">'
            + 'Next</span></span></a></span>');
        }

        document.write('</small></div></div></div>'
          + '<div class="Space15" style="clear: both">&nbsp;</div>\n');
        break;
      }
    }
  }
}

