var curlevel = "1.0";

function calc_next_level_str (level)
    {
    var i;
    var items;
    var result;
    var tmp;

    items = curlevel.split (".");

    // If the current level is the same as the number of
    // items in the split, then just increment the last
    // digit.

    if (level > items.length-1)
        {
        items[level] = "1";
        }
    else
        {
        if (level < items.length-1)
            {
            items.length = level + 1;
            }

        tmp = parseInt (items[items.length-1]);
        tmp++;
        items[items.length-1] = tmp.toString();
        }

    // Reassemble level string.

    result = "";

    for (i = 0; i < items.length; i++)
        {
        result += items[i];
        if (i < items.length-1)
            {
            result += ".";
            }
        }

    curlevel = result;
    return (result);
    }


function display_toc_item (rel,page)
    {
    var img;
    var str;

    if (this.visible == false)
        {
        return;
        }

    if (page == this.graphic)
        {
        img = "cnt/" + this.graphic + "-down.gif";
        str = '<img src="' + rel + img  + '" class="tocimg" alt="' + this.title + '">';
        }
    else
        {
        img = "cnt/"     + this.graphic + ".gif";
        str = '<a href="'  + rel + this.link + '">' +
              '<img src="' + rel + img  + '" class="tocimg" alt="' + this.title + '" border="0">' +
              '</a>';
        }

    document.write (str);

    return;
    }


function toc_item (level,rel,link,graphic,title)
    {
    this.level   = calc_next_level_str(level);
    this.rel     = rel;
    this.link    = link;
    this.graphic = graphic;
    this.title   = title;
    this.visible = new Boolean(false);
    this.indent  = level;

    this.display_toc_item = display_toc_item;
    }



var tocitems = new Array();

function add_item (level,rel,link,graphic,title)
    {
    tocitems[tocitems.length] = new toc_item (level,rel,link,graphic,title);
    }


function build_toc (rel)
    {
    add_item (1,rel,"index.html",                         "home",               "GALA Choruses Home");

    add_item (1,rel,"news_and_notes.html",                "news_and_notes",     "News &amp; Notes");
    add_item (1,rel,"events_prog_serv.html",              "events_prog_serv",   "Events, Programs &amp; Services");
    add_item (2,rel,"events/index.html",                  "event_calendar",     "GALA Choruses Event Calendar");
    add_item (2,rel,"events/2006_mixed_chorus/index.html", "2006_annual_conf",   "GALA Choruses 2006 Annual Conference");

    add_item (2,rel,"festival/index.html",                "festival_vii",       "VIIe Festival International GALA Choruses");

    add_item (2,rel,"events/past_events.html",            "past_events",        "Past Events");
    add_item (3,rel,"events/2003_mgrs_dirs/index.html",   "mgrs_dirs_retreat",  "2003 Managers &amp; Directors Retreat");

    add_item (2,rel,"progserv/index.html",                  "prog_and_services",  "GALA Choruses Programs &amp; Services");
    add_item (3,rel,"progserv/jobs.html",                   "glbt_chorus_jobs",   "GLBT Chorus Job Openings");
    add_item (3,rel,"progserv/com_match_grants.html",       "com_match_grants",   "GALA Choruses Commission Matching Grants");
    add_item (3,rel,"progserv/training_and_mentoring.html", "training_mentoring", "GALA Choruses Training &amp; Mentoring");
    add_item (3,rel,"progserv/documents.html",              "memb_samp_docs",     "GALA Choruses Sample Documents");


    add_item (1,rel,"meet/index.html",                    "meet",               "Meet GALA Choruses");
    add_item (2,rel,"meet/board_of_directors.html",       "board_of_directors", "Meet the Board");
    add_item (2,rel,"meet/staff.html",                    "staff",              "Meet the Staff");
    add_item (2,rel,"about/history_legacy.html",          "history_legacy",     "Our History, Our Legacy");
    add_item (2,rel,"about/sponsors.html",                "sponsors",           "GALA Choruses Sponsors");
    add_item (2,rel,"about/affiliations.html",            "affiliations",       "GALA Choruses Affiliations");
    add_item (2,rel,"about/credits.html",                 "credits",            "GALA Choruses Tech Team");

    add_item (1,rel,"advertising/index.html",             "ad_opportunities",   "GALA Choruses Advertising Opportunities");

    add_item (1,rel,"forms/forms.html",                                         "forms",              "GALA Choruses Online Forms");
    add_item (1,rel,"membership/membership.html",                               "membership",         "GALA Choruses Joining the Association");
//    add_item (2,rel,"membership/members_only/index.html", "members_only", "GALA Choruses Members Only");

    add_item (1,rel,"donors/index.html",    "donors",   "GALA Choruses Donors Corner");

    add_item (1,rel,"resources/online_resources.html",    "online_resources",   "GALA Choruses Online Resources");
    add_item (2,rel,"resources/youth_participation.html","youth_participation", "Youth Participation");
    add_item (2,rel,"resources/articles/articles_of_interest.html","articles_of_interest", "Articles of Interest");
    add_item (2,rel,"resources/communication_toolkit.html","comm_toolkit", "Communication Toolkit");
    add_item (2,rel,"resources/email/email_lists.html",   "email_lists",        "E-mail Lists");
    add_item (3,rel,"resources/email/gala_email_lists.html",   "gala_email_lists",  "GALA Choruses E-mail Lists");
    add_item (3,rel,"resources/email/other_email_lists.html",   "other_email_lists","Non-GALA Choruses E-mail Lists");
    add_item (3,rel,"resources/email/subscribing.html",   "subscribing",        "Subscribing to an E-mail List");
    add_item (3,rel,"resources/email/unsubscribing.html", "unsubscribing",      "Unubscribing from an E-mail List");

    add_item (2,rel,"resources/links.html",               "links",              "GALA Choruses Links");
    add_item (2,rel,"resources/recommended_reading.html", "rec_reading",        "GALA Choruses Recommended Reading");

    add_item (1,rel,"publications/publications.html",     "publications",       "GALA Choruses Publications");
    add_item (2,rel,"publications/ordering.html",         "ordering",           "GALA Choruses Publications Ordering");
    add_item (1,rel,"membership/choruses/index.html",     "choruses",           "GLBT Choruses Worldwide");
    add_item (1,rel,"events/calendar.html",               "calendar",           "Master Calendar");
    add_item (1,rel,"meet/contact_information.html",      "contact_information","Contact Us");
    add_item (1,rel,"special_offers.html",                "special_offers",     "Special Offers");
    add_item (1,rel,"merchandise.html",                   "merchandise",        "Merchandise");
    add_item (1,rel,"site_map.html",                      "site_map",           "GALA Choruses Site Map");
    }


