/*
 * jQuery Plugin: Radius
 * http://www.roydukkey.com/
 *
 * Copyright (c) 2009 Rory Dueck
 *
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Date: yyyy-mm-dd (DDD, dd MMM yyyy)
 * Version: x.x.x
 *
 * NOTE: Please report any improvements to roydukkey-at-gmail-dot-com.
 *       There are still many improvements that can me made to this
 *       script. Thanks to all in the open community.
 */
(function($){
// Do CAST all VARS

$.fn.radius = function(s,t) {
	if (typeof(s) == "number") {
		s={radius: s};
	}
	if (typeof(t) == "string") {
		var a = t.toLowerCase().split(/\s+/), t={};
		for( var i in a ) {
			if( a[i].indexOf("px") != -1 ) {
				t.width = a[i].replace("px","");
				
			} else if( a[i].indexOf("#") != -1 ) {
				t.color = a[i];
				
			} else {
				t.style = a[i]
			}
		}
	}
	
	classID = "doCorner";
	var o = $.extend({
		radius: 10,
		width: 1,
		color: "#000000"
	},s,t);
	
	return this.each(function() {
		if( $.browser.msie ) {
			if( !document.namespaces.v ) document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
						
			f = $(this).css("backgroundColor");
			
			$(this).css({
				backgroundColor: "transparent",
				position: "relative",
				zoom: 1
			});
			
			o.radius = Math.min(o.radius / Math.min(this.offsetWidth, this.offsetHeight), 1);
		
			w = this.offsetWidth;
			h = this.offsetHeight;
			
			this.innerHTML = '<v:roundrect arcsize="'+o.radius+'" strokecolor="'+o.color+'" strokeweight="'+o.width+'" style="behavior:url(#default#VML); width:'+w+'; height:'+h+'; antialias:true; display:block; position:absolute; top:0; left:0; z-index:-1;">'+(f!="transparent"?'<v:fill color="'+f+'" src="" type="tile" style="behavior:url(#default#VML); width:100%; height:100%;" />':'')+'</v:roundrect>'+this.innerHTML;
			
		} else {
			$(this).css({
				border: o.width+"px "+o.style+" "+o.color,
				"-moz-border-radius": ""+o.radius+"px",
				"-webkit-border-radius": ""+o.radius+"px"
			});
		}
		
	})
}

})(jQuery);
