

var caption = {

    apply: function(el, overwrite) {
        if (overwrite) {
            var curr_caption = app.get('gallery_caption');
            if (curr_caption) {
                curr_caption.parentNode.removeChild(curr_caption);
                // If there's an existing caption, get rid of it.
            }
        }
        if (!el.dataDescription && !el.dataCaption) {
            return false;
        }
        var c_caption = document.createElement('div');
        if (overwrite) {
            c_caption.id = 'gallery_caption';
        } else {
            c_caption.id = el.id + '_caption';
        }
        c_caption.className = 'caption';
        var c_title = document.createElement('div');
        c_title.className = 'title';
        var title = document.createTextNode(el.dataCaption);
        c_title.appendChild(title);
        var c_desc = document.createElement('div');
        c_desc.className = 'description';
        var desc = document.createTextNode(el.dataDescription);
        c_desc.appendChild(desc);
        c_caption.appendChild(c_title);
        c_caption.appendChild(c_desc);
        c_caption.style.width = (el.width - 16) + 'px';
        c_caption.style.padding = '8px';
        el.parentNode.appendChild(c_caption);
        return c_caption;
    }
};
