function getObj(objName) {
    try {
        if (document.getElementById) {
            return eval('document.getElementById("' + objName + '")')
        } else {
            return eval("document.all." + objName)
        }
    } catch (e) {}
}
function getOLeft(b) {
    curObj = b;
    var a = curObj.offsetLeft;
    while (curObj != curObj.offsetParent && curObj.offsetParent) {
        curObj = curObj.offsetParent;
        if (curObj.tagName == "DIV" || curObj.tagName == "TABLE" || curObj.tagName == "TR" || curObj.tagName == "TD") {
            a += curObj.offsetLeft
        }
    }
    return a
}
function QvodPlay() {
    if (QvodPlayer.PlayState != 3) {
        QvodPlayer.Play();
        getObj("playControl").src = "http://img.megajoy.com/qvod/images/07.gif";
        if (FirstPlay) {
            getObj("mediaInfo").innerText = "连接中";
            FirstPlay = false
        } else {
            getObj("mediaInfo").innerText = "播放中"
        }
    } else {
        var a = '<invoke name="PauseAd" returntype="xml" UserAd="0"></invoke> ';
        var b = QvodPlayer.CallFunction(a);
        QvodPause()
    }
}
function QvodPause() {
    if (QvodPlayer.Currentpos > 0) {
        QvodPlayer.Pause();
        getObj("playControl").src = "http://img.megajoy.com/qvod/images/08.gif";
        getObj("mediaInfo").innerText = "已暂停"
    }
}
function QvodStop() {
    if (QvodPlayer.CurrentPos > 0) {
        QvodPlayer.Stop();
        getObj("playControl").src = "http://img.megajoy.com/qvod/images/07.gif";
        getObj("mediaInfo").innerText = "已停止"
    }
}
function FullScreen() {
    try {
        if (QvodPlayer.CurrentPos > 0) {
            var a = true;
            QvodPlayer.Full = a
        }
    } catch (b) {}
}
var mute = false;

function Mute() {
    if (mute) {
        mute = false;
        QvodPlayer.Mute = mute;
        getObj("muteControl").src = "http://img.megajoy.com/qvod/images/mute.gif";
        getObj("muteControl").alt = "关闭声音"
    } else {
        mute = true;
        QvodPlayer.Mute = mute;
        getObj("muteControl").src = "http://img.megajoy.com/qvod/images/mute_2.gif";
        getObj("muteControl").alt = "打开声音"
    }
}
var tdwidth = getObj("tdqvod").width;
var tdheight = getObj("tdqvod").height;
var isPorV = 0;
var fFlag = false;
var pFlag = false;
var vFlag = false;
var pZoneWidth = tdwidth - 20;
var vZoneWidth = 33;
var bufferingProgress = 0;
var downloadProgress = 0;
var bitRate;
var currentPositionString = "";
var mediaTitle;
var itemTitle;
var FirstPlay = true;

