<!--

/*  **********************************************  */
/*  For inclusion in the HEAD of the "banner" page  */
/*  **********************************************  */

/*  *************  */
/*  Configuration  */

/*  The following names need to match the corresponding style sheet.  */

/*  The banner is an arrangement of named blocks (each with an ID). Whether 
    each block is a DIV or a cell in a table is something we prefer not to 
    depend on. One important block presents the available subwebs. It needs 
    scripting support so that the current subweb is highlighted.  */

var sSubwebs = "Subwebs";

/*  The subwebs block is some sort of list in which each item (or cell) 
    represents either a single subweb or a group of them. The distinction is 
    known to the style sheet through class names.  */

var sSubweb = "Subweb";

/*  This script modifies the class names to show various changes of state.  */

var sCurrent = "Current";

/*  If only for now, there is also a notification area, again known by ID.  */

var sNotificationArea = "Notification";

/*  *******  */
/*  Subwebs  */

function GetCurrentSubwebLink (CurrentSubweb)
{
    var subwebs = window.document.getElementById (sSubwebs);
    if (subwebs == null) return;

    var links = subwebs.getElementsByTagName ("A");
    var numlinks = links.length;
    for (var i = 0; i < numlinks; i ++) {
        var link = links [i];
        if (link.href == CurrentSubweb) return link;
    }
    return null;
}

function ShowAsCurrentSubweb (CurrentSubwebLink)
{
    for (var x = CurrentSubwebLink; x != null; x = x.parentNode) {
        var classes = x.className.split (" ");
        var numclasses = classes.length;
        for (var i = 0; i < numclasses; i ++) {
            if (classes [i] == sSubweb) {
                x.className = sCurrent + " " + x.className;
                return true;
            }
        }
    }
    return false;
}

/*  As a temporary (and really ugly) provision, pending discovery of how to 
    specify the colour for flat frame borders in browsers other than 
    Internet Explorer, change the style sheet's specification of colour for 
    the current subweb (which is supposed to match the border colour).  */

function EnsureCurrentSubwebStyle ()
{
    var thisbody = window.document.body;
    var framesetbody = window.top.document.body;

    var nav = window.navigator;
    if (nav == null) return;
    var appname = nav.appName;
    if (appname == "Microsoft Internet Explorer") return;
    var sheet = GetLastStyleSheet ();
    if (sheet == null) return;
    var colour = null;
    switch (appname) {

        /*  Observation (only) suggests that the Netscape browsers either 
            show no border or make it white.  */

        case "Netscape": {          // Firefox, Safari and Chrome 
            colour = "#FFFFFF";
            break;
        }

        /*  Opera is seen to use whatever is the system's ButtonFace colour 
            (and so is Internet Explorer when "bordercolor" is not set).  */

        case "Opera": {
            colour = "ButtonFace";
            break;
        }
    }
    if (colour == null) return;
    var rule = "background-color:" + colour;
    var selector = "#" + sSubwebs + " ." + sCurrent + " a";
    AppendStyleSheetRule (sheet, selector, rule);
    AppendStyleSheetRule (sheet, selector + ":hover", rule);
}

function OnLoad (Event)                         // onload 
{
    /*  Compose a URL for the current subweb.  */
    
    var cursubweb = window.top.locSubweb;
    if (cursubweb == null) return;

    cursubweb = PathAppend (cursubweb.toString (), sDefaultFilename);

    /*  Find the matching link and show it as current.  */

    var link = GetCurrentSubwebLink (cursubweb);
    if (link == null) return;

    ShowAsCurrentSubweb (link);
    EnsureCurrentSubwebStyle ();
}

/*  *********************  */
/*  Global initialisation  */

/*  The banner page is meant to be seen only through another page, called a 
    viewer, which presents the page in a frame as context for a document 
    that is being shown concurrently in another frame. 

    If the window for this page is not the banner frame in the expected 
    viewer, reload the whole window with the default document from the same 
    directory.  */

if (!IsViewerFrame (sBannerFrame)) {
    if (IsRecognisedHostName ()) ViewDefaultFileInSameDirectory ();
}
else {
    window.onload = OnLoad;
    window.document.onclick = RedirectClickedLink;
}

/*  Copyright © 2007-2009. Geoff Chappell. All rights reserved.  */

//-->