function FJInsertIcon(mt_icon_base, position) {
    var mt_icons = [
        [ "1.gif", "男の子", 11, 11 ],
        [ "2.gif", "女の子", 11, 11 ],
        [ "3.gif", "携帯", 11, 11 ],
        [ "4.gif", "パソコン", 11, 11 ],
        [ "5.gif", "ファイト", 11, 11 ],
        [ "6.gif", "ナイス", 11, 11 ],
        [ "7.gif", "グー", 11, 11 ],
        [ "8.gif", "チョキ", 11, 11 ],
        [ "9.gif", "パー", 11, 11 ],
        [ "10.gif", "くるま", 11, 11 ],
        [ "11.gif", "ひこうき", 11, 11 ],
        [ "12.gif", "でんしゃ", 11, 11 ],
        [ "13.gif", "？", 11, 11 ],
        [ "14.gif", "！", 11, 11 ],
        [ "15.gif", "ハート", 11, 11 ],
        [ "16.gif", "とけい", 11, 11 ],
        [ "17.gif", "おうち", 11, 11 ],
        [ "18.gif", "マイク", 11, 11 ],
        [ "19.gif", "♪", 11, 11 ],
        [ "20.gif", "しょくじ", 11, 11 ],
        [ "21.gif", "ケーキ", 11, 11 ],
        [ "22.gif", "ビール", 11, 11 ],
        [ "23.gif", "ゆき", 11, 11 ],
        [ "24.gif", "くもり", 11, 11 ],
        [ "25.gif", "はれ", 11, 11 ],
        [ "52.gif", "あめ", 11, 11 ],
        [ "26.gif", "つき", 11, 11 ],
        [ "28.gif", "ねこ", 11, 11 ],
        [ "29.gif", "ねずみ", 11, 11 ],
        [ "30.gif", "ニコ", 11, 11 ],
        [ "31.gif", "ニコニコ", 11, 11 ],
        [ "32.gif", "ブー", 11, 11 ],
        [ "33.gif", "シュン", 11, 11 ],
        [ "34.gif", "プレゼント", 11, 11 ],
        [ "36.gif", "でんきゅう", 11, 11 ],
        [ "53.gif", "＄", 11, 11 ],
        [ "37.gif", "ドクロ", 11, 11 ],
        [ "38.gif", "おんせん", 11, 11 ],
        [ "39.gif", "かんらんしゃ", 11, 11 ],
        [ "40.gif", "CD", 11, 11 ],
        [ "41.gif", "DVD", 11, 11 ],
        [ "42.gif", "Zzz", 11, 11 ],
        [ "43.gif", "ハンバーガー", 11, 11 ],
        [ "44.gif", "ツリー", 11, 11 ],
        [ "45.gif", "クロバー", 11, 11 ],
        [ "46.gif", "Windows1", 11, 11 ],
        [ "47.gif", "Mac", 11, 11 ],
        [ "48.gif", "Windows2", 11, 11 ],
        [ "49.gif", "IE", 11, 11 ],
        [ "50.gif", "Netscape", 11, 11 ],
        [ "51.gif", "むちゃ", 11, 11 ]
/*
        [ "ファイル名", "説明", 幅, 高さ ],
        [ "ファイル名", "説明", 幅, 高さ ]
*/
    ];
    var i_file = 0;
    var i_alt = 1;
    var i_width = 2;
    var i_height = 3;
    var toolbarPosition = position;

    this.insertToTextArea = function(v) {
        var e = document.getElementById('comment-text');
        if (document.selection) {
            e.focus();
            var range = document.selection.createRange();
            range.text = v;
        } else {
            var length = e.textLength;
            var start = e.selectionStart;
            var end = e.selectionEnd;
            if (end == 1 || end == 2) end = length;
            e.value = e.value.substring(0, start) + v + e.value.substr(end, length);
            e.selectionStart = start + v.length;
            e.selectionEnd = start + v.length;
        }
        e.focus();
    };

    this.insertIconEditor = function(i) {
        var i_html;

        if (app.editor.mode == 'iframe') {
            var id = "temp_id_for_retrieving_inserted_element_" + Unique.id();
            i_html = '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" class="mt_icon" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" title="' + mt_icons[i][i_alt] + '" id="' + id + '" />';
            var inserted = _insertHTML(i_html, false, id, true);
            if (inserted) {
                inserted.src = mt_icon_base + mt_icons[i][i_file];
            }
        }
        else {
            i_html = '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" class="mt_icon" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" title="' + mt_icons[i][i_alt] + '" />';
            app.editor.actual.setSelection(i_html);
        }
    };

    this.insertIconTag = function(i) {
        var i_html;

        i_html = '<img src="' + mt_icon_base + mt_icons[i][0] + '" class="mt_icon" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" title="' + mt_icons[i][i_alt] + '" />';
        this.insertToTextArea(i_html);
    };

    this.insertIconMacro = function(i) {
        var i_html;

        i_html = ':' + mt_icons[i][0] + ':';
        this.insertToTextArea(i_html);
    };

    this.listIconsEditor = function() {
        var i;

        var editor = document.getElementById('editor-content-enclosure');
        var editorParent = editor.parentNode;
        var iconDiv = document.createElement('div');
        iconDiv.id = 'editor-content-iconbar';
        iconDiv.style.padding = '3px 10px';
        iconDiv.style.border = '1px solid #cccccc';
        iconDiv.style.borderTop = 'none';
        iconDiv.style.backgroundColor = '#f3f3f3';
        if (toolbarPosition == 1) {
            editorParent.insertBefore(iconDiv, editor);
        }
        else if (toolbarPosition == 2) {
            editorParent.appendChild(iconDiv);
        }
        var spanElement = document.createElement('span');
        spanElement.id = 'editor_insert_icons';
        var html = '';
        for (i = 0; i < mt_icons.length; i++) {
            html += '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" border="0" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" title="' + mt_icons[i][i_alt] + '" onclick="_fj_insert_icon_obj.insertIconEditor(' + i + ');" style="cursor : pointer;" />';
        }
        spanElement.innerHTML = html;
        iconDiv.appendChild(spanElement);
    };

    this.listIconsCommentForm = function(mode) {
        var i;
        var html = '';

        for (i = 0; i < mt_icons.length; i++) {
            if (mode == 'tag') {
                html += '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" border="0" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" title="' + mt_icons[i][i_alt] + '" onclick="_fj_insert_icon_obj.insertIconTag(' + i + ');" style="cursor : pointer;" />';
            }
            else if (mode == 'macro') {
                html += '<img src="' + mt_icon_base + mt_icons[i][i_file] + '" border="0" width="' + mt_icons[i][i_width] + '" height="' + mt_icons[i][i_height] + '" alt="' + mt_icons[i][i_alt] + '" title="' + mt_icons[i][i_alt] + '" onclick="_fj_insert_icon_obj.insertIconMacro(' + i + ');" style="cursor : pointer;" />';
            }
        }
        document.write(html);
    };

    _insertHTML = function(html, select, id, isTempId) {
        var editor = app.editor.actual;
        var selection = editor.getSelection();
        var inserted = null;
        if (selection.createRange) { // Internet Explorer (IE)
            var range = selection.createRange();
            if (selection.type == "None" || selection.type == "Text") {
                try {
                    range.pasteHTML(html);
                } catch (err) {
                    log("Error pasting html on selection of type 'Text' or 'None': " + err);
                }
                if (defined(id)) {
                    inserted = editor.document.getElementById(id);
                    if(select) 
                        range.moveToElementText(inserted);
                } else {
                    if(range.moveStart) {
                        range.moveStart("character", ((html.length) * (-1)));
                        inserted = range.parentElement();
                    }
                }
                if (select) 
                    range.select();
            }
            else { // IE 'Control' selection    
                range.item(0).outerHTML = html;
                inserted = range.item(0); 
            }
        }
 
        // mozilla
        else if (selection.getRangeAt) {
            var range;
            if (selection.rangeCount)
                range = selection.getRangeAt(0);
            else {
                range = editor.document.createRange();
                range.setStart(editor.document.body, 0);
                range.setEnd(editor.document.body, 0);
                selection.addRange(range);
            }
            var anchor = range.startContainer;

            if (selection && range && editor.isCaretAtEnd(selection, range)) { 
                var paragraph = editor.document.createElement(editor.FORMAT_BLOCK_TAG);
                paragraph.insertBefore(editor.document.createElement("br"), null);
                editor.document.getElementsByTagName("body")[0].insertBefore(paragraph, null);
            } 

            if (select && anchor.nodeType == Node.TEXT_NODE && !html.match( /<[a-z][a-z]*\s/i)) {
                range.setStart(anchor, selection.anchorOffset);
                var insertNode = editor.document.createTextNode(html);
                range.insertNode(insertNode);
                var inserted = insertNode;
            }
            else {
                var pS = anchor.previousSibling;
                var nS = anchor.nextSibling;
                editor.document.execCommand("insertHTML", false, html);
                if(pS !== anchor.previousSibling)
                    inserted = anchor.previousSibling;
                else if(nS !== anchor.nextSibling)
                    inserted = anchor.nextSibling;
                else 
                    inserted = anchor.firstChild;
            }

            if (defined(id))
                inserted = editor.document.getElementById(id);
            if (inserted && inserted.tagName && inserted.tagName.toLowerCase() == "a")
                editor.tagJustInserted = true;
            if (select) {
                range.selectNode(inserted);
                editor.monitorSelection(); // Required for Mozilla for proper arrow keys on highlighted link.
            }
            selection.addRange(range);        
        }

        if(isTempId && inserted) {
            inserted.id = undefined;
            inserted.removeAttribute("id");
        }
        return inserted;
    };
}
