// Hover.js
// Javascript Behaviour for the Hover Visual Effect
// Copyright (c) by Matthias Hertel, http://www.mathertel.de
// This work is licensed under a BSD style license. See http://www.mathertel.de/License.aspx
// ----- 
// 02.04.2006 created by Matthias Hertel
// 11.07.2007 enabling disabled elements
// 11.07.2007 enabling selected elements
// 28.12.2007 documentation
// 01.10.2010 IE9 compatibility avoiding browser detection.

jcl.HoverBehavior = {
  /// <summary>Implementation of  JavaScript based mouse hover effect.<br />
  /// The hover behavior must be attached to the document level only once. 
  /// To enable this effect it is necesary to just include this file.</summary>

  // ----- Properties -----
  _obj: null, /// <summary>The current hovered object.</summary>

  // --- events

  onmouseover: function (evt) {
    /// <summary>Handle mouseover event. If the object underneath the mousepointer
    /// is enabled for the hover effect the classname is extended by "Hover".</summary>
    var obj = evt.srcElement;

    if ((obj != null) && (obj.getAttribute) && (obj.getAttribute("hover") != null)) // IE9 compatible
      obj.hover = true;
    if ((obj != null) && (obj.hover != null) && (obj != jcl.HoverBehavior._obj) &&
      (obj.className.indexOf("disabled") < 0) && (obj.className.indexOf("selected") < 0)) {
      jcl.HoverBehavior._obj = obj;
      obj.className = obj.className + "Hover";
    } // if
  }, // onmouseover


  onmouseout: function (evt) {
    /// <summary>Handle mouseout event. Remove the hover effect from the object.</summary>
    var obj = evt.srcElement;
    if ((obj != null) && (obj == jcl.HoverBehavior._obj)) {
      var cn = obj.className.split(" ");
      cn[0] = cn[0].replace(/(Pushed|Hover)$/, "");
      obj.className = cn.join(" ");
      jcl.HoverBehavior._obj = null;
    } // if 
  }, // onmouseout


  onmousedown: function (evt) {
    /// <summary>Handle mousedown event. If the object underneath the mousepointer
    /// is enabled for the hover effect the classname is now extended by "Pushed".</summary>
    var obj = evt.srcElement;
    if (obj == jcl.HoverBehavior._obj)
      obj.className = obj.className.replace(/(Pushed|Hover)$/, "") + "Pushed";
  }, // onmousedown


  onmouseup: function (evt) {
    /// <summary>Handle mouseup event. If the object underneath the mousepointer
    /// is enabled for the hover effect the classname is un-"Pushed" and extended by "Hover".</summary>
    var obj = evt.srcElement;
    if (obj == jcl.HoverBehavior._obj)
      obj.className = obj.className.replace(/(Pushed|Hover)$/, "") + "Hover";
  } // onmouseup

} // jcl.HoverBehavior

jcl.LoadBehaviour(document, jcl.HoverBehavior);

