if (typeof(com) == 'undefined') {
    com = {};
}
if (typeof(com.is_a) == 'undefined') {
    com.is_a = {};
}

com.is_a.Tabber = function(tabIds, panelIds, activeTabClass, activePanelClass)
{
    this.activeTab = null;
    this.activeTabInitialClass = null;
    this.activePanel = null;
    this.activePanelInitialClass = null;
    this.tabs = new Array(tabIds.length);
    this.panels = new Array(panelIds.length);
    
    this.init = function()
    {
        for(var i = 0; i < tabIds.length; i++) {
            var tab = document.getElementById(tabIds[i]);
            var panel = document.getElementById(panelIds[i]);
            this.tabs[i] = tab;
            this.panels[i] = panel;
            var createOnClick = function(self, tab, panel) { // Closure, понимаешь ;)
                return function() {self.tabClick(tab, panel);}
            }
            tab.onclick = createOnClick(this, tab, panel);
            if (i == 0) {
                tab.onclick();
            }
        }
    }
    
    this.tabClick = function(tab, panel)
    {
        if (this.activeTab === tab) {
            return;
        }
        
        if (this.activeTab != null) {
            this.activeTab.className = this.activeTabInitialClass;
            this.activePanel.className = this.activePanelInitialClass;
        }
        
        this.activeTab = tab;
        this.activeTabInitialClass = tab.className;
        this.activeTab.className = activeTabClass;
        this.activePanel = panel;
        this.activePanelInitialClass = panel.className;
        this.activePanel.className = activePanelClass;
    }
    
    this.activateTab = function(tabIndex)
    {
        if (tabIndex >= 0 && tabIndex < this.tabs.length) {
            this.tabs[tabIndex].onclick();
        }
    }
    
    this.init();
}