/*
 * @name: 				jExists
 * @version:			1.0
 * @jQuery method name:	ifE
 * @author: 			Max Shindler <max.shindler@gmail.com>
 * @desc:				Simple extension adding a possibility to check if 
 * 						there have been found some elements and then executes the code
 * @params: 			{ ok: function callback if found, no: function callback if not found }
 * 						or just pass a function which while be called when something found
 */
(function($) {
	jQuery.fn.ifE = function(param1, param2) {
		
		var options = {
				okCallback: null,
				noCallback: null
			};
		
		if(typeof param1 == 'object') { jQuery.extend(options, param1); }
		else if(typeof param1 == 'function') { options.okCallback = param1; }
		
		if(this.length === 0) {
			if(typeof options.noCallback == 'function') {
				options.noCallback();
				return this;
			} else {
				return false;
			}	
		} else {
			if(typeof options.okCallback == 'function') {
				this.each(function(index, o) { options.okCallback(o); });
				return this;
			} else {
				return true;
			}		
		}
		
		return this;
	};
})(jQuery);
