//Open external links in new window
function externalLinks() {
    $('a[@rel$=external]').click(function(){
        this.target = "_blank";
    });
};

function twoCols(src, type) {
    var origList = src;

    var leftList = document.createElement(type);
    var rightList = document.createElement(type);
    var container = document.createElement('div');

    var items = origList.getElementsByTagName('li');

    var itemsLength = items.length/2;
    for (i = 0; i < itemsLength; i++) {
        leftList.appendChild(items[0]);
    }

    itemsLength = items.length;
    for (i = 0; i < itemsLength; i++) {
        rightList.appendChild(items[0]);
    }
    container.appendChild(leftList);
    container.appendChild(rightList);

    leftList.setAttribute('class', 'left');
    rightList.setAttribute('class', 'right');
    container.setAttribute('class','twocol');
    if (document.all) {
        leftList.setAttribute('className', 'left');
        rightList.setAttribute('className', 'right');
        container.setAttribute('className','twocol');
    }
    if (type == 'ol') {
        rightList.setAttribute('start', leftList.getElementsByTagName('li').length + 1 );
    }
    origList.parentNode.replaceChild(container, origList);
}

function allTwoCols (whichclass, type)
{
    var uls = document.getElementsByTagName(type);
    for (var i=0; i< uls.length; i++) {
        if (uls[i].getAttribute('class') == whichclass ||
            uls[i].getAttribute('className') == whichclass) {
            twoCols(uls[i], type.toLowerCase());
        }
    }
}

$(document).ready(function(){
    allTwoCols('twoColumns', 'ul');
    externalLinks();
});