/**
 * jQuery.bindExist
 * Copyright (c) 2009-2010 Francois-Guillaume Ribreau - jquery(at)fgribreau(dot)com | http://fgribreau.com
 * Dual licensed under MIT and GPL.
 * Date: 9/23/2009
 *
 * @projectDescription Check if a bind's type is specified on an element or not.
 * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
 * Works with jQuery +1.2.3.
 *
 * @author Francois-Guillaume Ribreau
 * @version 1.0.1
 *
 * @id jQuery.fn.bindExist
 * @param {String} eventName.namespace The event bind name to check on.
 *	  Exemple of value:
 *			- click
 *			- mouseover.myNameSpace
 *
 * @return {booleen} Returns true if the bind exist.
 *
 * @desc Test without namespace
 * @example $('#myDiv').bindExist('click');//return false
 *			$('#myDiv').bind('click',function(){});
 *			$('#myDiv').bindExist('click');//return true
 *
 * @desc Test without namespace
 * @example $('#myDiv').bindExist('click.myNS');//return false
 *			$('#myDiv').bind('click.myNS',function(){});
 *			$('#myDiv').bindExist('click.myNS');//return true
 *
*/

(function($){
	$.fn.bindExist = function(bindName){
		var bind = (bindName?bindName:'').split('.'),
			ret = false;
		
		if(bind.length == 1){
			ret = (typeof this.data('events')[bind[0]] !== 'undefined');
		}
		else{
			var evt = this.data('events');
			if(evt){
				for(i in evt[bind[0]]){
					if(evt[bind[0]][i].type == bind[1]){
						ret = true;
						break;
					}
				}
			}
			else
				return false;
		}
		
		return ret;
	};
})(jQuery);