//
// Menu Script
// Copyright (C) 2003, Toshiyuki Nakano
//
function Is (){
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.nav  = ((agent.indexOf('mozilla') != -1) &&
                 (agent.indexOf('spoofer') == -1) &&
                 (agent.indexOf('compatible') == -1) &&
                 (agent.indexOf('opera') == -1) &&
                 (agent.indexOf('webtv') == -1) &&
                 (agent.indexOf('hotjava') == -1));
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly = (this.nav && ((agent.indexOf(";nav") != -1) ||
                                 (agent.indexOf("; nav") != -1)));
    this.nav6 = (this.nav && (this.major == 5));
    this.nav6up = (this.nav && (this.major >= 5));
    this.gecko = (agent.indexOf('gecko') != -1);
    this.safari = (agent.indexOf('safari') != -1);
    if (this.safari) {
        this.gecko = false;
    }
    this.ie = ((agent.indexOf("msie") != -1) &&
               (agent.indexOf("opera") == -1));
    this.ie3 = (this.ie && (this.major < 4));
    this.ie4 = (this.ie && (this.major == 4) &&
                (agent.indexOf("msie 4") != -1));
    this.ie4up = (this.ie  && (this.major >= 4));
    this.ie5 = (this.ie && (this.major == 4) &&
                (agent.indexOf("msie 5.0") != -1) );
    this.ie5_5 = (this.ie && (this.major == 4) &&
                  (agent.indexOf("msie 5.5") != -1));
    this.ie5up = (this.ie  && !this.ie3 && !this.ie4);
    this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6 = (this.ie && (this.major == 4) &&
                (agent.indexOf("msie 6.") != -1) );
    this.ie6up = (this.ie  && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);
    this.aol = (agent.indexOf("aol") != -1);
    this.aol3 = (this.aol && this.ie3);
    this.aol4 = (this.aol && this.ie4);
    this.aol5 = (agent.indexOf("aol 5") != -1);
    this.aol6 = (agent.indexOf("aol 6") != -1);
    this.opera = (agent.indexOf("opera") != -1);
    this.opera2 = (agent.indexOf("opera 2") != -1 || agent.indexOf("opera/2") != -1);
    this.opera3 = (agent.indexOf("opera 3") != -1 || agent.indexOf("opera/3") != -1);
    this.opera4 = (agent.indexOf("opera 4") != -1 || agent.indexOf("opera/4") != -1);
    this.opera5 = (agent.indexOf("opera 5") != -1 || agent.indexOf("opera/5") != -1);
    this.opera5up = (this.opera && !this.opera2 && !this.opera3 && !this.opera4);
    this.webtv = (agent.indexOf("webtv") != -1); 
    this.TVNavigator = ((agent.indexOf("navio") != -1) ||
                        (agent.indexOf("navio_aoltv") != -1)); 
    this.AOLTV = this.TVNavigator;
    this.hotjava = (agent.indexOf("hotjava") != -1);
    this.hotjava3 = (this.hotjava && (this.major == 3));
    this.hotjava3up = (this.hotjava && (this.major >= 3));
    if (this.nav2 || this.ie3) {
        this.js = 1.0;
    } else if (this.nav3) {
        this.js = 1.1;
    } else if (this.opera5up) {
        this.js = 1.3;
    } else if (this.opera) {
        this.js = 1.1;
    } else if ((this.nav4 && (this.minor <= 4.05)) || this.ie4) {
        this.js = 1.2;
    } else if ((this.nav4 && (this.minor > 4.05)) || this.ie5) {
        this.js = 1.3;
    } else if (this.hotjava3up) {
        this.js = 1.4;
    } else if (this.nav6 || this.gecko) {
        this.js = 1.5;
    } else if (this.nav6up) {
        this.js = 1.5;
    } else if (this.ie5up) {
        this.js = 1.3;
    } else {
        this.js = 0.0;
    }
    this.win = ((agent.indexOf("win") != -1) ||
                (agent.indexOf("16bit") != -1));
    this.win95 = ((agent.indexOf("win95") != -1) ||
                  (agent.indexOf("windows 95") != -1));
    this.win16 = ((agent.indexOf("win16") != -1) ||
                  (agent.indexOf("16bit") != -1) ||
                  (agent.indexOf("windows 3.1") != -1) ||
                  (agent.indexOf("windows 16-bit") != -1));
    this.win31 = ((agent.indexOf("windows 3.1") != -1) ||
                  (agent.indexOf("win16") != -1) ||
                  (agent.indexOf("windows 16-bit") != -1));
    this.win98 = ((agent.indexOf("win98") != -1) ||
                  (agent.indexOf("windows 98") != -1));
    this.winnt = ((agent.indexOf("winnt") != -1) ||
                  (agent.indexOf("windows nt") != -1));
    this.win32 = (this.win95 || this.winnt || this.win98 || 
                  ((this.major >= 4) && (navigator.platform == "Win32")) ||
                  (agent.indexOf("win32") != -1) || (agent.indexOf("32bit") != -1));
    this.winme = ((agent.indexOf("win 9x 4.90") != -1));
    this.win2k = ((agent.indexOf("windows nt 5.0") != -1));
    this.os2 = ((agent.indexOf("os/2") != -1) ||
                (navigator.appVersion.indexOf("OS/2") != -1) ||
                (agent.indexOf("ibm-webexplorer") != -1));
    this.mac = (agent.indexOf("mac") != -1);
    if (this.mac && this.ie5up) {
        this.js = 1.4;
    }
    this.mac68k = (this.mac && ((agent.indexOf("68k") != -1) ||
                                (agent.indexOf("68000") != -1)));
    this.macppc = (this.mac && ((agent.indexOf("ppc") != -1) ||
                                (agent.indexOf("powerpc") != -1)));
    this.sun = (agent.indexOf("sunos") != -1);
    this.sun4 = (agent.indexOf("sunos 4") != -1);
    this.sun5 = (agent.indexOf("sunos 5") != -1);
    this.suni86 = (this.sun && (agent.indexOf("i86") != -1));
    this.irix = (agent.indexOf("irix") != -1);
    this.irix5 = (agent.indexOf("irix 5") != -1);
    this.irix6 = ((agent.indexOf("irix 6") != -1) || (agent.indexOf("irix6") != -1));
    this.hpux = (agent.indexOf("hp-ux") != -1);
    this.hpux9 = (this.hpux && (agent.indexOf("09.") != -1));
    this.hpux10= (this.hpux && (agent.indexOf("10.") != -1));
    this.aix = (agent.indexOf("aix") != -1);
    this.aix1 = (agent.indexOf("aix 1") != -1);
    this.aix2 = (agent.indexOf("aix 2") != -1);
    this.aix3 = (agent.indexOf("aix 3") != -1);
    this.aix4 = (agent.indexOf("aix 4") != -1);
    this.linux = (agent.indexOf("inux") != -1);
    this.sco = (agent.indexOf("sco") != -1) || (agent.indexOf("unix_sv") != -1);
    this.unixware = (agent.indexOf("unix_system_v") != -1);
    this.mpras = (agent.indexOf("ncr") != -1);
    this.reliant = (agent.indexOf("reliantunix") != -1);
    this.dec = ((agent.indexOf("dec") != -1) ||
                (agent.indexOf("osf1") != -1) ||
                (agent.indexOf("dec_alpha") != -1) ||
                (agent.indexOf("alphaserver") != -1) ||
                (agent.indexOf("ultrix") != -1) ||
                (agent.indexOf("alphastation") != -1));
    this.sinix = (agent.indexOf("sinix") != -1);
    this.freebsd = (agent.indexOf("freebsd") != -1);
    this.bsd = (agent.indexOf("bsd") != -1);
    this.unix = ((agent.indexOf("x11")!=-1) || this.sun || this.irix || this.hpux ||
                 this.sco ||this.unixware || this.mpras || this.reliant ||
                 this.dec || this.sinix || this.aix || this.linux || this.bsd ||
                 this.freebsd);
    this.vms = ((agent.indexOf("vax") != -1) || (agent.indexOf("openvms") != -1));
}

