function basename(s) {
    var p;
    p = s.indexOf('?');
    if(p != -1) s = s.substring(0,p);
    p = s.lastIndexOf('/');
    return p < 0 ? s : p == s.length - 1 ? 'default.asp' : s.substring(p+1);
}

function rollover(e) {
    var src = this.src;
    p = src.indexOf("-ns");
    if(p >= 0) this.src = src.substring(0,p) + "-s" + src.substring(p+3);
}

function rollout(e) {
    var src = this.src;
    p = src.indexOf("-s");
    if(p >= 0) this.src = src.substring(0,p) + "-ns" + src.substring(p+2);
}

function fixup() {
    var i,j,as,href,is,src,p,base;
    if(window.location.hash == '#nofix') return;
    base = window.location.protocol + '//' + window.location.hostname;
    document.title += ' - ' + basename(window.location.href);
    as = document.getElementsByTagName("a");
    for(i=0;i<as.length;i++) {
        href = as[i].getAttribute("href");
        if(href.indexOf(':') != -1 && href.substring(0,base.length) != base) continue;
        is = as[i].getElementsByTagName("img");
        p = href.lastIndexOf('#');
        if(p >= 0) href = href.substring(0,p);
        if(!as[i].getAttribute("onclick") && href.indexOf('?') == -1 && basename(href) == basename(window.location.href)) {
            as[i].removeAttribute("href");
            for(j=0;j<is.length;j++) {
                src = is[j].src;
                p = src.lastIndexOf("-ns");
                if(p >= 0) is[j].src = src.substring(0,p) + "-s" + src.substring(p+3);
            }
        } else {
            for(j=0;j<is.length;j++) {
                is[j].onmouseover = rollover;
                is[j].onmouseout = rollout;
            }
        }
    }
}

