// throttleing
var timerID = null;
var start = -1;
var times = new Array();
var dif = 2000;
$.swim.throttle = {};
$.swim.throttle.addjustTime = function(newTime){
	if(newTime > 1500) newTime = 1500;
	if(times.length < 4){
		times.push(newTime);
	}else{
		times[3] = times[2];
		times[2] = times[1];
		times[1] = times[0];
		times[0] = newTime;
	}
	var ret = $.swim.throttle.getAverage(times);
	return ret;
};
$.swim.throttle.getAverage = function(array){
	var val = 0;
	for(var i = 0; i < array.length; i++){
		val += array[i];
	}
	return val / array.length;
};
$.swim.throttle.throttle = function(callBack){
	if(start > -1){
		dif = $.swim.throttle.addjustTime((new Date().getTime() - start) + 100);
	}
	start = new Date().getTime();
	if(timerID != null){
		clearTimeout(timerID);
		timerID = null;
	}
	timerID = setTimeout(callBack, dif);
};
(function($){
	$.fn.throttleElement = function(preThrottle, postThrottle){
		if(preThrottle == null) preThrottle = doNTG;
		if(postThrottle == null) postThrottle = doNTG;
		$(this).bind('keyup', function(){
			eval(preThrottle);
			$.swim.throttle.throttle(postThrottle);
		});
	}
})(jQuery);
// end throttleing