/***************************************************************\
| |\  /|                                                We Put  |
| | >< Hypercosm         component_group.js             3d      |
| |/  \|                                                To Work |
|***************************************************************|
|                                                               |
|        This file defines the Javascript behaviors of a        |
|        generalized user interface component.                  |
|                                                               |
|***************************************************************|
|                Copyright (c) 2008 Hypercosm, LLC.             |
\***************************************************************/


//
// "class" constructor
//


function componentGroup(components) {
  
  // set attributes
  //
  this.components = new Array();
  
  // add components
  //
  if (components)
    for (var i = 0; i < components.length; i++)
      this.addComponent(components[i]);
  
  return this;
}    // componentGroup


//
// "object" or "instance" methods
//


componentGroup.prototype.addComponent = function(component) {
  this.components[this.components.length] = component;
}	// addComponent


componentGroup.prototype.getComponent = function(index) {
  return this.components[index];
}	// getComponent


componentGroup.prototype.getComponents = function() {
  return this.components;
}	// getComponents


//
// batch processing method
//


componentGroup.prototype.call = function(methodName, parameters) {
  for (var i = 0; i < this.components.length; i++)
  
    // recurse if component is a component group
    //
    if (this.components[i].__proto__ == componentGroup.prototype)
      this.components[i].call(methodName, parameters);
	  
    // call method on component if it exists
    //
    else if (this.components[i][methodName])
      this.components[i][methodName](parameters);
}	// call