// ==== CONFIGURATION ====
var TO_BIND = "a,input"; // jQuery selector string used to bind blocking
var BLOCK_TIMEOUT = 2000; // Milliseconds to keep links blocked after a click
// =====================================================================================

var lastObjectClicked;
var lastClickWhen;

function allowClick(object) {
	// If the user is clicking on a different object, or the blocking timeout has expired, allow the click
	if(lastObjectClicked != object || new Date().getTime() - lastClickWhen > BLOCK_TIMEOUT) {
		lastObjectClicked = object;
		lastClickWhen = new Date().getTime();
		return true;
	} else {
		return false;
	}
}
			
$(document).ready(function(){
	$(TO_BIND).each(function(){
		var onclick = "" + $(this).attr("onclick");
		
		// IE fix - for some reason IE produces a function instead of just returning the actual "onclick" code
		if (onclick.indexOf("function") >= 0){
			onclick = onclick + "\nonclick();";
		}
		// IE fix - end
		
		$(this).attr("onclick", "");
		
		if (onclick != ''){
			$(this).bind("click", function (e){				
				var result = allowClick(e.target);
				
				if (result){
					eval(onclick);
				}
			});
		}
	});
});