window.onload = initialize; 

function initialize()
{
    copyPageHeadToTitle();
    markExtLinks();
    markMenu();
}

function copyPageHeadToTitle()
{
    var t = document.getElementById('pagehead');
    if( t != null )
    {
        document.title = 'BBSC ' + t.firstChild.data;
    }
}

function markExtLinks()
{
    /*
    Go through all links. If any has a class="external" then do some funky stuff after it 
    */

    var x = document.getElementsByTagName('a');
    for (var i=0; i<x.length; i++)
    {
	var e = x[i];
        if (e.className == 'external')
        {
           var s = document.createElement('span');
           {
             s.className = 'external-marker';
	     var t = document.createTextNode('external link  ');
             s.appendChild(t);
           }
	   //insertAfter(e.parentNode, s, e);
           e.parentNode.insertBefore(s,e.nextSibling);
        }
    }
}

function markMenu()
{
    /*
    Go through all links. If any has a class="menu" then check to see if we're in its folder
    If we are, then change its class to menucurrent
    */

    var path = window.location.pathname;
    var folders = path.split('/');
    var folder = '/' + folders[folders.length-2] + '/';

    var x = document.getElementsByTagName('a');
    for (var i=0; i<x.length; i++)
    {
        if (x[i].className == 'menuItem')
        {
	    if( x[i].href.indexOf(folder) != -1 )
	    {
                x[i].className = 'menuCurrent';
	    }
        }
    }
}

