/*
	Author: Olu Ayandosu
	Detects when window resize stops and fires an event
*/

(function() {
	var specialEvent = $.event.special,
		guid = 'D' + (+new Date() + 1);

	specialEvent.resizeStop = {
		trottle: 300,

		setup: function() {
			var timer;
				
			var handler = function(evt) {
				var _self = this,
					_args = arguments;
					
				if (timer) { clearTimeout(timer) };

				timer = setTimeout( function(){
					timer = null;
					evt.type = 'resizeStop';
				
					$.event.handle.apply(_self, _args);
				}, specialEvent.resizeStop.trottle);
			};

			$(this).bind('resize', handler).data(guid, handler);
		},

		teardown: function() {
			$(this).unbind( 'resize', $(this).data(guid) );
		}
	};

})();
