Fetion.Web.Chat.loadSRC("css/chat/OUT_CE.css");
Fetion.Web.Chat.defined("Fetion.Web.Chat.FUN_CE");

Fetion.Web.Chat.FUN_CE.create = function (o)
{
    var span = document.createElement("SPAN");
    var html = "";
    html += "<img src='chat/img/chat/LoadingImage_s.gif'/>";
    span.innerHTML = html;
    span.onselectstart = "return false";

    span.data = o;
    span.ondblclick = function ()
    {
        var data = this.data;
        window.external.LDblClick(data.id, data.type);
    };

    if (o.parent)
        o.parent.appendChild(span);

    if (o.path)
        this.update(span, o);
    return span;
};

Fetion.Web.Chat.FUN_CE.update = function (ctrl, data)
{
    if (data.status == "overdue")
        data.path = "overdue";
    else if (data.status == "failure")
        data.path = "failure";

    if (window.isChrome)
    {
        if (data.thumb)
        {
            var imgFilePath = unescape(data.thumb);
            var fileName = imgFilePath.substring(imgFilePath.lastIndexOf("\\") + 1);

            ctrl.childNodes[0].name = fileName;
            ctrl.childNodes[0].setAttribute("shortcut", "[图片]");
            ctrl.childNodes[0].setAttribute("id", fileName.substr(0, fileName.indexOf(".")));
            ctrl.childNodes[0].src = imgFilePath;
            ctrl.childNodes[0].width = ctrl.childNodes[0].height = 100;
            ctrl.childNodes[0].setAttribute("type", "IMG");
            var img = ctrl.childNodes[0];
            ctrl.img = img;
            img.onload = this.onload;
            img.onerror = this.onerror;
            return;
        }
    }

    var imgFilePath = unescape(data.path);
    var fileName = imgFilePath.substring(imgFilePath.lastIndexOf("\\") + 1);
    ctrl.style.overflow = "hidden";
    ctrl.onclick = null;
    var html = "<img width='100' src='" + data.path + "' id='" + data.id + "' name='" + fileName + "' type='" + data.type + "' shortcut='" + data.textValue + "'>";
    if (data.status == "failure")
    {
        html = "<img title='点击重新加载' src='chat/img/chat/LoadingImageFailed.png' style='cursor:hand'>";
        ctrl.onclick = function ()
        {
            // 不再是双击查看原图的提示，而应该是点击重新加载,todo
            var rst = window.external.DownLoadObj(this.data.id);
            if (rst)
            {
                // 更新为loading图;todo
                this.innerHTML = "<img title='双击查看原图' src='chat/img/chat/LoadingImage_s.gif'>";
            }
        };
    }

    ctrl.innerHTML = html;
    var img = ctrl.childNodes[0];
    ctrl.img = img;
    img.onload = this.onload;
    img.onerror = this.onerror;
    if (window.addEventListener)
        window.addEventListener("resize", function () { img.onload() }, false);
    else
        window.attachEvent("onresize", function () { img.onload() });
};
Fetion.Web.Chat.FUN_CE.onload = function ()
{
    Fetion.Web.Chat.scroll();
};
Fetion.Web.Chat.FUN_CE.onerror = function ()
{
    this.style.width = this.style.height = "auto";
    this.src = "chat/img/chat/LoadingImageFailed.png";
};
