var Buttress = function () {

  return {

    version: '0.1',
    
    namespace: function () {
      var a = arguments, o = null, i, j, d;
      for (i=0; i<a.length; i += 1) {
        d=a[i].split(".");
        o = this;

        //
        // Create the given namespace (including the last item)
        //
        // If the Buttress name is included, it is omitted because it is 
        // implied.
        // 
        // The base algorithm for this comes from the YAHOO.register function.
        //
        for (j=(d[0] == "Buttress") ? 1 : 0; j < d.length; j += 1) {
          o[d[j]]=o[d[j]] || {};
          o=o[d[j]];
        }
      }

      return o;
    },

    register: function (namespace, toRegister) {
      var o = null, j, d;

      d = namespace.split(".");
      o = this;

      //
      // Create the given namespace up to but not including the very last one
      //
      // If the Buttress name is included, it is omitted because it is implied.
      //
      // The base algorithm for this comes from the YAHOO.register function.
      //
      for (j = (d[0] == "Buttress") ? 1 : 0; j < d.length - 1; j += 1) {
        o[d[j]] = o[d[j]] || {};
        o = o[d[j]];
      }

      // now add the final namespace item and assign the given object to it.
      o[d[d.length - 1]] = toRegister;
    },

    configure: function (config, defaults) {
      var k;

      if (defaults) {
        for (k in defaults) if (defaults.hasOwnProperty(k)) {
          this[k] = defaults[k];
        }
      }

      if (config) {
        for (k in config) if (config.hasOwnProperty(k)) {
          this[k] = config[k];
        } 
      }
    },

    insist: function (these) {
      for (var i=0; i<these.length; i += 1) {
        if (!this[these[i]]) {
          throw new Error(this + ' insists on having ' + these);
        }
      }
    }
  };
}();

