

var caption = {

    apply: function(el) {
        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.
        }
        var c_caption = document.createElement('div');
        c_caption.id = 'gallery_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 + 'px';
        el.parentNode.appendChild(c_caption);
        if (!el.dataDescription && !el.dataCaption) {
            c_caption.style.display = 'none';
        }
    }
};
