(function($) {

	$.fn.reverse = function() {
		return this.pushStack(this.get().reverse(), arguments);
	};

	$.fn.sort = function() {
		return this.pushStack($.makeArray([].sort.apply(this, arguments)));
	};

	$.fn.random = function(startIndex) {
		startIndex = startIndex || 0;
		return this.pushStack(this.eq(startIndex + Math.floor(Math.random() * (this.length - startIndex))));
	};

	$.fn.replace = function() {
		var stack = [];
		return this.domManip(arguments, true, 1, function(a) {
			this.parentNode.replaceChild(a, this);
			stack.push(a);
		}).pushStack(stack);
	};

	$.fn.dump = function(groupTitle) {
		if ("console" in window && "log" in console) {
			if (groupTitle && typeof console.group == "function") console.group(groupTitle);
			for (var i = 0; i < this.length; i++) {
				console.log("(" + i + ") ", this[i]);
			}
			if (groupTitle && typeof console.groupEnd == "function") console.groupEnd();
		}
		return this;
	};

	$.fn.inArray = function(elem, array) {
		return array.indexOf(elem);
	};

	/*$.expr[":"].data = function(elem, index, m) {
		m[0] = m[0].replace(/:data\(|\)$/g, "");
		var regex = new RegExp("(['\"]?)((?:\\\\\\1|.)+?)\\1(,|$)", "g");
		var key = regex.exec(m[0])[2];
		var val = regex.exec(m[0])[2];
		return val ? $(elem).data(key) == val : !!$(elem).data(key);
	};*/

	$.extend($.expr[':'], {
		data: function(elem, i, match) {
			return !!$.data(elem, match[3]);
		}
	});

})(jQuery);
