if (typeof RedactorPlugins === 'undefined') var RedactorPlugins = {};

RedactorPlugins.replies = {

    init: function()
    {
        var callback = jQuery.proxy(function()
        {
            jQuery('#redactor_modal .redactor_reply_link').each(jQuery.proxy(function(i,s)
            {
                jQuery(s).click(jQuery.proxy(function()
                {
                    this.insertReply(jQuery(s).next().html());
                    return false;
                }, this));
            }, this));
            this.selectionSave();
            this.bufferSet();
        }, this);
        this.buttonAddSeparator();
        this.buttonAdd('replies', IMQM_REPLIES_TITLE, function()
        {
            this.modalInit(IMQM_REPLIES_TITLE, '#repliesmodal', 500, callback);
        });

    },

    insertReply: function(html)
    {
        this.selectionRestore();
        this.execCommand('inserthtml', html);
        this.modalClose();
    }

}