var buttons = new Array();

function $ () {
    var elements = [], e, i, imax;
    for (i=0, imax=arguments.length; i<imax; i++) {
        e = arguments[i];
        if (typeof e == 'string')
            e = document.getElementById(e);
        if (imax == 1)
            return e;
        elements.push(e);
    }
    return elements;
}

function hasClassName (node, className) {
    if (!(node = $(node))) return;
    var cn = node.className;
    return (cn.length && (cn == className || cn.match (new RegExp("(^|\\s)" + className + "(\\s|$)"))));
}

function addClassName (node, className) {
    if (!(node = $(node)) || hasClassName(node, className)) return;
    node.className += (node.className ? ' ' : '') + className;
}

function removeClassName (node, className) {
    if (!(node = $(node))) return;
    node.className = node.className.replace (new RegExp("(^|\\s+)"+className+"(\\s+|$)"), ' ');
}

function menu_on_main() {
    var nr, item, tmp_tag;
    var main_obj_length = $("tabs_menu").getElementsByTagName("li").length;
    
    for (item = 0; item < main_obj_length ; ++ item) {
        if ( $("tabs_menu").getElementsByTagName("li")[item].getElementsByTagName("a").length ) {
            tmp_tag = $("tabs_menu").getElementsByTagName("li")[item].getElementsByTagName("a")[0];
            nr      = tmp_tag.id.match(/[\d]+$/);

            if ($("content" + nr)) {
                buttons[parseInt(nr)] = new menu_btn(nr, tmp_tag.id);
            }
        }
    }
    buttons[0].activation();
}

function menu_btn (nr, id) {
    this.nr               = nr;
    this.btn              = $(id);
    this.id               = id;
    this.content_box      = $("content" + this.nr);
    this.activation       = function () {
        var item;
        var nr             = parseInt(this.id.match(/[\d]+$/));
        var buttons_length = buttons.length;
        var act_btn        = buttons[nr].btn;

        for (item = 0; item < buttons_length; ++item ) {
            buttons[item].deactivation();
        }

        addClassName (buttons[nr].content_box, "active");

        if (hasClassName (act_btn, "tab")) {
            removeClassName (act_btn, "tab");
            addClassName (act_btn, "tabActive");
        }
    }
    this.deactivation     = function () {
        var nr      = parseInt(this.id.match(/[\d]+$/));
        var act_btn = buttons[nr].btn;

        removeClassName (buttons[nr].content_box, "active");

        if (hasClassName (act_btn, "tabActive")) {
            removeClassName (act_btn, "tabActive");
            addClassName (act_btn, "tab");
        }
    }
    this.btn.onmouseover = function () {
        var nr = parseInt(this.id.match(/[\d]+$/));
        Timer  = setTimeout("buttons[" + nr + "].activation()", 0);
    }
}

