/** layout javascript for PO, copied from GKN */

// arrays of [margin, top borderwidth, right/left borderwidth, height]
SB = {
    'r10' : [[7,1,0,0],[5,0,2,1],[4,0,1,1],[3,0,1,1],[2,0,1,1],[1,0,1,2]],
    'r09' : [[6,1,0,0],[4,0,2,1],[3,0,1,1],[2,0,1,1],[1,0,1,2]],
    'dbl' : [[9,1,0,0],[6,1,0,0],[4,0,5,1],[3,0,3,1],[2,0,2,2],[1,0,2,3]]
};

function ApplyCorner(el,corner) {
    var before = '', after = '', newcontent = '', style = '';

    for (i=0; i < corner.length; i++) {
        if (corner[i][1] > 0) {
            style  = 'border-width:0;';
            style += 'border-top-width:' + corner[i][1] + 'px;';
            style += 'height:0px;';
        } else {
            style  = 'border-width:0 ' + corner[i][2] + 'px;';
            style += 'height:' + corner[i][3] + 'px;';
        }
        style += 'margin: 0 ' + corner[i][0] + 'px;';
        style += 'line-height: 0px; font-size: 0px; overflow-x: visible; overflow-y: hidden; padding: 0;';

        layer = '<div class="layer" style="' + style + '"></div>';
        before = before + layer;
        after  = layer  + after;
    }

    style = 'line-height:0px;font-size:0px;padding:0;margin:0;overflow-x:visible;overflow-y:hidden;width:100%;';
    newcontent  = '<div class="filler before" style="' + style + '">' + before + '</div>';
    newcontent += '<div class="content">' + el.innerHTML + '</div>';
    newcontent += '<div class="filler after" style="' + style + '">' + after + '</div>';

    el.innerHTML = newcontent;
    el.addClassName('corners');
}

document.observe('dom:loaded', function() {
    $$('div.box').each(function(element) { ApplyCorner(element,SB.r09); });
    $$('div.box-double').each(function(element) { ApplyCorner(element,SB.dbl); });
    $$('div.gadget').each(function(element) { ApplyCorner(element,SB.r09); });
    $$('div.roundcorners').each(function(element) { ApplyCorner(element,SB.r09); });
});