/*
	__foundation/_js/jquery/jquery.common.js
	purpose: common jquery functions
*/


// - allows binding before existing stack of events
jQuery.fn.preBind = function(namespace, fn) {
	
	var type = namespace.split('.')[0];
	this.bind(namespace, fn);
	
	var currentBindings = this.data('events')[type];
	var currentBindingsLastIndex = currentBindings.length - 1;
	
	var newBindings = [];
	
	newBindings.push(currentBindings[currentBindingsLastIndex]);
	
	jQuery.each(currentBindings, function (index) {
	 if (index < currentBindingsLastIndex)
		newBindings.push(this);
	});
	
	this.data('events')[type] = newBindings;
	
	return this;
};
