$.fn.corner = function(o)
{
	function gpc(node)	{
		for ( ; node && node.nodeName.toLowerCase() != "html"; node = node.parentNode  ) {
			var v = $.css(node,"backgroundColor");
			if ( v && v != "transparent" )
				return v;
		}
		return "#ffffff";
    };
	o = o || "";
	var width = parseInt((o.match(/(\d+)px/)||[])[1]) || 10;
	var fx = (o.match(/round|bevel|fold|notch/)||["round"])[0];
	var opts = {
		TL:		/top|tl/i.test(o), 		TR:		/top|tr/i.test(o),
		BL:		/bottom|bl/i.test(o),	BR:		/bottom|br/i.test(o)//,
	};
	if ( !opts.TL && !opts.TR && !opts.BL && !opts.BR )
		opts = { TL:1, TR:1, BL:1, BR:1 };
	var topBorder = "none "+(opts.TR?"solid":"none")+" none "+(opts.TL?"solid":"none");
	var botBorder = "none "+(opts.BR?"solid":"none")+" none "+(opts.BL?"solid":"none");
	return this.each(function(){
		var pad = {
			T: parseInt($.css(this,"paddingTop"))||0,
			R: parseInt($.css(this,"paddingRight"))||0,
			B: parseInt($.css(this,"paddingBottom"))||0,
			L: parseInt($.css(this,"paddingLeft"))||0
		};
		var strip = document.createElement("div");
		var s = strip.style;
		s.overflow = "hidden";
		s.height = "1px";
		s.backgroundColor = "transparent";
		s.borderStyle = "solid";
		s.borderColor = gpc(this.parentNode);
		var t=document.createElement("div");
		var b=document.createElement("div");
		t.style.backgroundColor = b.style.backgroundColor = "transparent";
		t.style.margin = "-"+pad.T+"px -"+pad.R+"px "+(pad.T-width)+"px -"+pad.L+"px";
		b.style.margin = (pad.B-width)+"px -"+pad.R+"px -"+pad.B+"px -"+pad.L+"px";
		for ( var i=0; i < width; i++ ) {
			var w = fx=="round"? Math.round(width*(1-Math.cos(Math.asin(i/width)))) : i+1;
			var e = strip.cloneNode(false);
			e.style.borderWidth = "0 "+(opts.TR?w:0)+"px 0 "+(opts.TL?w:0)+"px";
			e.style.borderStyle = topBorder;
			t.insertBefore(e.cloneNode(false), t.firstChild);
			e.style.borderWidth = "0 "+(opts.BR?w:0)+"px 0 "+(opts.BL?w:0)+"px";
			e.style.borderStyle = botBorder;
			b.appendChild(e);
		}
		this.insertBefore(t, this.firstChild);
		this.appendChild(b);
	});
};
