(function($) {
	$.fn.extend({
		niftycorners: function(top,bottom,bg) {
			if(top == 'both') top = '';
			if (bottom == 'both') bottom = '';
			ptop = this.css('padding-top');
			pbot = this.css('padding-bottom');
			plef = this.css('padding-left');
			prig = this.css('padding-right');
			heig = this.innerHeight() - (parseInt(ptop) + parseInt(pbot));
			widt = this.innerWidth();
			add = 0;
			this.css('padding','0');
			this.wrapInner('<div class="rinnerbox"></div>');
			this.children('div.rinnerbox').css('background-image',bg);			
	
			if (top != 'none'){
				this.prepend('<b class="rtop' + top + '"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b><b class="r5"></b><b class="r6"></b><b class="r7"></b><b class="r8"></b></b>');
				this.children('b.rtop' + top).children().css('background-image',bg);
				ptop = parseInt(ptop)-9;
				add = add + 9;
				if (ptop < 0) {heig = heig + ptop; ptop = 0;};
				ptop = ptop +'px'
			};
			
			if (bottom != 'none'){
				this.append('<b class="rbottom' + bottom + '"><b class="r8"></b><b class="r7"></b><b class="r6"></b><b class="r5"></b><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>');
				this.children('b.rbottom'+ bottom).children().css('background-image',bg);
				pbot = parseInt(pbot)-9;
				add = add + 9;
				if (pbot < 0) {heig = heig + pbot;pbot = 0;};
				pbot = pbot +'px'
			};
			if (heig < 0) heig = 0;
			this.children('div.rinnerbox').css('padding', ptop + ' ' + prig + ' ' + pbot + ' ' + plef);
			this.children('div.rinnerbox').css('height',heig + 'px');
			this.css('height', 'auto');
			this.css('width', widt+'px')
			return this.css('background-image','none');
			
			}
	});
})(jQuery);
