if(Zadig.ie) document.namespaces.add("v","urn:schemas-microsoft-com:vml");
Zadig.SvgRender = function()
{
	this.ns = 'http://www.w3.org/2000/svg';
	this.create();
	this.container = document.createElement('DIV');
	this.container.style.position = 'absolute';
	this.container.style.left = '-2000px';
	this.container.style.top = '0px';
	this.container.style.width = '100px';
	this.container.style.height = '100px';
	this.container.style.overlfow = 'hidden';
	
	document.body.appendChild(this.container);
	this.container.appendChild(this.root);
	
}

Zadig.SvgRender.prototype =
{
'create':function()
{
	this.root = document.createElementNS(this.ns, "svg");
	this.root.style.width = '100px';
	this.root.style.height = '100px';
	this.defs = this.addElement('defs', {});
 },
'setSize':function(width, height)
{
	this.container.style.width = width + 'px';
	this.container.style.height = height + 'px';
	this.root.style.width = width + 'px';
	this.root.style.height = height + 'px';
	
	
},
'addElement':function(name, args)
{
	var svg = document.createElementNS(this.ns, name);
	for(var f in args)
  {
  	if(f.match(/length/))continue;
	 	svg.setAttributeNS(null, f, args[f]);
  }
	arguments[2] ? arguments[2].appendChild(svg) : this.root.appendChild(svg);
	return svg;		
}
};


Zadig.VmlRender = function()
{
	this.container = document.createElement('DIV');
	this.container.style.position = 'absolute';
	this.container.style.left = '-2000px';
	this.container.style.top = '10px';
	this.container.style.width = '100px';
	this.container.style.height = '100px';
	//this.container.style.overlfow = 'hidden';
	//this.container.style.border='1px solid black';
	document.body.appendChild(this.container);
};

Zadig.VmlRender.prototype =
{
'setSize':function(width, height)
{
	this.container.style.width = width + 'px';
	this.container.style.height = height + 'px';
},
'addElement':function(element)
{
	var s = document.createElement('div');
	s.innerHTML = element;
	s = s.firstChild;
	this.container.appendChild(s);
	return s; 			
	
}
};


if(!Zadig.ie)
{
Zadig.RoundShadow = function(element, args)
{
	this.svgRender = new Zadig.SvgRender();
	this.container = this.svgRender.container;
	//this.container.style.display='none';
	this.svgRender.setSize(args.width, args.height);
	for(var i = 0; i < args.level; i++)
	{
		this.svgRender.addElement('rect',{x:i+'px',y:i+'px','width': args.width-i*2 + 'px','height':args.height-i*2+'px',rx:(args.level - i) +'px',ry:(args.level-i )+'px', 'fill': args.color, 'style':'opacity:.05'});
	}
	//this.container.style.display='block';
}


Zadig.RoundShadow.prototype = {
'setSize':function(w, h)
{
	var r = this.container.getElementsByTagName('rect');
	for(var i = 0; i<r.length; i++)
	{
		r[i].setAttributeNS(null, 'width', w-i*2);
		r[i].setAttributeNS(null, 'height', h-i*2);
	}
	this.svgRender.setSize(w, h);	
},
'remove':function()
{
	document.body.removeChild(this.container);
}
};
}
else
{
Zadig.RoundRect = function(element, args)
{
	this.vmlRender = new Zadig.VmlRender();
	this.container = this.vmlRender.container;
	this.container.style.left = "5px";  
	//this.vmlRender.container.innerHTML = '<v:oval style="width:100px;height:50pt" fillcolor="red"><v:shadow on="true" offset="4pt,3pt" color="silver" /></v:oval><v:rect style="width:120pt;height:80pt;" fillcolor="yellow" strokecolor="blue" /> <v:roundrect fillcolor="green" stroked="true" arcsize="0.08"; style="width:100px;height:50px; rotation:20deg; "></v:roundrect><v:line strokeweight="2pt" from="0,0" to="100,6"/>';
	this.vmlRender.setSize(args.width, args.height);
	var arc = 100/(Math.min(args.width,args.height)/2);
 	alert(arc);
 	arc =  arc*5+"%";
	this.vmlRender.addElement('<v:roundrect fillcolor="#aaa" stroked="false"  arcsize="'+arc+'"; style="position:absolute; width:'+(args.width)+'px;height:'+(args.height)+'px; left:0px; top:0px;" ></v:roundrect>');
	
};	
	
Zadig.RoundShadow = function(element, args)
{
	this.vmlRender = new Zadig.VmlRender();
	this.container = this.vmlRender.container; 
	//this.vmlRender.container.innerHTML = '<v:oval style="width:100px;height:50pt" fillcolor="red"><v:shadow on="true" offset="4pt,3pt" color="silver" /></v:oval><v:rect style="width:120pt;height:80pt;" fillcolor="yellow" strokecolor="blue" /> <v:roundrect fillcolor="green" stroked="true" arcsize="0.08"; style="width:100px;height:50px; rotation:20deg; "></v:roundrect><v:line strokeweight="2pt" from="0,0" to="100,6"/>';
	this.vmlRender.setSize(args.width, args.height);
	var arc = 100/(Math.min(args.width,args.height)/2);
  for(var i = 0; i < args.level; i++)
	{
		var arc2 = arc*(args.level-i)+'%';
		Zadig.setOpacity(this.vmlRender.addElement('<v:roundrect fillcolor="'+args.color+'" stroked="false"  arcsize="'+arc2+'"; style="position:absolute; width:'+(args.width-i*2)+'px;height:'+(args.height-i*2)+'px; left:'+i+'px; top:'+i+'px;" ></v:roundrect>'), 5);
	}
}	
Zadig.RoundShadow.prototype = {
'setSize':function(w, h)
{
	//return;
	this.vmlRender.setSize(w, h);
	var r = this.container.getElementsByTagName('roundrect');
	var len = r.length;
	var list= new Array();
	var x;
	for(;x=this.container.firstChild;)
	{
		this.container.removeChild(x);
		list.push(x);
	}
	var arc = 100/(Math.min(w,h)/2);
	for(var i = 0; i <len; i++)
	{
		rr = list[i];
		rr.style.width= (w-i*2)+'px';
		rr.style.height= (h-i*2)+'px';
		var arc2 = arc*(len-i) + "%";
		rr.arcSize=arc2 ;
		this.container.appendChild(list[i]);
	}
},
'remove':function()
{
	document.body.removeChild(this.container);
}
}

	
};
