// Register the namespace for the control.
Type.registerNamespace('KommodeControls');

//Define the custom control class which receives a reference to the
//DOM elenet it is associated with.
KommodeControls.PageCommentsForm = function(element) { 
    
  //Initialize the base class, passing a reference to the DOM element.  
  KommodeControls.PageCommentsForm.initializeBase(this, [element]);

  // Private class properties
  this._doShow = false;
  this._expanded = true;
  this._buttonId = null;
  this._buttonUniqueId = null;
  
}

// Create the prototype for the control.
KommodeControls.PageCommentsForm.prototype = {

  //Initialize the custom control class.
  initialize : function() {
    
    //Initialize the base class, passing a reference to the DOM element.  
    KommodeControls.PageCommentsForm.callBaseMethod(this, 'initialize');

    if (this._doShow) {
      this.showForm();
    }

  },

  //Clean-up the custom control class.
  dispose : function() {

    //Clear the behavior event handlers associated with DOM element.
    $clearHandlers(this.get_element());
    //Call the base class dispose() method.
    KommodeControls.PageCommentsForm.callBaseMethod(this, 'dispose');
  },


  /*Properties*/

  get_doShow : function() {
    return this._doShow;
  },
  set_doShow : function(value) {
    if (this._doShow !== value) {
      this._doShow = value;
    }
  },

  get_expanded : function() {
    return this._expanded;
  },
  set_expanded : function(value) {
    if (this._expanded !== value) {
      this._expanded = value;
    }
  },

  get_buttonId : function() {
    return this._buttonId;
  },
  set_buttonId : function(value) {
    this._buttonId = value;
  },

  get_buttonUniqueId : function() {
    return this._buttonUniqueId;
  },
  set_buttonUniqueId : function(value) {
    this._buttonUniqueId = value;
  },


  /* Custom functions */

  showForm : function () {
	var item = $(this.get_element());
	if (item) {
      Effect.SlideDown(item, {duration: .3});
	}
  },

  hideForm : function () {
    var item = $(this.get_element());
    if ((item) && (this._buttonUniqueId)) {
      Effect.SlideUp(item, {duration: .3, afterFinish: (function () {
        __doPostBack(this._buttonUniqueId, '');
      }).bindAsEventListener(this)});
    }
  }

}

// Optional descriptor for JSON serialization.
/*
KommodeControls.PageCommentsForm.descriptor = 
{
    properties: 
    [
      {name: 'doShow', type: Boolean},
      {name: 'expanded', type: Boolean},
      {name: 'buttonId', type: String},
      {name: 'buttonUniqueId', type: String},
    ]
}
*/

//Register the PageCommentsForm class with the client AJAX library and specify
//its base class as Sys.UI.Control.
KommodeControls.PageCommentsForm.registerClass('KommodeControls.PageCommentsForm', Sys.UI.Control);

//Notify the Sys.Application class this script has been loaded.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
