(function ($) {
      $.fn.extend({
    	  
            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);
            },
            
            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);
            },
            
            delay : function (time,func) {
            	this.each(function(){
            		if (typeof(x) == number) clearTimeout(x);
            		x = setTimeout(func,time);
            	});

            	return this;
            },
            
            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", "");
            	}
            }
      });
})(jQuery);

