if (!Ext.ww) Ext.ww={}
Ext.ww.ExpandCollapse = function(conf) {
  Ext.apply(this, {
    iMinHeight: 1,
    texts: [], 
    initial: function () {
      this.items = this.getElements_Expandable();
      if (this.items.length < 1) return false;
      for(var i=0; i<this.items.length; i++) {
        this.items[i].cid = this.items[i].dom.getAttribute('cid');
        if (this.items[i].cid) this.manipulate(this.items[i], i);
      }
    },
    manipulate: function (el, index) {
      this.setPointer(el);
      el.index = index;
      el.ownerCt = this;
      el.ct = this.getElement_Content(el, this);
      el.updateStatus = function () {
        this.dom.setAttribute('status', this.uptStatus);
        this.dom.innerHTML = this.uptHtml;
        this.setStyle('cursor', 'pointer');
      }
      el.on('click', this.onclick, el);
    },
    manipulate_contentEl: function (el, scope) {
      el.initHeight = el.getHeight();
      el.setStyle('overflow', 'hidden');
      el.setHeight(scope.iMinHeight);
      el.hide();
    },
    onclick: function () {
      var status = this.dom.getAttribute('status');
      if (status != 'loading') {
        this.ownerCt.setUpdateText(this, status);
        this.uptStatus = (status=='hide')?'show':'hide';
        var uptStatus = this.uptStatus;
        
        this.dom.setAttribute('status', 'loading');
        this.ownerCt.setDefault(this);
        this.dom.innerHTML = '<img src="/admin/img/ext/tree/loading.gif" border="0"/>';
        if (uptStatus=='show') {
          var iHeight = this.ct.initHeight;
          this.ct.show();
          this.ct.setHeight(iHeight, {duration: 1, scope: this, 
            callback: function () { 
              this.updateStatus(); 
            }
          });        
        } else {
          this.ct.setHeight(this.ownerCt.iMinHeight, {duration: 1, scope: this, 
            callback: function () { 
              this.updateStatus() 
              this.ct.hide();
            }
          });
        }
      }
    },
    setPointer: function (el) {
      el.setStyle('cursor', 'pointer');
    },
    setDefault: function (el) {
      el.setStyle('cursor', 'default');
    }, 
    setUpdateText: function (el, status) {
      var html = el.dom.innerHTML;
      el.uptHtml = (status=='hide')?html.replace('Show', 'Hide'):html.replace('Hide', 'Show');
      var scope = el.ownerCt;
      if (scope.texts.length > 0) {
        var i = el.index;
        var sStatus = (status=='hide')?'toHide':'toShow';
        if (typeof(scope.texts[i][sStatus]) == 'string') el.uptHtml = scope.texts[i][sStatus];
      }
    },
    getElement_Content: function (el, scope) {
      var id = el.cid;
      var oReturn = Ext.get(id);
      this.manipulate_contentEl(oReturn, scope);
      return oReturn;
    },
    getElements_Expandable: function () {
      var arrReturn = []
      var objs = Ext.query('a[status]');
      for (var i=0; i<objs.length; i++) {
        arrReturn.push(Ext.get(objs[i]));
      }
      return arrReturn;
    }
  });
  Ext.apply(this, conf);
  this.initial.call(this);
}