var jq = jQuery;

function wTab(cfg) {
    var this_ = this;
    this.btns = cfg.btns;
    this.tabs = cfg.tabs;
    this.cons = cfg.cons;
    this.curIdx = cfg.curIdx || 0;
    this.idxA = [0, this.tabs.length - 1];
    var evtype = 'bind_' + (cfg.evtype || 'click');
    if (this[evtype]) {
        this[evtype]();
    }
    if (this.btns) {
        jq(this.btns[0]).click(function() {
            this_.navTo(this_.curIdx - 1);
            return false;
        });
        jq(this.btns[1]).click(function() {
            this_.navTo(this_.curIdx + 1);
            return false;
        });
    }
    this.navTo(this.curIdx, 1);
}
jQuery.extend(wTab.prototype, {
    bind_click: function() {
        var this_ = this;
        this.tabs.each(function(idx, tab) {
            jq(tab).click(function(ev) {
                if (this_.navTo(idx)) {
                    ev.stopPropagation();
                    return false;
                }
            });
        });
    },
    bind_hover: function() {
        var this_ = this;
        this.tabs.each(function(idx, tab) {
            jq(tab).hover(function() {
                this_.navTo(idx);
            },
            function() {});
        });
    },
    navTo: function(idx, f) {
        if ((idx < this.idxA[0] || idx > this.idxA[1]) || (this.curIdx == idx && !f)) return false;
        this.curIdx = idx;
        this.tabs.removeClass('over');
        jq(this.tabs[idx]).addClass('over');
        this.cons.css('display', 'none');
        jq(this.cons[idx]).css('display', '');
        return true;
    }
}); 
