(function ($) {
	$.expr[":"].childOf = function () {
		return ($(arguments[0]).parents(arguments[2][3]).length > 0);
	}
	$.extend({
		increment : function ( string ) {
			var incrementBy = (!isNaN(parseInt(arguments[1])) ? parseInt(arguments[1]) : 1), pattern = new RegExp(/\d+/gi);
			return (string.length && string.match(pattern) ? string.replace(pattern, parseInt(string.match(pattern)[0]) + incrementBy) : string + incrementBy);
		}
	});
	$.fn.extend({
		appendChain : function (element) {
			var children = [];
			this.each(function () {
				that = $(document.createElement("div")).append(element);
				that.children().each(function () { children.push(this); }).appendTo(this);
				that.remove();
			});
			return $(children);
		},
		increment : function ( key ) {
			var incrementBy = (arguments[1] || 1);
			return this.each(function () {
				$(this).attr(key, $.increment($(this).attr(key), incrementBy));
			});
		},
		prependChain : function (element) {
			var children = [];
			this.each(function () {
				that = $(document.createElement("div")).append(element);
				that.children().each(function () { children.push(this); }).prependTo(this);
				that.remove();
			});
			return $(children);
		},
		scrollTo : function (top, left, speed) {
			left = (typeof left == "number" ? left : 0);
			speed = (typeof speed == "number" ? speed : 0);
			top = (typeof top == "number" ? top : 0);
			this.each(function () {
				if (speed > 0) jQuery(this).animate({ scrollLeft : left, scrollTop : top }, speed);
				else if (this.scrollTo) this.scrollTo(left, top);
			});
			return this;
		},
		scrollToTop : function (speed) {
			this.each(function () {
				scrollTo(0, 0, speed);
			});
		},
		stopLoading : function () {
			if (navigator.userAgent.search(/msie/gi) >= 0) {
				if (jQuery(document).children("iframe#stopLoading").length == 0) {
					iframe = document.createElement("iframe");
					iframe.height = iframe.width = 1;
					iframe.id = iframe.name = "stopLoading";
					document.appendChild(iframe);
				}
				jQuery(document).children("iframe#stopLoading").attr("src", "");
			}
		}
	});
	if (!$().delay)
		$.fn.extend({
			delay : function (time,func) {
				this.each(function(){
					if (typeof(x) == "number") clearTimeout(x);
					x = setTimeout(func,time);
				});
				return this;
			}
		});
})(jQuery);

