function toggle(id) {
    var latestAttachmentVersionBlock = document.getElementById("attachment_" + id);
    var oldAttachmentVersionRows = document.getElementsByClassName('history_' + id);
    for (var i = 0; i < oldAttachmentVersionRows.length; i++) {
        var oldAttachmentVersionRow =  oldAttachmentVersionRows[i];

        if (oldAttachmentVersionRow.className.indexOf(' hidden') != -1) {
            oldAttachmentVersionRow.className = oldAttachmentVersionRow.className.replace(' hidden', '');
        } else {
            oldAttachmentVersionRow.className += ' hidden';
        }
    }

    var arrowIcon = document.getElementById('arrow' + id);
    var contextPath = document.getElementById('contextPath').value;
    with (arrowIcon) {
        if (src != null && (src.indexOf(contextPath + '/images/icons/arrow_closed_active_16.gif') != -1 || src.indexOf(contextPath + '/images/icons/arrow_closing_active_16.gif') != -1)) {
            src = contextPath + '/images/icons/arrow_opening_active_16.gif';
        } else {
            src = contextPath + '/images/icons/arrow_closing_active_16.gif';
        }
    }
}

// ========================
// = AJS-based JavaScript =
// ========================
AJS.toInit(function ($) {
    var addons = $("#upload-attachments li.hidden");
    $("p.link a").click(function () {
        addons.removeClass("hidden");
        $("p.link").addClass("hidden");
    });
    $("p.link").removeClass("hidden");
});