﻿/**
* hoverIntent is similar to jQuery's built-in "hover" function except that
* instead of firing the onMouseOver event immediately, hoverIntent checks
* to see if the user's mouse has slowed down (beneath the sensitivity
* threshold) before firing the onMouseOver event.
* 
* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* hoverIntent is currently available for use in all personal or commercial 
* projects under both MIT and GPL licenses. This means that you can choose 
* the license that best suits your project, and use it accordingly.
* 
* // basic usage (just like .hover) receives onMouseOver and onMouseOut functions
* $("ul li").hoverIntent( showNav , hideNav );
* 
* // advanced usage receives configuration object only
* $("ul li").hoverIntent({
*	sensitivity: 7, // number = sensitivity threshold (must be 1 or higher)
*	interval: 100,   // number = milliseconds of polling interval
*	over: showNav,  // function = onMouseOver callback (required)
*	timeout: 0,   // number = milliseconds delay before onMouseOut function call
*	out: hideNav    // function = onMouseOut callback (required)
* });
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne <brian@cherne.net>
*/
(function(e) {
  e.fn.hoverIntent = function(l, m) {
    var d = {sensitivity:7, interval:100, timeout:0};
    d = e.extend(d, m ? {over:l, out:m} : l);
    var g, h, i, j, k = function(c) {
      g = c.pageX;
      h = c.pageY
    }, n = function(c, a) {
      a.hoverIntent_t = clearTimeout(a.hoverIntent_t);
      if(Math.abs(i - g) + Math.abs(j - h) < d.sensitivity) {
        e(a).unbind("mousemove", k);
        a.hoverIntent_s = 1;
        return d.over.apply(a, [c])
      }else {
        i = g;
        j = h;
        a.hoverIntent_t = setTimeout(function() {
          n(c, a)
        }, d.interval)
      }
    }, o = function(c) {
      for(var a = (c.type == "mouseover" ? c.fromElement : c.toElement) || c.relatedTarget;a && a != this;) {
        try {
          a = a.parentNode
        }catch(p) {
          a = this
        }
      }
      if(a == this) {
        return false
      }
      var f = jQuery.extend({}, c), b = this;
      if(b.hoverIntent_t) {
        b.hoverIntent_t = clearTimeout(b.hoverIntent_t)
      }
      if(c.type == "mouseover") {
        i = f.pageX;
        j = f.pageY;
        e(b).bind("mousemove", k);
        if(b.hoverIntent_s != 1) {
          b.hoverIntent_t = setTimeout(function() {
            n(f, b)
          }, d.interval)
        }
      }else {
        e(b).unbind("mousemove", k);
        if(b.hoverIntent_s == 1) {
          b.hoverIntent_t = setTimeout(function() {
            b.hoverIntent_t = clearTimeout(b.hoverIntent_t);
            b.hoverIntent_s = 0;
            d.out.apply(b, [f])
          }, d.timeout)
        }
      }
    };
    return this.mouseover(o).mouseout(o)
  }
})(jQuery);