function mouseDown(a) {
    isPorV = a;
    if (isPorV == 0) {
        if (QvodPlayer.CurrentPos > 0) {
            pFlag = true;
            if (window.event.srcElement.id != "pZone") {
                getObj("pBox").style.left = getObj("pBox").offsetLeft - 1
            } else {
                getObj("pBox").style.left = (window.event.x - 12)
            }
        }
    } else {
        if (isPorV == 1) {
            vFlag = true;
            if (window.event.srcElement.id != "vZone") {
                getObj("vBox").style.left = getObj("vBox").offsetLeft + "px"
            } else {
                getObj("vBox").style.left = (window.event.x - 3)
            }
        }
    }
}
function mouseMove() {
    if (isPorV == 0) {
        if (QvodPlayer.CurrentPos > 0) {
            if (pFlag) {
                getObj("pBox").style.left = window.event.clientX - getOLeft(getObj("pZone")) - 12 + "px"
            }
            if (parseInt(getObj("pBox").style.left.replace("px", "")) > pZoneWidth) {
                getObj("pBox").style.left = pZoneWidth + "px"
            }
            if (parseInt(getObj("pBox").style.left.replace("px", "")) < -5) {
                getObj("pBox").style.left = -5 + "px"
            }
        }
    } else {
        if (isPorV == 1) {
            if (vFlag) {
                getObj("vBox").style.left = window.event.clientX - getOLeft(getObj("vZone")) - 4 + "px"
            }
            if (parseInt(getObj("vBox").style.left.replace("px", "")) > vZoneWidth) {
                getObj("vBox").style.left = vZoneWidth + "px"
            }
            if (parseInt(getObj("vBox").style.left.replace("px", "")) < 0) {
                getObj("vBox").style.left = 0 + "px"
            }
            if (isPorV == 1) {
                if (vFlag) {
                    tempVol = (parseInt(getObj("vBox").style.left) / vZoneWidth) * 100;
                    var b = Math.round(tempVol);
                    if (b < 0) {
                        b = 0
                    }
                    if (b > 100) {
                        b = 100
                    }
                    var c = b.toString(10);
                    var a = b;
                    QvodPlayer.Volume = a
                }
            }
        }
    }
}
function mouseUp() {
    if (isPorV == 0) {
        var b = QvodPlayer.CurrentPos;
        if (b > 0) {
            if (pFlag) {
                var f = QvodPlayer.Duration;
                var e = f * (parseInt(getObj("pBox").style.left) / pZoneWidth);
                e = Math.floor(e);
                if (e < 0) {
                    e = 0
                }
                QvodPlayer.CurrentPos = e
            }
            pFlag = false
        }
    } else {
        if (isPorV == 1) {
            if (vFlag) {
                e = (parseInt(getObj("vBox").style.left) / vZoneWidth) * 100;
                var c = Math.round(e);
                if (c < 0) {
                    c = 0
                }
                if (c > 100) {
                    c = 100
                }
                var d = c.toString(10);
                getObj("mediaInfo").innerText = "当前音量：" + Math.round(d) + "%";
                var a = c;
                QvodPlayer.Volume = a
            }
            vFlag = false
        }
    }
}
function mouseEnd() {
    window.event.returnValue = false
}
function OnloadFun() {
    startdrag();
    setInterval("FixPos()", 1000)
}
var hc = false;
var firstload = false;
var killad = false;

