window.onload = function () {
    initMailLinks();
    initAboutBox();
}


function initMailLinks() {
    var emailnk = document.getElementById('stephenemail');
    emailUpdate(emailnk, "stephen", "paulsens", "us",
                           "?", "subject=Your Resume");
}


function initAboutBox() {
    var aboutlink = document.getElementById('aboutlink');
    var aboutbox  = document.getElementById('aboutbox');
    var closebox  = document.getElementById('closebox');

    aboutlink.onclick = function(evt) {
        var blockstyle = aboutbox.style.display;
        if (blockstyle && blockstyle != '') {
            if (blockstyle == 'none') {
                aboutbox.style.display = 'block';
            }
            else {
                aboutbox.style.display = 'none';
            }
        }
        else {
            aboutbox.style.display = 'block';
        }
        return false; // don't follow the link
    };

    closebox.onclick = function(evt) {
        aboutbox.style.display = 'none';
    };
}


function emailUpdate() {
    var l = emailUpdate.arguments.length;
    var addr = "";
    var target = "mailto:";
    var el = emailUpdate.arguments[0];

    if (l < 3) {
        alert("Programming Error: not enough parameters to 'emailUpdate()'");
        return;
    }

    addr  = emailUpdate.arguments[1];
    addr += "@";
    //alert("addr is ["+addr+"]");

    for (i=2; i<l; i++)
    {
        arg = emailUpdate.arguments[i];
        if (arg == "?") break;
	if (i>2) addr += ".";
        addr += arg;
        //alert("addr is ["+addr+"]");
    }
    target += addr;

    if (arg == "?")
    {
        //alert("target is ["+target+"]");
        for (;i<l; i++)
        {
            arg = emailUpdate.arguments[i];
            target += arg;
            //alert("target is ["+target+"]");
        }
    }

    /* Note these have to be set in this order or IE
     * (in its infinite wisdom) will change the link
     * text to the target text.
     */
    //alert("about to set href attribute to ["+target+"]");
    el.attributes['href'].nodeValue = target;
    //alert("about to set inner html to ["+addr+"]");
    el.innerHTML = addr;
}

