/* Copyright (c) 2010 Brandon Aaron (http://brandonaaron.net)
 * Licensed under the MIT License (LICENSE.txt).
 *
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 * Thanks to: Seamus Leahy for adding deltaX and deltaY
 *
 * Version: 3.0.3
 *
 * Requires: 1.2.2+
 */
 /**
 * jQuery mousehold plugin - fires an event while the mouse is clicked down.
 * Additionally, the function, when executed, is passed a single
 * argument representing the count of times the event has been fired during
 * this session of the mouse hold.
 *
 * @author Remy Sharp (leftlogic.com)
 * @date 2006-12-15
 * @example $("img").mousehold(200, function(i){  })
 * @desc Repeats firing the passed function while the mouse is clicked down
 *
 * @name mousehold
 * @type jQuery
 * @param Number timeout The frequency to repeat the event in milliseconds
 * @param Function fn A function to execute
 * @cat Plugin
 */


(function(c){var a=["DOMMouseScroll","mousewheel"];c.event.special.mousewheel={setup:function(){if(this.addEventListener){for(var d=a.length;d;){this.addEventListener(a[--d],b,false)}}else{this.onmousewheel=b}},teardown:function(){if(this.removeEventListener){for(var d=a.length;d;){this.removeEventListener(a[--d],b,false)}}else{this.onmousewheel=null}}};c.fn.extend({mousewheel:function(d){return d?this.bind("mousewheel",d):this.trigger("mousewheel")},unmousewheel:function(d){return this.unbind("mousewheel",d)}});function b(i){var g=i,f=[].slice.call(arguments,1),j=0,h=true,e=0,d=0;i=c.event.fix(i||window.event);i.type="mousewheel";if(i.wheelDelta){j=i.wheelDelta/120}if(i.detail){j=-i.detail/3}d=j;if(g.axis!==undefined&&g.axis===g.HORIZONTAL_AXIS){d=0;e=-1*j}if(g.wheelDeltaY!==undefined){d=g.wheelDeltaY/120}if(g.wheelDeltaX!==undefined){e=-1*g.wheelDeltaX/120}f.unshift(i,j,e,d);return c.event.handle.apply(this,f)}})(jQuery);
jQuery.fn.mousehold = function(timeout, f, delay)
	{
	//Allows us to pass only one parameter
	if	(timeout && typeof timeout == 'function')
			{
			f = timeout;
			timeout = 100;
			}

	//If there is no delay, set a default
	if	(!delay)
			{
			var delay = 500;
			}

	//Only continue if it's been passed a function, this is infact a function
	if (f && typeof f == 'function')
		{
		var timer = 0;
		var delaytimer = 0;
		var fireStep = 0;

		return this.each(function()
				{
				jQuery(this).mousedown(function()
					{
					fireStep = 1;
					var ctr = 0;
					var t = this;

					delaytimer = setTimeout(function ()
						{
						timer = setInterval(function()
							{
							ctr++;
							f.call(t, ctr);
							fireStep = 2;
							}, timeout);
						}, delay);
					});

				//This makes sure that as we mouse out, or mouse up - all the timers are stopped
				clearMousehold = function()
					{
					clearInterval(timer);
					clearTimeout(delaytimer);
					if (fireStep == 1) f.call(this, 1);
					fireStep = 0;
					}
			
				jQuery(this).mouseout(clearMousehold);
				jQuery(this).mouseup(clearMousehold);
				});
		}
	}