function FixPos() {
    if (!killad) {
        var g = '<invoke name="PauseAd" returntype="xml" UserAd="0"></invoke> ';
        var c = QvodPlayer.CallFunction(g);
        killad = true
    }
    if (!firstload) {
        QvodPlayer.Volume = 50;
        firstload = true
    }
    var e = QvodPlayer.Duration;
    if (e > 0) {
        if (QvodPlayer.get_CurTaskProcess() == 1000 && hc == false && typeof(nexturl) != "undefined") {
            QvodPlayer.StartNextDown(nexturl);
            hc = true
        }
        var m = QvodPlayer.CurrentPos;
        if (m == 0) {
            var o = Math.round(m / e * pZoneWidth) + 5
        } else {
            var o = Math.round(m / e * pZoneWidth) + 5
        }
        if (!isNaN(o)) {
            getObj("pBox").style.left = o
        }
        if (QvodPlayer.PlayState == 1) {
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/07.gif";
            getObj("pBox").style.left = 5;
            mediaInfo.innerText = "已停止"
        }
        downloadProgress = 0;
        downloadProgress = Math.round(QvodPlayer.Downrate);
        bitRate = 0;
        currentPositionString = "";
        if (e > 3600) {
            var n = Math.floor(e / 3600);
            var p = n > 9 ? n.toString(10) : ("0" + n.toString(10));
            var j = Math.floor((e % 3600) / 60);
            var q = j > 9 ? j.toString(10) : ("0" + j.toString(10));
            var d = Math.floor(e % 60);
            var i = d > 9 ? d.toString(10) : ("0" + d.toString(10));
            var f = Math.floor(m / 3600);
            var l = f > 9 ? f.toString(10) : ("0" + f.toString(10));
            var a = Math.floor((m % 3600) / 60);
            var b = a > 9 ? a.toString(10) : ("0" + a.toString(10));
            var h = Math.floor(m % 60);
            var k = h > 9 ? h.toString(10) : ("0" + h.toString(10));
            currentPositionString = l + ":" + b + ":" + k;
            currentPositionString = currentPositionString + " / ";
            currentPositionString = currentPositionString + p + ":" + q + ":" + i
        } else {
            var j = Math.floor((e % 3600) / 60);
            var q = j > 9 ? j.toString(10) : ("0" + j.toString(10));
            var d = Math.floor(e % 60);
            var i = d > 9 ? d.toString(10) : ("0" + d.toString(10));
            var a = Math.floor((m % 3600) / 60);
            var b = a > 9 ? a.toString(10) : ("0" + a.toString(10));
            var h = Math.floor(m % 60);
            var k = h > 9 ? h.toString(10) : ("0" + h.toString(10));
            currentPositionString = b + ":" + k;
            currentPositionString = currentPositionString + " / ";
            currentPositionString = currentPositionString + q + ":" + i
        }
        getObj("mediaTime").innerText = currentPositionString.toString();
        document.getElementById("iframe_ad").style.display = "none";
        switch (QvodPlayer.PlayState) {
        case 10:
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/08.gif";
            mediaInfo.innerText = "缓冲:(" + downloadProgress.toString(10) + " KB/S)";
            break;
        case 1:
            mediaInfo.innerText = "已停止";
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/07.gif";
            break;
        case 3:
            if (document.getElementById("divad")) {
                document.getElementById("divad").style.display = "none"
            }
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/08.gif";
            if (downloadProgress < 1) {
                mediaInfo.innerText = "播放中(" + QvodPlayer.get_Rate() + " Kbps)"
            } else {
                if (m <= 6) {
                    mediaInfo.innerText = "播放中(" + QvodPlayer.get_Rate() + " Kbps)"
                } else {
                    mediaInfo.innerText = "播放中(" + downloadProgress.toString(10) + " KB/S)"
                }
            }
            break;
        case 2:
            if (document.getElementById("divad")) {
                document.getElementById("divad").style.paddingTop = (tdheight - 240) / 2;
                document.getElementById("divad").style.paddingLeft = (tdwidth - 320) / 2;
                document.getElementById("divad").style.display = ""
            }
            mediaInfo.innerText = "已暂停";
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/07.gif";
            break;
        default:
            break
        }
    } else {
        downloadProgress = 0;
        downloadProgress = Math.round(QvodPlayer.Downrate);
        switch (QvodPlayer.PlayState) {
        case 0:
            mediaInfo.innerText = "准备就绪";
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/07.gif";
            document.getElementById("iframe_ad").style.display = "";
            break;
        case 10:
            mediaInfo.innerText = "正在缓冲 (" + downloadProgress.toString(10) + " KB/S)";
            getObj("mediaTime").innerText = "00:00 / 00:00";
            break;
        case 4:
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/08.gif";
            mediaInfo.innerText = "缓冲:(" + downloadProgress.toString(10) + " KB/S)";
            break;
        case 1:
            mediaInfo.innerText = "已停止";
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/07.gif";
            break;
        case 3:
            if (document.getElementById("divad")) {
                document.getElementById("divad").style.display = "none"
            }
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/08.gif";
            if (downloadProgress < 1) {
                mediaInfo.innerText = "播放中"
            } else {
                mediaInfo.innerText = "播放中(" + downloadProgress.toString(10) + " KB/S)"
            }
            break;
        case 2:
            if (document.getElementById("divad")) {
                document.getElementById("divad").style.display = ""
            }
            mediaInfo.innerText = "已暂停";
            getObj("playControl").src = "http://img.megajoy.com/qvod/images/07.gif";
            break;
        default:
            break
        }
    }
}
function startdrag() {
    if (QvodPlayer.Currentpos || (!isNaN(QvodPlayer.Currentpos))) {
        window.document.onmousemove = mouseMove;
        window.document.ondragstart = mouseEnd;
        window.document.onmouseup = mouseUp
    }
}
function PointPlay(a) {
    QvodPlayer.stop();
    mediaInfo.innerText = "正在缓冲";
    getObj("mediaTime").innerText = "00:00 / 00:00";
    QvodPlayer.URL = a;
    QvodPlayer.Play();
    getObj("playControl").src = "http://img.megajoy.com/qvod/images/08.gif"
}
OnloadFun();