function home(title, url, elements) {
    this.title = title;
    this.url = url;
    this.elements = elements;
    prepareIcons(this.elements);
    this.write = homeWrite;
}

function homeWrite() {
    if (is.gecko) {
        document.write('<nobr style="font-size:13px;">');
    } else {
        document.write('<nobr style="font-size:15px;">');
    }
    writeIcon("H");
    if (this.url == "") {
        document.write(this.title + '<br>');
    } else {
        document.write('<a href="' + this.url + '">' + this.title + '</a><br>');
    }
    for (var i = 0; i < this.elements.length; i++) {
        this.elements[i].write();
    }
    document.write('</nobr>');
}

function directory(title, url, id, elements) {
    this.type = "Directory";
    this.title = title;
    this.url = url;
    this.id = id;
    this.elements = elements;
    prepareIcons(this.elements);
    this.icons = new Array("D");
    this.write = dirWrite;
}

function prepareIcons(elements) {
    for (var i = 0; i < elements.length - 1; i++) {
        if (elements[i].type == "Directory") {
            if (is.nav6up || is.ie5up || is.opera || is.gecko || is.safari) {
                elements[i].icons.push("+");
            } else {
                elements[i].icons.push("-");
            }
            addIcon(elements[i].elements, "|");
        } else {
            elements[i].icons.push("T");
        }
    }
    if (elements[elements.length - 1].type == "Directory") {
        if (is.nav6up || is.ie5up || is.opera || is.gecko || is.safari) {
            elements[elements.length - 1].icons.push("+L");
        } else {
            elements[elements.length - 1].icons.push("-L");
        }
        addIcon(elements[elements.length - 1].elements, "B");
    } else {
        elements[elements.length - 1].icons.push("|L");
    }
}

