// Client-Side Rounded Corners Replacement

var RoundedClassName = "Rounded";
window.onload = roundCorners;

// Rewrites "rounded corner" images
function roundCorners() {

    if (!document.getElementsByTagName) return;
    var imgs = document.getElementsByTagName("img");
    for (var i=0; i < imgs.length; i++) {
        var img = imgs[i];

        if (img.className.indexOf(RoundedClassName)>=0) {

            // We want to create the new divs, which cause the rounding
            var containerDiv;
            // Create a container div, with the original image as the background.
            // Make it have the same dimensions as the original
            containerDiv = document.createElement('div');
            containerDiv.style.cssText= "position: relative; width:" + img.width + "px; height:" + img.height + "px; background: url(" + img.src + ");";
            // Preserve the existing classes
	        var classString = img.className;
	        classString.replace(RoundedClassName,"");	    
	        containerDiv.className = classString;
            img.parentNode.insertBefore(containerDiv,img);
            // Remove the original
            img.parentNode.removeChild(img);
            
            // Create the four internal divs that make the illusion of corners
            newDiv = document.createElement("div");
            newDiv.className = "JRoundedImageTop";
            containerDiv.appendChild(newDiv);
            
            newDiv = document.createElement("div");
            newDiv.className = "JRoundedImageRight";
            containerDiv.appendChild(newDiv);
            
            newDiv = document.createElement("div");
            newDiv.className = "JRoundedImageBottomLeft";
            containerDiv.appendChild(newDiv);
            
            newDiv = document.createElement("div");
            newDiv.className = "JRoundedImageBottomRight";
            containerDiv.appendChild(newDiv);   
            
            // Offset for the removal
            i--;                                 
        }
    }    
}            