// Email un-obfuscator for mailto: URLs
// By Andrew Shearer amc2005 (no spam) at shearersoftware dot (no spam) com

window.onload = function() {
    if (!document.getElementsByTagName) return;
    var a = document.getElementsByTagName('a');
    for (var i = 0; i < a.length; i++) {
        var href = a[i].getAttribute('href');
        if (href && href.substr(0, 7) == 'mailto:') {
            href = href.replace("REMOVE_123_THIS@ANTI_S.pam-", '@');
            href = href.replace("REMOVE_THIS@REMOVE_ANTISPAM", '@');
            a[i].setAttribute('href', href);
            while (a[i].firstChild) {
                a[i].removeChild(a[i].firstChild);
            }
            var child = document.createTextNode(href.substr(7));    // ditch 'mailto:' prefix
            a[i].appendChild(child);
        }
    }
}

// Andrew Shearer 2005-06 - 2005-08
// JavaScript for navigation menu.
// Finds and highlights current page in the menu.
// Requires links nested inside an element with an ID of 'navmenu',
// and a CSS style for 'a.current'.

function makePathCanonical(path) {
    if (!path) path = '';
    path = path.toLowerCase();
    //path = path.replace(/^([a-z]+:\/\/[^/]+)?(\/[^#\?]*)/, "\\2");
    // strip leading scheme + host, trailing query & hash
    
    if (path.substr(0, 1) != '/') {
        // add leading slash (not present in rel. links in Opera, IE Win,
        // but is in Safari, Firefox, IE Mac)
        
        //path = document.location.pathname.substr(0, document.location.pathname.lastIndexOf('/')+1) + path;
        path = '/' + path;
        
    }
    path = path.replace(/\/(index|default)\.[^\/]+$/, '/');
    // strip trailing index.html, default.asp, etc.
    
    return path;
}

var menuInited = false;

function initMenu() {
    if (menuInited || !document.getElementById || !document.getElementById('navmenu')) {
        return;
    }
    var currentPath = makePathCanonical(window.location.pathname);
    var links = document.getElementById('navmenu').getElementsByTagName('a');
    for (var linkNum = 0; linkNum < links.length; linkNum++) {
        if (makePathCanonical(links[linkNum].pathname) == currentPath) {
            if (links[linkNum].className) {
                links[linkNum].className += ' current';
            }
            else {
                links[linkNum].className = 'current';
            }
        }
    }
}

var prevOnload = window.onload;
window.onload = function(e) {
    if (prevOnload) prevOnload(e);
    initMenu();
}

// first try is ahead of onload handler, so it can occur before page is drawn
// if browser DOM is ready (otherwise, onload handler will pick it up)
initMenu();