function addIcon(elements, icon) {
    for(var i = 0; i < elements.length; i++) {
        elements[i].icons.push(icon);
        if (elements[i].type == "Directory") {
            addIcon(elements[i].elements, icon);
        }
    }
}

function dirWrite() {
    for (var i = this.icons.length - 1; i >= 0; i--) {
        if (this.icons[i] == "+" || this.icons[i] == "+L" ||
            this.icons[i] == "-" || this.icons[i] == "-L") {
            writeIcon(this.icons[i], this.id);
        } else if (this.icons[i] == "D") {
            writeIcon(this.icons[i], this.id + "x");
        } else {
            writeIcon(this.icons[i], "");
        }
    }
    if (this.url == "") {
        document.write(this.title + '<br>');
    } else {
        document.write('<a href="' + this.url + '">' + this.title + '</a><br>');
    }
    if (is.nav6up || is.ie5up || is.opera || is.gecko || is.safari) {
        document.write('<div id="' + this.id + 'd" style="display:none">');
    }
    for (var i = 0; i < this.elements.length; i++) {
        this.elements[i].write();
    }
    if (is.nav6up || is.ie5up || is.opera || is.gecko || is.safari) {
        document.write('</div>');
    }
}

function file(title, url) {
    this.type = "File";
    this.title = title;
    this.url = url;
    this.icons = new Array("F");
    this.write = fileWrite;
}

function mail(title, url) {
    this.type = "Mail";
    this.title = title;
    this.url = url;
    this.icons = new Array("M");
    this.write = fileWrite;
}

function fileWrite() {
    for (var i = this.icons.length - 1; i >= 0; i--) {
        writeIcon(this.icons[i], "");
    }
    if (this.url == "") {
        document.write(this.title + '<br>');
    } else {
        document.write('<a href="' + this.url + '">' + this.title + '</a><br>');
    }
}

function writeIcon(icon, id) {
    var str = "";

    switch(icon) {
    case "H":
        str = '<img src="img/home.gif" align="top" height="16" width="19">';
        break;
    case "F":
        str = '<img src="img/file.gif" align="top" height="16" width="19">';
        break;
    case "D":
        str = '<img src="img/folder.gif" align="top" height="16" width="19" id="' + id + '">';
        break;
    case "M":
        str = '<img src="img/mail.gif" align="top" height="16" width="19">';
        break;
    case "B":
        str = '<img src="img/blank.gif" align="top" height="16" width="19">';
        break;
    case "+":
        str = '<img src="img/plus.gif" align="top" height="16" width="19" class="Directory" id="' + id + '">';
        break;
    case "-":
        str = '<img src="img/lminus.gif" align="top" height="16" width="19" class="Directory" id="' + id + '">';
        break;
    case "+L":
        str = '<img src="img/lplus.gif" align="top" height="16" width="19" class="DirectoryLast" id="' + id + '">';
        break;
    case "-L":
        str = '<img src="img/lminus.gif" align="top" height="16" width="19" class="DirectoryLast" id="' + id + '">';
        break;
    case "|":
        str = '<img src="img/line.gif" align="top" height="16" width="19">';
        break;
    case "|L":
        str = '<img src="img/last.gif" align="top" height="16" width="19">';
        break;
    case "T":
        str = '<img src="img/branch.gif" align="top" height="16" width="19">';
        break;
    }
    document.write(str);
}

function clickHandler(event) {
    var src, id, elem, dir;
    if (is.nav6up || is.gecko) {
        src = event.originalTarget;
    } else {
        src = window.event.srcElement;
    }
    if (src.className == "Directory") {
        id = src.id + "d";
        if (is.nav6up || is.gecko) {
            elem = document.getElementById(id);
        } else {
            elem = document.all(id);
        }
        if (elem.style.display == "none") {
            elem.style.display = "";
            src.src = "img/minus.gif";
        } else {
            elem.style.display = "none";
            src.src = "img/plus.gif";
        }
    } else if (src.className == "DirectoryLast") {
        id = src.id + "d";
        if (is.nav6up || is.gecko) {
            elem = document.getElementById(id);
        } else {
            elem = document.all(id);
        }
        if (elem.style.display == "none") {
            elem.style.display = "";
            src.src = "img/lminus.gif";
        } else {
            elem.style.display = "none";
            src.src = "img/lplus.gif";
        }
    }
    id = src.id + 'x';
    if (is.nav6up || is.gecko) {
        dir = document.getElementById(id);
    } else {
        dir = document.all(id);
    }
    if (elem.style.display == "none") {
        dir.src = "img/folder.gif";
    } else {
        dir.src = "img/ofolder.gif";
    }
}

var is = new Is();
if (is.nav6up || is.ie5up || is.opera || is.gecko || is.safari) {
    document.onclick = clickHandler;
}

// -- END OF SCRIPT -- //
