var TAB_PREFIX = "entry";

function Tabber(prefix) {
    if ( !prefix ) {
        this.prefix = TAB_PREFIX;
    } else {
        this.prefix = prefix;
    }
    
    this.init = function() {
        this.container = document.getElementById( this.prefix + "-container" );

        this.tabbar = document.getElementById( this.prefix + "-tabbar" );
        for ( var i = 0; i < this.tabbar.childNodes.length; i++ ) {
            var tab = this.tabbar.childNodes[i];
            if ( tab.nodeName.toUpperCase() == "DIV" ) {
                var tabName = tab.id.substring( tab.id.lastIndexOf("-")+1 );
                tab.onclick = this.getTabEventHandler(tabName);
            }
        }

        this.content = document.getElementById( this.prefix + "-content" );
        this.contenttabs = new Object();
        var first = true;
        for ( var i = 0; i < this.content.childNodes.length; i++ ) {
            var child = this.content.childNodes[i];
            if ( child.nodeName.toUpperCase() == "DIV" ) {
                var tabName = child.id.substring( child.id.lastIndexOf("-")+1 );
                if ( first != true ) {
                    child.style.display = "none";
                }
                first = false;
                this.contenttabs[tabName] = child;   
            }
        }
    };
    
    this.showTab = function(tabName) {
        var toShow= this.contenttabs[tabName];
        if ( toShow ) {
            for ( var name in this.contenttabs ) {
                var curr = this.contenttabs[name];
                if ( curr == toShow ) {
                    curr.style.display = "block";
                } else {
                    curr.style.display = "none";
                }
            }
        }
    };
    
    this.getTabEventHandler = function(tabName) {
        var _this = this;
        return function() {
            _this.showTab( tabName );
        };
    };
    
    this.init();
    return this;
}




