// ============================================================================
// brdcast.resource
// ============================================================================
brdcast.resource = function()
{
    // init vars
    var wrapper = document.getElementById('resourcesWrapper');
      
    // clean the wrapper
    buffalo.utils.clearWhiteSpace(wrapper);
    
    // get the resources
    var resources = buffalo.utils.getElementsByClassName('resource', wrapper);
    
    // loop through the resources
    for (var i = 0; i < resources.length; i ++)
    {
        // store the height
        resources[i].nextSibling.store = resources[i].nextSibling.offsetHeight + 'px';
        
        // hide all of the resources except the first
        if (i != 0) resources[i].nextSibling.style.display = 'none';
        if (i != 0) resources[i].style.backgroundImage = 'url(/img/buttons/resourceOff.gif)';
        
        // add the open states
        if (i == 0)
            resources[i].open = true;
        else
            resources[i].open = false;
        
        // add the onclick states
        buffalo.utils.events.add(resources[i], 'click', this.change);
        
        // store the top-level resources
        resources[i].resources = resources;
    }
}

// show the correct resources
brdcast.resource.prototype.change = function()
{
    // check for already open
    if (this.open == true)
        return;
    
    // get the speed
    var speed = (document.all) ? 12 : 10;
    
    // loop through and hide all resources
    for (var i = 0; i < this.resources.length; i ++)
        if (this.resources[i].open == true)
        {
            // store the height
            var height = this.resources[i].nextSibling.store;
            
            // hide the resource
            var fx = new buffalo.honey(this.resources[i].nextSibling, 15);
            fx.changeSize({dir:1, alter:-speed, max:0});
            
            // change the open state
            this.resources[i].open = false;
            
            // change the image
            this.resources[i].style.backgroundImage = 'url(/img/buttons/resourceOff.gif)';
            
            // restore the height
            this.resources[i].nextSibling.store = height;
        }
    
    // get ready for honey
    this.nextSibling.style.height = '0px';
    this.nextSibling.style.display = 'block';
    
    // show the current resource
    var fx = new buffalo.honey(this.nextSibling, 15);
    fx.changeSize({dir:1, alter:speed, max:parseInt(this.nextSibling.store)});
    
    // change the open state
    this.open = true;
    
    // change the image
    this.style.backgroundImage = 'url(/img/buttons/resourceOn.gif)';
}
