function rot13(str) {
    var chars = 'abcdefghijklmnopqrstuvwxyz';

    return String(str).replace(/[a-z]/gi, function(ch) {
        var base = (ch < 'a') ? 65 : 97;
        var idx = ((ch.charCodeAt() - base) + 13) % 26;
        if (ch < 'a') {
            return chars.charAt(idx).toUpperCase();
        } else {
            return chars.charAt(idx);
        }
    });
}

if (!window.Node) {
    var Node = {
        ELEMENT_NODE: 1,
        TEXT_NODE: 3
    };
}

function obfuscateNode(node) {
    switch (node.nodeType) {
    case Node.ELEMENT_NODE:
        var next = node.firstChild;
        while (next) {
            obfuscateNode(next);
            next = next.nextSibling;
        }
        break;
    case Node.TEXT_NODE:
        node.data = rot13(node.data);
        break;
    }
}

document.observe('dom:loaded', function() {
    var node;
    if ((node = $('toggle-rot13')) == null)
        return;
    node.observe('click', function(e) {
        e.stop();
        obfuscateNode(document.body);
    });
});
