/* Basic functions used on my website */

// Determines whether a function from fx.js is present
// and defines a local namespace function accordingly
function getFxSlide()
{
    if (typeof(slide_elt) != 'undefined') {
        // Uses the slide_elt function from fx.js if present
        return slide_elt;
    }
    else {
        // Falls back on a closure that sets the CSS display property
        return function(eid) {
            var e = document.getElementById(eid);
            if (e.style.display == 'none') { e.style.display = ''; }
            else { e.style.display = 'none'; }
        }
    }
}
var fxSlide = getFxSlide();

var elShown;
function showEl(id) {
    var el;

    if (document.getElementById(id)) {
        el = document.getElementById(id);
        if (el.style.display == "none") {
            elShown = id;
            fxSlide(id);
        } else {
            elShown = "";
            fxSlide(id);
        }
        return false;
    } else {
        return true;
    }
}

function showCat(id) {
    if ( elShown != "" ) { showEl( elShown ); }
    return showEl(id + "-category");
}

function showComment(id) {
    if (document.getElementById(id + "-comment")) {
        document.getElementById("link-bar-comments").innerHTML = document.getElementById(id + "-comment").innerHTML;
    }
    return false;
}

function initLinkBar() {
    var pathComponents = document.location.href.split("/");
    var currentLocation = "";
    if (pathComponents[3].indexOf('.') == -1) {
        currentLocation = pathComponents[3];
    } else {
        return false;
    }

    // The CGI scripts
    if (currentLocation == "cgi-bin") {
        currentLocation = "scripts";
    }

    if (document.getElementById(currentLocation + "-category")) {
        showEl( currentLocation + "-category" );
        showComment( currentLocation );
    }
    return false;
}
