var DigWar = Class.create({});

DigWar.Tabs = Class.create({
    current : null,

    initialize : function() {
    	$$('div.collateral-tabs div.tab-header div.tab').each(function(tab) {
    		tab.observe('click', this.show.bind(this, tab));
    	}.bind(this));
    	this.hideAll();
    	this.show($$('div.collateral-tabs div.tab-header div.tab').first());
    },

    show : function(elm) {
        this.hideAll();
        var nextId = elm.id.replace('tab-', '');
        if (nextId != this.current) {
            var next = $('tab-' + nextId + '-content')
            if (next.hasAttribute('url') && !next.hasAttribute('loaded')) {
                new Ajax.Updater(next.id, next.getAttribute('url'), {
                    onSuccess: function (response) {
                        next.addAttribute('loaded', 'loaded');
                    }
                });
            }
            this.current = nextId;
            elm.addClassName('active');
            next.show();
        }
    },

    hideAll : function() {
    	$$('div.collateral-tabs div.tab-header div.tab').each(function(tab) {
    		tab.removeClassName('active');
    	}.bind(this));
    	$$('div.collateral-tabs div.tab-container div.tab-content').each(function(tab) {
    		tab.hide();
    	}.bind(this));
    }
});

var my_glider;
document.observe("dom:loaded", function() {
    my_glider = new Glider('home-glider', {duration: 1.0, autoGlide: true, frequency: 8});
});
