﻿function Tabs(tabid, cls) {
    var lis = document.getElementById(tabid).getElementsByTagName('LI')
    this.cls = cls;
    this.ary = [];
    this.to = null;
    this.def = null;
    this.lst = false;
    for (var rel, sub, z0 = 0; z0 < lis.length; z0++) {
        rel = lis[z0].getAttribute('rel');
        sub = document.getElementById(rel);
        if (rel && sub) {
            this.ary[z0] = [lis[z0], sub];
            if (lis[z0].className && lis[z0].className == cls) {
                sub.style.display = 'block';
                this.lst = this.ary[z0];
                this.def = this.ary[z0];
            }
            this.addevt(lis[z0], 'mouseover', 'MseOver', z0);
            this.addevt(lis[z0], 'mouseout', 'MseOut', z0);
            this.addevt(sub, 'mouseover', 'Cancel', z0);
            this.addevt(sub, 'mouseout', 'MseOut', z0);
        }
    }
}

Tabs.prototype.Hide = function() {
    if (this.lst) {
        this.lst[0].className = '';
        this.lst[1].style.display = 'none';
    }
}

Tabs.prototype.MseOut = function(e, nu) {
    var oop = this;
    this.to = setTimeout(function() { oop.Def(); }, 500);
}

Tabs.prototype.Def = function() {
    this.Hide();
    if (this.def) {
        this.lst = this.def
        this.def[0].className = this.cls;
        this.def[1].style.display = 'block';
    }
}

Tabs.prototype.MseOver = function(e, nu) {
    this.Cancel();
    this.Hide();
    this.lst = this.ary[nu];
    this.lst[0].className = this.cls;
    this.lst[1].style.display = 'block';
}

Tabs.prototype.Cancel = function() {
    clearTimeout(this.to);
}


Tabs.prototype.addevt = function(o, t, f, p) {
    var oop = this;
    if (o.addEventListener) o.addEventListener(t, function(e) { return oop[f](e, p); }, false);
    else if (o.attachEvent) o.attachEvent('on' + t, function(e) { return oop[f](e, p); });
    else {
        var prev = o['on' + t];
        if (prev) o['on' + t] = function(e) { prev(e); oop[f](e, p); };
        else o['on' + t] = o[f];
    }
}

