$.sceditor.command.set("addSnippet", {
    exec: function () {
        $('#showAddSnippet').click();
    },
    txtExec: function () {
    },
    tooltip: "Add text snippet"
});

$.sceditor.command.set("showSnippetlist", {
    exec: function () {
        $('#showSnippetlist').click();
    },
    txtExec: function () {
    },
    tooltip: "Manage snippets"
})

$.sceditor.command.set("insertSnippet", {
    exec: function (caller) {
        var $editorInstance = this;
        var editor = $editorInstance,
                $content = $("<div />");
        $.getJSON("index.php?module=ticket&class=snippets&event=ajaxSnippets", function (data) {
            var items = [];
            $.each(data, function (key, val) {
                $(
                    '<a class="sceditor-header-option" href="#" title="' + val.snippet.replace(/(?:_NEWLINE_)/g, '\n') + '">' + val.title + '</a><br /><br />'
                    )
                    .data('snippet', val.snippet)
                    .click(function (e) {
                        $editorInstance.insertText(val.snippet.replace(/(?:_NEWLINE_)/g, '\n'));
                        editor.closeDropDown(true);
                        e.preventDefault();
                    })
                    .appendTo($content);
            });
        });
        
        editor.createDropDown(caller, "header-picker", $content[0], false);
    },   
    tooltip: "Insert text snippet"
});
