ns('Carib.Order.Widgets');

/**
 * Panel
 * 
 * @version $Id: panel.js 398 2009-07-02 15:05:36Z  $
 */
Carib.Order.Widgets.Panel = function(config) {
  // configurable {
  this.selector = ''; //required
  this.id = false;
  this.auto_init = false;
  this.title = '';
  // }
  
  this.addEvents({
    show: true,
    hide: true,
    resize: true
  });
  
  Carib.Order.Widgets.Panel.superclass.constructor.call(this, config);
  
  if(this.auto_init)
    this.init();
}

utils.extend(Carib.Order.Widgets.Panel, utils.Observable, {
  init: function() {
    
  },
  
  show: function() {
    this.getEl().show();
    this.onShow();
  },
  
  hide: function() {
    this.getEl().hide();
    this.onHide();
  },
  
  setWidth: function(width) {
    this.getEl().width(width);
    this.onResize();
  },
  
  setHeight: function(height) {
    this.getEl().height(height);
    this.onResize();
  },
  
  setSize: function(width, height) {
    size = new Size(width, height);
    this.getEl().height(size.height).width(size.width);
    this.onResize();
  },
  
  getSize: function() {
    var $el = this.getEl();
    return new Size($el.outerWidth(), $el.outerHeight());
  },
  
  getTitle: function() {
    return this.title;
  },
  
  onShow: function() {
    this.fireEvent('show', [this]);
  },
  
  onHide: function() {
    this.fireEvent('hide', [this]);
  },
  
  onResize: function() {
    this.fireEvent('resize', [this]);
  },
  
  getEl: function() {
    return $(this.selector);
  },
  
  getId: function() {
    if(!this.id) {
      this.id = this.getEl().generateId().attr('id');
    }
    return this.id;
  }  
});
