function t4roundcorners( class_name, generator_url,
                         quadrant_width, quadrant_height )
{
    this.class_name = class_name;
    this.generator_url = generator_url;
    this.quadrant_width = quadrant_width;
    this.quadrant_height = quadrant_height;
    
    if ( navigator.appVersion.indexOf("MSIE 6") != -1 )
    {
        this._msie6 = true;
    }
    else
    {
        this._msie6 = false;
    }    
}

t4roundcorners.prototype.create_divs_for_current_document = function()
{
    // Get all the <div>s
    var result = document.getElementsByTagName("div");
    var divs = Array();
    
    for( var a = 0; a < result.length; a++ )
    {
        var div = result[a];
		var cls = t4lib.get_attribute(div, "class");

        if ( cls != null )
        {
            var parts = cls.split(" ");
            
            for( var b = 0; b < parts.length; b++ )
            {
                if ( this.class_name == parts[b] )
                {
                    divs.push(div);
                }
		    }
        }
	}
    
    return this.create_divs_for_elements(divs);
}

t4roundcorners.prototype.create_divs_for_elements = function(divs)
{
    var new_divs = Array();

    for(var a = 0; a < divs.length; a++)
    {
        var div = divs[a];
        this.create_background_divs(div, new_divs)
    }

    return new_divs;
}

t4roundcorners.prototype.run = function()
{
    var new_divs = this.create_divs_for_current_document();

    var body = document.getElementsByTagName("body")[0];
    for(var a = 0; a < new_divs.length; a++)
    {
        body.appendChild(new_divs[a]);
    }
}

t4roundcorners.prototype.imgurl = function(part)
{
    return this.generator_url + "/" + part;
}

t4roundcorners.prototype.msie6 = function()
{
    return this._msie6;
}

t4roundcorners.prototype.bgcss = function(div, part)
{
    if ( this.msie6() )
    {
        /* It's hard to believe, but this crap actually kind of works.
           The representation in MSIE 6 is far from perfect, but it
           works redamentarily */
        div.style.filter =
            "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" +
            this.imgurl(part) + "', sizingMethod='scale')";
    }
    else
    {
        div.style.backgroundImage = "url(" + this.imgurl(part) + ")";
    }        
}

t4roundcorners.prototype.create_background_divs = function(div, new_divs)
{
    var parent = div.parentNode;
    // Create 9 divs for the background images to go to

    var left = div.offsetLeft;
    var top = div.offsetTop;
    var width = div.offsetWidth;
    var height = div.offsetHeight;
    var right = left + width;
    var bottom = top + height;
    
    var img;

    var div_z_index = 0;
    if ( window.getComputedStyle )
    {
        div_z_index = window.getComputedStyle(div, "").getPropertyValue(
            "z-index");
    }
    else if ( div.currentStyle )
    {
        div_z_index = div.currentStyle.zIndex;
    }

    var new_z_index = parseInt(div_z_index) - 1;
    if ( new_z_index  < 1) new_z_index = 1;

    // i - top right
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = ( right - this.quadrant_width ) + "px";
    img.style.top = top + "px";
    img.style.width = this.quadrant_width + "px";
    img.style.height = this.quadrant_height + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "i");
    new_divs.push(img)

    // alert(div.currentStyle["z-index"]);
    //alert(this.class_name + " '" + String(div.style.zIndex) + "'");

    // ii - top left
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = left + "px";
    img.style.top = top + "px";
    img.style.width = this.quadrant_width + "px";
    img.style.height = this.quadrant_height + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "ii");
    new_divs.push(img);


    // iii - bottom left
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = left + "px";
    img.style.top = ( bottom - this.quadrant_height ) + "px";
    img.style.width = this.quadrant_width + "px";
    img.style.height = this.quadrant_height + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "iii");
    new_divs.push(img);    

    // iv - bottom right
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = ( right - this.quadrant_width ) + "px";
    img.style.top = ( bottom - this.quadrant_height ) + "px";
    img.style.width = this.quadrant_width + "px";
    img.style.height = this.quadrant_height + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "iv");
    new_divs.push(img);    

    // left
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = left + "px";
    img.style.top = (top + this.quadrant_height) + "px";
    img.style.width = this.quadrant_width + "px";
    img.style.height = (height-2*this.quadrant_height) + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "left");
    new_divs.push(img);

    // top
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = (left + this.quadrant_width) + "px";
    img.style.top = top + "px";
    img.style.width = (width - 2*this.quadrant_width) + "px";
    img.style.height = this.quadrant_height + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "top");
    new_divs.push(img);

    // right
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = (right - this.quadrant_width - 2) + "px";
    img.style.top = (top + this.quadrant_height) + "px";
    img.style.width = this.quadrant_width + "px";
    img.style.height = (height-2*this.quadrant_height) + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "right");
    new_divs.push(img);

    // bottom
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = (left + this.quadrant_width) + "px";
    img.style.top = (bottom - this.quadrant_height - 2) + "px";
    img.style.width = (width - 2*this.quadrant_width) + "px";
    img.style.height = this.quadrant_height + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "bottom");
    new_divs.push(img);

    // middle
    img = document.createElement("div");
    img.style.position = "absolute";
    img.style.left = (left + this.quadrant_width) + "px";
    img.style.top = (top + this.quadrant_height) + "px";
    img.style.width = (width - 2*this.quadrant_width - 2) + "px";
    img.style.height = (height - 2*this.quadrant_height - 2) + "px";
    img.style.zIndex = new_z_index;
    this.bgcss(img, "middle");
    new_divs.push(img);    
}


