Fetion.Web.Chat.defined("Fetion.Web.Chat.CE_AUDIO");
Fetion.Web.Chat.CE_AUDIO.create = function (o)
{
    var html = "<span onselectstart='return false' ondragstart='return false' style='cursor:hand'>";
    html += "<img src='chat/img/chat/LoadingImage_s.gif'><img onselectstart='return false' ondragstart='return false' style='display:none;margin-left:-25px'>";
    html += "</span>";
    var ctrl = document.createElement("SPAN");
    ctrl.innerHTML = html;
    ctrl = ctrl.childNodes[0];
    var img = ctrl.childNodes[0];
    ctrl.img = img;
    var horn = ctrl.childNodes[1];
    ctrl.horn = horn;
    img.audio = horn.audio = ctrl;
    horn.normal = "chat/img/chat/ec_audio_normal.png";
    horn.play = "chat/img/chat/ec_audio_play.gif";

    if (o.thumb)
        this.update(ctrl, o);

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

    return ctrl;
};
Fetion.Web.Chat.CE_AUDIO.update = function (ctrl, data)
{
    ctrl.img.src = data.thumb;
    ctrl.img.onload = this.onload;
    ctrl.img.onerror = this.onerror;
    ctrl.img.style.width = ctrl.img.style.height = "100px";
    if (window.isChrome)
    {
        ctrl.img.setAttribute("type", "IMG");
        var imgFilePath = unescape(data.thumb);
        var fileName = imgFilePath.substring(imgFilePath.lastIndexOf("\\") + 1);
        ctrl.img.name = fileName;
        ctrl.img.setAttribute("shortcut", "[图片]");
        ctrl.img.setAttribute("id", fileName.substr(0, fileName.indexOf(".")));
        ctrl.removeChild(ctrl.horn);
        return;
    }
    ctrl.horn.style.display = "";
    ctrl.data = data;
    ctrl.onclick = function ()
    {
        var ctrl = this;

        if (window.preCE_AUDIO && window.preCE_AUDIO != ctrl && window.preCE_AUDIO.play)
            preCE_AUDIO.click();

        ctrl.play = !ctrl.play;
        window.preCE_AUDIO = ctrl;
        if (ctrl.play == true)
        {
            ctrl.img.src = ctrl.data.picpath;
            ctrl.horn.src = ctrl.horn.play;
            ctrl.time = ctrl.data.time;
            ctrl.curTime = 0;
            ctrl.intervalID = setInterval(function ()
            {
                if (ctrl.curTime++ < ctrl.time)
                    return;
                ctrl.click();
            }, 1000);
            //调客户端接口，播放声音
            window.external.OperateSoundMsg(ctrl.data.audiopath, 1);
        }
        else
        {
            if (ctrl.intervalID)
                clearInterval(ctrl.intervalID);
            ctrl.img.src = ctrl.data.thumb;
            ctrl.horn.src = ctrl.horn.normal;
            //调客户端接口，停止声音
            window.external.OperateSoundMsg(ctrl.data.audiopath, 2);
        }
    }
    ctrl.horn.onmouseover = function ()
    {
        this.src = "chat/img/chat/ec_audio_hover.png";
    };
    ctrl.horn.onmouseleave = function ()
    {
        this.src = this.audio.play == true ? this.play : this.normal;
    };
    ctrl.horn.onmouseleave();
};
Fetion.Web.Chat.CE_AUDIO.onload = function ()
{
    Fetion.Web.Chat.scroll();
};
Fetion.Web.Chat.CE_AUDIO.onerror = function ()
{
    var ctrl = this.parentNode;
    ctrl.onclick = null;
    //ctrl.removeChild(ctrl.horn);
    this.style.width = this.style.height = "auto";
    this.src = "chat/img/chat/LoadingImageFailed.png";
};