// Constants to define a side of an element
var SS_ROUNDCORNERS_SIDE_TOP=1;
var SS_ROUNDCORNERS_SIDE_RIGHT=2;
var SS_ROUNDCORNERS_SIDE_BOTTOM=3;
var SS_ROUNDCORNERS_SIDE_LEFT=4;


// Round the corners on a single side of an element
// Orientation: Refer to constants above for side definitions
function SS_RoundElementCornersSingleSide(Element, BGColor, BorderColor, BorderWidth, Orientation){
	Element=SS_GetElement(Element);

	if (Element!=null){
		var NewNode=null;

		if (Orientation==null){
			Orientation=SS_ROUNDCORNERS_SIDE_TOP;
		}

		if (BorderWidth==null){
			BorderWidth=(BorderColor?1:0);
		}

		// Top Border
		if (BorderWidth){
			if (BorderColor==null){
				BorderColor="#000000";
			}
			Element.style.borderLeft=BorderWidth+"px solid "+BorderColor;
			Element.style.borderRight=BorderWidth+"px solid "+BorderColor;
			NewNode=document.createElement("div");
			NewNode.style.padding="0px";
			NewNode.style.margin="0px "+(BorderWidth*4)+"px 0px "+(BorderWidth*4)+"px";
			NewNode.style.backgroundColor=BorderColor;
			NewNode.style.width=(SS_GetElementW(Element)-(8*BorderWidth))+"px";
			NewNode.style.height=BorderWidth+"px";
			if (Orientation==1){
				Element.parentNode.insertBefore(NewNode, Element);
			} else {
				Element.parentNode.insertBefore(NewNode, Element.nextSibling);
			}
		}

		// Middle Corner
		NewNode=document.createElement("div");
		NewNode.style.padding="0px";
		NewNode.style.margin="0px "+(BorderWidth?BorderWidth*2:2)+"px 0px "+(BorderWidth?BorderWidth*2:2)+"px";
		if (BGColor){
			NewNode.style.backgroundColor=BGColor;
		}
		if (BorderWidth){
			NewNode.style.borderLeft=(BorderWidth*2)+"px solid "+BorderColor;
			NewNode.style.borderRight=(BorderWidth*2)+"px solid "+BorderColor;
		}
		NewNode.style.width=(SS_GetElementW(Element)-(BorderWidth?8*BorderWidth:4))+"px";
		NewNode.style.height=(BorderWidth?BorderWidth:1)+"px";
		if (Orientation==1){
			Element.parentNode.insertBefore(NewNode, Element);
		} else {
			Element.parentNode.insertBefore(NewNode, Element.nextSibling);
		}

		// Bottom Corner
		NewNode=document.createElement("div");
		NewNode.style.padding="0px";
		NewNode.style.margin="0px "+(BorderWidth?BorderWidth:1)+"px 0px "+(BorderWidth?BorderWidth:1)+"px";
		if (BGColor){
			NewNode.style.backgroundColor=BGColor;
		}
		if (BorderWidth){
			NewNode.style.borderLeft=BorderWidth+"px solid "+BorderColor;
			NewNode.style.borderRight=BorderWidth+"px solid "+BorderColor;
		}
		NewNode.style.width=(SS_GetElementW(Element)-(BorderWidth?4*BorderWidth:2))+"px";
		NewNode.style.height=(BorderWidth?BorderWidth*2:1)+"px";
		if (Orientation==1){
			Element.parentNode.insertBefore(NewNode, Element);
		} else {
			Element.parentNode.insertBefore(NewNode, Element.nextSibling);
		}
	}
}


// Add rounded corners to the top of an element with the given background color and/or border color
function SS_RoundElementTopCorners(Element, BGColor, BorderColor, BorderWidth){
	SS_RoundElementCornersSingleSide(Element, BGColor, BorderColor, BorderWidth, SS_ROUNDCORNERS_SIDE_TOP);
}




// Add rounded corners to the bottom of an element with the given background color and/or border color
function SS_RoundElementBottomCorners(Element, BGColor, BorderColor, BorderWidth){
	SS_RoundElementCornersSingleSide(Element, BGColor, BorderColor, BorderWidth, SS_ROUNDCORNERS_SIDE_BOTTOM);
}



// Round all corners of the element using the given background and/or border colors
function SS_RoundElementCorners(Element, BGColor, BorderColor, BorderWidth){
	SS_RoundElementTopCorners(Element, BGColor, BorderColor, BorderWidth);
	SS_RoundElementBottomCorners(Element, BGColor, BorderColor, BorderWidth);
}