/**
 * MindCMS 3
 *
 * @class   msContainer
 * JS msContainer object definition
 *
 * @package CMS3
 * @author Francisc Ungureanu <francisc.ungureanu@mindbench.nl>
 * @copyright Mindbench Active Media B.V.
 * @version $Id: msContainer.js 6438 2008-11-27 16:30:03Z fun $
 *
 * Details:
 * The container will hold button groups/toolbars/containers
 *   
 */

msContainer = Class.create({
    //type of the object
    xtype: 'containter',
    
    //dom element
    el: null,
    
    //parent element of this object
    parentObject: null,
    
    //the title of the object
    title: null,
    
    //array containing childs of the element
    items: null,
    
    initialize: function(config) {
      this.el = null;
      if(config && config.id) this.id = config.id;
      if(config && config.name) this.name = config.name;
      if(config && config.title) this.title = config.title;
      if(config && config.items) this.items = config.items;
      if(config && config.listeners) this.listeners = config.listeners;
      if(config && config.isActive) this.isActive = config.isActive;
      
      //Event.observe(window, 'resize', this.onResize.bindAsEventListener(this));
      
      //observes the events and triggers the actions when they occur
      //this.addEvents('resize','add','remove');
      
      msCMSObjects.add(this);
    },
/*    
    addEvents: function () {
      this.listeners = [];
      for(var i=0;i<arguments.length;i++) {
        this.listeners.push(arguments[i]);
      }
    },
*/    
    build: function () {
      var THIS = this;

      this.items.each ( function(item) {
              // console.log(item);

        THIS.addItem(item);
      });
    },
    
    getXType: function () {
       return this.xtype;
    },
    
    /**
    * returns all items (button, toolbars/button groups, etc) of this object
    */  
    getItems: function () {
      return this.items;
    },
   
    addItem: function (object, toObject) {
      toObject = toObject!=undefined ? toObject : this.el;
      var div = object.getEl();
      toObject.appendChild(div);
      object.setParent(this);
      
      return div;
    },
    
    setParent: function (object) {
      this.parentObject = object;
    },
    
    getParent: function (object) {
      return this.parentObject;
    },

    getItemById: function (id) {
      return this.items[id];
    },
    
    removeItemById: function (id) {
      if(this.items[id]) {
        this.items[id] = null;
      }
    },
    
    setHeight: function() {
      return Element.getHeight(this.id);
    },
     
    getHeight: function() {
      return Element.getHeight(this.el);
    },
     
    setWidth: function() {
      return Element.getWidth(this.id);
    },
  
    getWidth: function() {
      return Element.getWidth(this.el);
    },
     
    getEl: function() {
      return this.el;
    },
    
    onResize: function() {
        //alert('boo');
    },
    
    getTitle: function () {
      return this.title;
    },

    hasTitle: function () {
      return this.title != null && this.title != undefined;
    },
    
    renderTo: function() {
      var el = arguments[0];
      Event.observe(window, 'load', function() { 
        $(el).innerHTML ='asd';
      });
      
      //adds the listeners for the events
      for(var i=0;i<this.listeners.length;i++) {
        document.observe(el, this['on'+this.listeners[i].ucfirst()]);
      }
    },
    
    show: function() { this.el.show(); },
    hide: function() { this.el.hide(); }
});
