/*
 * jQuery rounded corner plugin
 *
 * version 0.1 (05/27/2007)
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */
(function($) { 

	$.fn.extend({
		rcorner: function(radius){
			var $ = jQuery;
			var getW = function(width,i){
				Math.round(width * (1 - Math.cos(Math.asin(i / width))));
			};
			/*
			 * function getW(w,i){
			 return Math.round(w*(1-Math.cos(Math.asin(i/w))));
			 };
			 */
			$(this).each(function(){
				var el = $(this);
				var elBg = $(this).css("backgroundColor");
				el.wrap("<div></div>");
				
				var wrapper = el.parent();								
				
				wrapper.css({
					position:	"absolute",
					top:		el.css("top"),
					left:		el.css("left"),
					right:		el.css("right"),
					bottom:		el.css("bottom"),
					padding:	0,
					margin:		0,
					zoom:		1
				});
				el.css({
					position:	"relative",
					display:	"block",
					top:		0,
					left:		0,
					zoom:		1
				});
				var width = el.outerWidth();
				var margins = new Array();
				switch(radius)
				{
					case 0:
					case 1:
						margins = [1];
					break;
					case 2:
						margins =[1,2];
					break;
					default:
						for(var i=0;i<radius;i++) margins.push(Math.round(radius * (1 - Math.cos(Math.asin(i / radius)))));
					break;	
				}
				for (i=0;i<margins.length;i++){
					wrapper.prepend("<div style='position:relative;width:"+(width-(margins[i]*2))+"px;zoom:1;height:1px;background-color:"+elBg+";margin:0 "+margins[i]+"px;'></div>");
					wrapper.append("<div style='position:relative;width:"+(width-(margins[i]*2))+"px;zoom:1;height:1px;background-color:"+elBg+";margin:0 "+margins[i]+"px;'></div>");
				}
				
					
			});
			
			
		}	
		
		
	});
    
})(jQuery);