function create_toc(page,rel)
    {
    var i;
    var pagelvl;
    var parentlvl;

    // Find the level for the current page.

    for (i = 0; i < tocitems.length; i++)
        {
        if (tocitems[i].graphic == page)
            {
            pagelvl = tocitems[i].level;
            tocitems[i].visible = true;
            break;
            }
        }

    // Set visibility for children of selected child.

    for (i = 0; i < tocitems.length; i++)
        {
        if (pagelvl == tocitems[i].level.substring(0,tocitems[i].level.lastIndexOf(".")))
            {
            tocitems[i].visible = true;
            }
        }

    // Pass through the TOC, setting all visibility levels until
    // reaching the top level. Start with the selected item, make
    // its parent and siblings visible, and then repeat for the
    // parent. Continue until reaching the top level.

    parentlvl = pagelvl;

    while (parentlvl.length != 0)
        {
        for (i = 0; i < tocitems.length; i++)
            {
            // Make the current parent visible.

            if (parentlvl == tocitems[i].level)
                {
                tocitems[i].visible = true;
                continue;
                }

            // Make siblings of the current parent visible.

            if (parentlvl.substring(0,parentlvl.lastIndexOf(".")) == 
                tocitems[i].level.substring(0,tocitems[i].level.lastIndexOf(".")))
                {
                tocitems[i].visible = true;
                continue;
                }
            }

        parentlvl = parentlvl.substring(0,parentlvl.lastIndexOf("."));
        }
    

    for (i = 0; i < tocitems.length; i++)
        {
        tocitems[i].display_toc_item (rel,page);
        }
    }


function begin_layout(page,rel)
    {
    var white;

    white  = rel + "graphics/pixel_white.gif";
    
    document.writeln ('<table width="780" cellspacing="0" cellpadding="0" border="0">');
    document.writeln ('  <tr>');
    document.write   ('    <td width="200" height="80" align="center">');
    document.writeln         ('<img src="' + rel + 'graphics/galalogo.gif" height="100" width="200" border="0"' +
                                ' alt="GALA Choruses: Our Voices Win Freedom"></td>');
    document.writeln ('    <td width="10"><img src="' + white + '" width="10" height="1"></td>');
    document.writeln ('    <td width="570"><img src="' + rel + 'titles/' + page + '.jpg" width="570" height="100"></td>');
    document.writeln ('  </tr>');
    document.writeln ('  <tr>');
    document.writeln ('    <td height="3" width="200"><img src="' + white  + '" width="200" height="3"></td>');
    document.writeln ('    <td height="3" width="10" ><img src="' + white  + '" width="9"   height="3"></td>');
    document.writeln ('    <td height="3"            ><img src="' + white  + '" width="1"   height="3"></td>');
    document.writeln ('  </tr>');
    document.writeln ('  <tr>');
    document.writeln ('    <td height="3" width="200"><img src="' + white  + '" width="200" height="3"></td>');
    document.writeln ('    <td height="3" width="10" ><img src="' + white  + '" width="9"   height="3"></td>');
    document.writeln ('    <td height="3"            ><img src="' + white  + '" width="1"   height="3"></td>');
    document.writeln ('  </tr>');
    document.writeln ('  <tr>');
    document.write   ('    <td width="200" valign="top">');

    create_toc(page,rel);

    document.writeln ('</td>');
    document.writeln ('    <td width="10"><img src="' + white + '" width="9" height="1"></td>');
    document.writeln ('    <td valign="top">');
    }


function finish_layout(topdirrel)
    {
    var white;

    white = topdirrel + "graphics/pixel_white.gif";

    document.writeln ('    </td>');
    document.writeln ('  </tr>');
    document.writeln ('  <tr>');
    document.writeln ('    <td height="3" width="200"></td>');
    document.writeln ('    <td height="3" width="10" ><img src="' + white + '" width="9" height="1"></td>');
    document.writeln ('    <td height="3"            ><img src="' + white + '" width="1" height="1"></td>');
    document.writeln ('  </tr>');
    document.writeln ('</table>');
    document.writeln ('<p>&nbsp;</p>');
    }


function modified()
    {
    var moddate;

    document.write ('&copy; 2005 by GALA Choruses, Inc.');
    document.writeln ("</br>");
    document.write ('<a href="mailto:webmaster@galachoruses.org,galaed@galachoruses.org?subject=' + document.title + 
                       '">Report a problem on this page.</a></p>');
    document.write ('<p>&nbsp;</p>');
    }

