/*
 * ******************************************************************************
 *  jquery.mb.components
 *  file: jquery.hoverIntent.min.js
 *
 *  Copyright (c) 2001-2014. Matteo Bicocchi (Pupunzi);
 *  Open lab srl, Firenze - Italy
 *  email: matteo@open-lab.com
 *  site: 	http://pupunzi.com
 *  blog:	http://pupunzi.open-lab.com
 * 	http://open-lab.com
 *
 *  Licences: MIT, GPL
 *  http://www.opensource.org/licenses/mit-license.php
 *  http://www.gnu.org/licenses/gpl.html
 *
 *  last modified: 07/01/14 22.50
 *  *****************************************************************************
 */

(function(a) {
  a.fn.hoverIntent = function(k, j) {
    var l = {
      sensitivity: 7,
      interval: 100,
      timeout: 0
    };
    l = a.extend(l, j ? {
      over: k,
      out: j
    } : k);
    var n, m, h, d;
    var e = function(f) {
      n = f.pageX;
      m = f.pageY
    };
    var c = function(g, f) {
      f.hoverIntent_t = clearTimeout(f.hoverIntent_t);
      if ((Math.abs(h - n) + Math.abs(d - m)) < l.sensitivity) {
        a(f).unbind("mousemove", e);
        f.hoverIntent_s = 1;
        return l.over.apply(f, [g])
      } else {
        h = n;
        d = m;
        f.hoverIntent_t = setTimeout(function() {
          c(g, f)
        }, l.interval)
      }
    };
    var i = function(g, f) {
      f.hoverIntent_t = clearTimeout(f.hoverIntent_t);
      f.hoverIntent_s = 0;
      return l.out.apply(f, [g])
    };
    var b = function(q) {
      var o = (q.type == "mouseover" ? q.fromElement : q.toElement) || q
        .relatedTarget;
      while (o && o != this) {
        try {
          o = o.parentNode
        } catch (q) {
          o = this
        }
      }
      if (o == this) {
        return false
      }
      var g = jQuery.extend({}, q);
      var f = this;
      if (f.hoverIntent_t) {
        f.hoverIntent_t = clearTimeout(f.hoverIntent_t)
      }
      if (q.type == "mouseover") {
        h = g.pageX;
        d = g.pageY;
        a(f).bind("mousemove", e);
        if (f.hoverIntent_s != 1) {
          f.hoverIntent_t = setTimeout(function() {
            c(g, f)
          }, l.interval)
        }
      } else {
        a(f).unbind("mousemove", e);
        if (f.hoverIntent_s == 1) {
          f.hoverIntent_t = setTimeout(function() {
            i(g, f)
          }, l.timeout)
        }
      }
    };
    return this.mouseover(b).mouseout(b)
  }
})(jQuery);
