// Plugin to get a more reliable resize-event handling
(function($) {
	$.fn.afterResize = function(callback, options) {		  
		  options = $.extend({}, $.fn.afterResize.defaults, options);
		  
		  return this.each(function() {
		  	var theTimeout=null;
		  	var $this = $(this);
		  
		  	$this.resize(function(ev) {
	  			if (theTimeout)
	  				clearTimeout(theTimeout);
	  				
	  			theTimeout = setTimeout(function() {
	  				theTimeout = null;
	  				callback.call($this.get(0), ev);
	  			}, options.threshold);
		  				
		  		lastResize = ev.timeStamp;
		  	});
		  
		  });
	}

	$.fn.afterResize.defaults = {
		// Callback is only invoked after the hreshold time(milliseconds) has passed an no other 
		// resize events was received. 
		threshold: 500
	};
})(jQuery);
