(function() {
    function mySetup() {
        var div = document.body.appendChild( document.createElement( 'div' ) );
        div.id = 'test';
        te.dom.push( div );

        te.getButtonByTitle = function( id, title ) {
            var title_class = {
                "全屏" : "fullscreen",
                "源代码" : "source",
                "撤销" : "undo",
                "重做" : "redo",
                "加粗" : "bold",
                "斜体" : "italic",
                "下划线" : "underline",
                "删除线" : "strikethrough",
                "上标" : "superscript",
                "下标" : "subscript",
                "清除格式" : "removeformat",
                "格式刷" : "formatmatch",
                "引用" : "blockquote",
                "纯文本粘贴模式" : "pasteplain",
                "字体颜色" : "forecolor",
                "背景色" : "backcolor",
                "有序列表" : "insertorderedlist",
                "无序列表" : "insertunorderedlist",
                "格式" : "paragraph",
                "字体" : "fontfamily",
                "字号" : "fontsize",
                "从左向右输入" : "directionalityltr",
                "从右向左输入" : "directionalityrtl",
                "居左对齐" : "justifyleft",
                "居中对齐" : "justifycenter",
                "居右对齐" : "justifyright",
                "两端对齐" : "justifyjustify",
                "超链接" : "link",
                "祛除链接" : "unlink",
                "图片" : "image",
                "特殊字符" : "spechars",
                "表情" : "emoticon",
                "视频" : "video",
                "Baidu地图" : "map",
                "Google地图" : "gmap",
                "分隔线" : "horizontal",
                "日期" : "date",
                "时间" : "time",
                "表格" : "inserttable",
                "删除表格" : "deletetable",
                "表格前插行" : "insertparagraphbeforetable",
                "前插入行" : "insertrow",
                "删除行" : "deleterow",
                "前插入列" : "insertcol",
                "删除列" : "deletecol",
                "合并多个单元格" : "mergecells",
                "右合并单元格" : "mergeright",
                "下合并单元格" : "mergedown",
                "完全拆分单元格" : "splittocells",
                "拆分成行" : "splittorows",
                "拆分成列" : "splittocols",
                "全选" : "selectall",
                "清空文档" : "cleardoc",
                "查询替换" : "searchreplace",
                "打印" : "print",
                "预览" : "preview",
                "帮助" : "help"
            };
            var ed = window.$EDITORUI[id];
            var buttons = ed.toolbars[0].items;
            var classname = title_class[title];
            for ( var i = 0; i < buttons.length; i++ ) {
                if ( buttons[i].getDom().className.indexOf( classname ) > -1 )
                    return buttons[i];
            }
        };

        te.getElementByClassNameAndEditorid = function( editorid, classname , eletype) {
            var editorui = window.$EDITORUI;
            var array = [];
            var i = 0;
            for ( var editor in editorui ) {
                if ( editorui[editor].id.indexOf( 'editor' ) > -1 ) {
                    i++;
                    if ( editorui[editor].id == editorid )
                        break;
                }

            }

            for ( var ele in editorui ) {
                if ( editorui[ele].getDom() && editorui[ele].getDom().className.indexOf( classname ) > -1 
                		&& editorui[ele].getDom().className.indexOf( 'edui-' + eletype ) > -1 ){
                    array.push( editorui[ele] );
                }
            }
            return array[i - 1];
        };
        
        te.getElementObjById = function( id ){
        	return window.$EDITORUI[id];
        };

//        te.presskey = function( key ) {
//            var title = $( 'title' )[0].innerHTML;
//            var browser = "";
//            if ( TT.browser.ie == 6 )
//                browser = 'ie6';
//            if ( TT.browser.ie == 7 )
//                browser = 'ie7';
//            if ( TT.browser.ie == 8 )
//                browser = 'ie8';
//            if ( TT.browser.safari )
//                browser = 'safari';
//            if ( TT.browser.firefox )
//                browser = 'firefox';
//            if ( TT.browser.chrome )
//                browser = 'chrome';
//            if ( TT.browser.maxthon )
//                browser = 'maxthon';
//            if ( TT.browser.opera )
//                browser = 'opera';
//
//            var urlstring = "http://localhost:9999/key?" + "browser=" + browser + "&title=" + title + "&message=" + key;
//            var xhr = TT.sio.log( urlstring );
//        };
    }

    var s = QUnit.testStart;
    QUnit.testStart = function() {
        s.apply( this, arguments );
        mySetup();
    };
})();