window.onload=function(){

	obj = this.getElementByClassName('round');

	round_top = document.createElement('span');
	round_top.className = 'rtop';
	round_btm = document.createElement('span');
	round_btm.className = 'rbottom';
	for(j = 1; j <=4; j++){
		el = document.createElement('span');	
		el.className = 'r' + j;
		round_top.appendChild(el);
		round_btm.insertBefore(el.cloneNode(true), round_btm.firstChild);
	}

	for(i = 0; i < obj.length; i++){
		
		rtop = round_top.cloneNode(true);
		rbtm = round_btm.cloneNode(true);
		objstyle = getRealStyle(obj[i]);
		bgcol =	objstyle.backgroundColor;
		
		for(k = 0; k < rtop.childNodes.length; k++){
			rtop.childNodes[k].style.backgroundColor = bgcol;
			rbtm.childNodes[k].style.backgroundColor = bgcol;
		}
	
		box = document.createElement('div');
		box.className = 'rounded';
		box.style.width = objstyle.width;
		box.style.margin = objstyle.margin;
		box.appendChild(rtop);

		con = obj[i].cloneNode(true);
		con.style.width = 'auto';
		con.style.padding = 0;
		con.style.margin = 0;

		con.style.borderStyle		= 'solid';
		con.style.borderColor		= objstyle.backgroundColor;
		con.style.borderLeftWidth	= objstyle.paddingLeft;
		con.style.borderRightWidth	= objstyle.paddingRight;
		con.style.borderTopWidth	= objstyle.paddingTop;
		con.style.borderBottomWidth = objstyle.paddingBottom;
		
		box.appendChild(con);
		box.appendChild(rbtm);
	
		obj[i].parentNode.replaceChild(box, obj[i]);
	
	}
}


//クラス指定後のリアルスタイルを取得できる！！！！
function getRealStyle(x){
return x.currentStyle || document.defaultView.getComputedStyle(x, '');
}

getElementByClassName = function(name)
{
	var elements=[];
	var allElements = document.getElementsByTagName('*');

	for(var i=0,len=allElements.length; i<len; i++)
	{
		var cls = allElements[i].className.split(" ");

		for(var j=0; j < cls.length; j++){
			if(cls[j] == name){
				elements.push(allElements[i]);
				continue;
			}
		}
	}
	return elements;
} 


