/*
 * The Menu Class
 */
function Menu() {
    this.menuItems = new Array();
    this.foldout = false;
    this.addMenuItem = Menu_addMenuItem;
    this.create = Menu_create;
    return this;
}

function Menu_addMenuItem(item) {
    if (item.active || (item.submenu && item.submenu.foldout)) {
        this.foldout = true;
    }   
    this.menuItems.push(item);
}

function Menu_create(level) {
    var i, l = 0;
    if (level) {
        l = level;
    }
    if (l == 0) {
        document.writeln('<table width="155" border="0" cellpadding="2" cellspacing="1" bgcolor="#E9DDC1">');
        //document.writeln('<tr><td><img src="images/menu/divider_top.gif"></td></tr>');
    }
    for (i=0; i < this.menuItems.length; i++) {
        var c = 'menu_level_'+l;
        var item = this.menuItems[i];
        if (item.active){
            c = c + ' menu_item_active';
        }
        document.writeln('<tr class="'+c+'"><td align="left" valign="top" bgcolor="#F7F4EB"><span class="menu_level_'+l+'_indent">');
        if (l == 0){
            var img;
            if (item.submenu && item.submenu.foldout) {
                img = "images/menu/arrow_open.gif";
            } else {
                img = "images/menu/arrow.gif";
            }           
            document.writeln('<img src="'+img+'">');
        } else {
            document.writeln('&nbsp;-');
        }
        if (item.active) {
            document.writeln(item.label);
        } else {
            document.writeln('<a class="meny1" href="'+item.href+'" class="'+c+'">'+item.label+'</a>');
        }
        document.writeln('</span></td></tr>');
        if (item.submenu && (item.submenu.foldout || item.active)) {
            item.submenu.create(l + 1);
        }
        if (l == 0) {
            //document.writeln('<tr><td><img src="images/menu/divider.gif"></td></tr>');
        }
    }
    if (l == 0) {
        document.writeln('</table>');
    }
}
/*
 * The MenuItem Class
 */
function MenuItem(label, href, submenu) {
    this.label = label;
    this.href = href;
    this.submenu = null;
    this.active = false;
    this.testIfActive = MenuItem_testIfActive;
    if (submenu) {
        this.submenu = submenu;
    }
    this.testIfActive();
    if (this.active && submenu) {
        this.submenu.foldout = true;
    }
    return this;
}

function MenuItem_testIfActive() {
    var url = this.href;
    if (url.charAt(0) == '/') {
        url = location.protocol + "//" + location.hostname + url;
    } else if (url.indexOf("://") == -1) {
        url = location.protocol + "//" + location.hostname + location.pathname.substring(0, location.pathname.lastIndexOf("/", location.pathname.length)+1) + url;
    }
    if (url == location.href) {
        this.active = true;
    }
}


