﻿Type.registerNamespace('Behaviors');

//Deze class bevat script benodigd voor de Ajax ImageExtender
Behaviors.ImageBehavior = function(element)
{
  Behaviors.ImageBehavior.initializeBase(this, [element]);

  this._normalImageUrl = null;
  this._hoverImageUrl = null;
  this._disabledImageUrl = null;
}

Behaviors.ImageBehavior.prototype = {
  initialize : function()
  {
    Behaviors.ImageBehavior.callBaseMethod(this, 'initialize');
  
    this._onmouseoverHandler = Function.createDelegate(this, this._onMouseOver);
    this._onmouseoutHandler = Function.createDelegate(this, this._onMouseOut);
    this._ommousedownHandler = Function.createDelegate(this, this._onMouseDown);
    this._onmouseupdHandler = Function.createDelegate(this, this._onMouseUp);    
    
    $addHandlers
    (
      this.get_element(),
      { 
        'mouseover' : this._onMouseOver,
        'mouseout': this._onMouseOut,
        'mousedown': this._onMouseDown,
        'mouseup': this._onMouseUp
      },
      this
    );
    
    //Stel initiele afbeelding in
    if(!this.get_element().disabled)
      this.get_element().src = this._normalImageUrl;
    else
      this.get_element().src = this._disabledImageUrl;
  },

  dispose : function()
  {
    $clearHandlers(this.get_element());
    Behaviors.ImageBehavior.callBaseMethod(this, 'dispose');
  },

  _onMouseOver : function(e) {
    if (this.get_element() && !this.get_element().disabled) {
      this.get_element().src = this._hoverImageUrl;
    }
  },

  _onMouseOut : function(e) {
    if (this.get_element() && !this.get_element().disabled) {
      this.get_element().src = this._normalImageUrl;
    }
  },

  _onMouseDown: function(e) {
      if (this.get_element() && !this.get_element().disabled) {
          this.get_element().src = this._normalImageUrl;
      }
  },

  _onMouseUp: function(e) {
      if (this.get_element() && !this.get_element().disabled) {
          this.get_element().src = this._normalImageUrl;
      }
  },

  get_normalImageUrl : function() {
    return this._normalImageUrl;
  },
  set_normalImageUrl : function(value) {
    if (this._normalImageUrl !== value) {
      this._normalImageUrl = value;
      this.raisePropertyChanged('normalImageUrl');
    }
  },

  get_hoverImageUrl : function() {
    return this._hoverImageUrl;
  },
  set_hoverImageUrl : function(value) {
    if (this._hoverImageUrl !== value) {
      this._hoverImageUrl = value;
      this.raisePropertyChanged('hoverImageUrl');
    }
  },

  get_disabledImageUrl : function() {
    return this._disabledImageUrl;
  },
  set_disabledImageUrl : function(value) {
    if (this._disabledImageUrl !== value) {
      this._disabledImageUrl = value;
      this.raisePropertyChanged('disabledImageUrl');
    }
  }
}

Behaviors.ImageBehavior.descriptor = 
{
    properties: [
     {name: 'normalImageUrl', type: String},
     {name: 'hoverImageUrl', type: String},
     {name: 'disabledImageUrl', type: String} 
    ]
}

Behaviors.ImageBehavior.registerClass('Behaviors.ImageBehavior', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 