function playerstop(obj) {
    //这是点击视频名称的动作，把要播放的视频索引赋给当前要播放的视频索引然后调用播放类（也就是视频结束类）
    //alert("1");
    if ($("#video").is(":hidden")) {
        $("#scormHtml").attr("src", "").hide();
        $("#video").show();
    }
    CKobject._K_('video').innerHTML = '<div id="a1"></div>';
    $("#interMain").html("<center style=\"color: #999;\">Yet no one spoke</center>");
    if ($(".hover").length > 0)
        $(".hover").removeClass("hover").addClass("old");
    if (obj == undefined || obj == null) {
        //设置当前播放的列表样式
        for (var i = 0; i < flvurl.length; i++) {
            if (i == dqbh) {

                //alert("2");
                CKobject._K_('list_' + i).className = 'hover'; //设置新的样式
                $("#cstitle").html($("#list_" + i).find("a").text());
                playVodieId = $("#list_" + i).find("a").attr("id"); //得到现在播放的ID
            }
        }
    } else {
        $(obj).parent().removeClass("old").addClass("hover");
        $("#cstitle").html($(obj).text());
        playVodieId = $(obj).attr("id"); //得到现在播放的ID
    }

    //设置列表样式结束
    var flashvars = {
        f: flvurl[dqbh],
        c: 0,
        b: 0,
        p: 1,
        e: 0,
        h: 3
    };
    var params = { bgcolor: '#000', allowFullScreen: true, allowScriptAccess: 'always', wmode: 'opaque' };
    var video = [flvurl[dqbh] + '->video/mp4'];
    //老方法CKobject.embedSWF('/Training/Learn/m/ckplayer/ckplayer.swf', 'a1', 'ckplayer_a1', '100%', $(window).height() - 100, flashvars, params);
    //以下为新方法
    CKobject.embed('/Training/Learn/m/ckplayer/ckplayer.swf', 'a1', 'ckplayer_a1', '100%', $(window).height() - 100, false, flashvars, video, params);
    
    //当为MP4格式时调用HTML5
    var houzhui = flvurl[dqbh].substring(flvurl[dqbh].lastIndexOf(".") + 1);
    //alert(houzhui);
    if (!CKobject.Flash()['f']) {//当系统不支持FLASH时
        if (browser.versions.android) {//安卓建议安装flash, 这样才能支持横屏
            $("#noflash").html("<a href=\"http://www.newstartsoft.com/flashplayer.apk\"  target=\"_blank\" style=\"color:red\">You need to install flash player [Click to download] refresh the interface after installation</a>");
            document.getElementById("noflash").style.display = "block";
            document.getElementById("video").style.display = "none";
        }
        else {
            if (houzhui == "mp4") {
                var video = [flvurl[dqbh] + '->video/mp4'];
                var support = ['iPad', 'iPhone', 'ios', 'android', 'msie10+false', 'webKit', 'IEMobile'];
                CKobject.embedHTML5('video', 'ckplayer_a1', '100%', $(window).height() * 0.5, video, flashvars, support);
            } else {
                $("#noflash").html("Sorry, your device does not support the FLV video format, please see the other video!");
                document.getElementById("noflash").style.display = "block";
                document.getElementById("video").style.display = "none";
            }
        }
    }
    dqbh = dqbh + 1; //把正在播放的视频的索引+1得到下个视频的索引用来做循环播放
    if (dqbh >= flvurl.length) {
        //全部视频都播放完成后，目前回到第一个视频，也可以对用户进行提示
        dqbh = 0;
    }
    iframeresize();
    //    windowActive();
}
function playload(obj, str) {
    dqbh = str;
    playerstop(obj);
}
//html网页资源课件的点击事件
function showHtml(obj, urlSrc) {
    if ($("#scormHtml").is(":hidden")) {
        $("#ckplayer_a1").remove();
        $("#video").hide();
        $("#scormHtml").show();
    }
    playTime = 0;
    setInterval(function () { playTime++; }, 1000);
    $(".hover").removeClass("hover").addClass("old");
    $(obj).parent().removeClass("old").addClass("hover");
    playVodieId = $(obj).attr("id");
    $("#scormHtml").attr("src", urlSrc);
    $("#cstitle").html($(obj).text());
    iframeresize();
    //    windowActive();
}

$(function () {
    iframeresize(); //自动调整页面自适应尺寸
    setInterval(getchart, 10000); //加载互动信息,10秒查1次
    setInterval(Setlearntime, 10000); //统计学习时间,10秒统计1次，越小统计精度越大

});
//更新统计学习时间
function Setlearntime() {
    $.get("/Training/Learn/Interacts.ashx?Key=" + QueryString("Key") + "&t=" + zanting);
}
function right_frameclose() {
    $("#right_frame").animate({ right: "-187px" }, function () { $("#Tmain").css("margin-right", "0"); });
    $("#right_frame_btn").attr("src", "/Training/Learn/m/tringht_open.gif");
    $("#right_frame_btn").attr("onclick", "right_frameopen(this)");
}
function right_frameopen() {
    $("#right_frame").animate({ right: 0 }, function () { $("#Tmain").css("margin-right", "187px"); });
    $("#right_frame_btn").attr("src", "/Training/Learn/m/tringht_close.gif");
    $("#right_frame_btn").attr("onclick", "right_frameclose(this)");
}
//菜单操作
function rightgo(obj, id) {
    // right_frameclose();
    $("#left_menu a").removeClass("hover");
    $(obj).addClass("hover");
    if (id == 1) {
        $("#Interacts").show()
        $("#rightmain").hide();
    } else if (id == 2) {
        $("#rightmain").attr("src", "Learn_Shares.aspx?Key=" + QueryString("Key"));
        $("#rightmain").show();
        $("#Interacts").hide();

    } else if (id == 3) {
        $("#rightmain").attr("src", "/Training/Exam/Practise_List.aspx?Key=" + QueryString("Key"));
        $("#rightmain").show();
        $("#Interacts").hide();
    } else if (id == 4) {
        $("#rightmain").attr("src", "/Training/Exam/Practise_List.aspx?Key=" + QueryString("Key") + "&type=1");
        $("#rightmain").show();
        $("#Interacts").hide();
    } else if (id == 5) {
        $("#courBar").css('display', 'block');
        $("#courDetail").stop().animate({ left: 5 });
    }
    else {
        window.open("/Frame/MainPet.aspx?url=/Training/ExamPlan/ExamSchoolAssignment.aspx?Key=" + QueryString("Key"));
    }
    right_frameopen();
}

//视频播放
function playstart() {
    CKobject.getObjectById('ckplayer_a1').videoPlay();
}
//切换播放视频
function playGoto(filepath) {
    //参数格式：{f->http://movie.ks.js.cn/flv/2012/02/6-1.flv}
    CKobject.getObjectById('ckplayer_a1').newAddress(filepath);
}
//播放状态监控
var zanting = 1;
function ckplayer_status(str) {
    //103暂停，102开始播放，101播放结束，105全屏，108加载结束（准备就绪）
    //$("#interText").val(str);//反馈数据测试
    var nowtime = str.substring(0, 5);
    if (nowtime == "time:") {
        playTime = str.substr(5); //当前播放时间
        zanting = 1;
    }
    else if (str == 106) {
        alert("I'm sorry, teaching video failed to load!"); //106打开视频错误
    }
    else if (str == 'pause') {
        zanting = 0;
    } else if (str == 'play') 
        //浏览器失去焦点和获得焦点自动暂停播放
        window.top.onblur = function () {
            zanting = 0;
            CKobject.getObjectById('ckplayer_a1').videoPause();
        };
        window.top.onfocus = function () {
            zanting = 1;
            CKobject.getObjectById('ckplayer_a1').videoPlay();
        };
//            alert("sd"); 
    }
//    else if (str.length > 10) {
//        //alert(str); 
//    }
//}
//获取互动
function getchart() {
    // alert("asd");
    $.getScript("/Training/Learn/Interacts.ashx?Key=" + QueryString("Key") + "&pid=" + jbid + "&Time=" + playTime);
    $("#interMain").scrollTop(100);
}
//发言
function setchart() {
    $.get("/Training/Learn/Interacts.ashx",
            { Key: QueryString("Key"), pid: jbid, Time: playTime, ChartText: $("#interText").val() },
            function (data) {
                if (data == "ok") {
                    $("#interMain").prepend("<p class='schart'>I said:" + $("#interText").val() + "<span>" + playTime + "</span></p>");
                    getchart();
                }
                else if (data == "nouser") {
                    alert("Prohibit anonymous messages, please login!");
                }
                else {
                    alert("Speak of failure!");
                }
            });
}
//点击发言区
function myinput(obj) {
    if (obj.value == "The input speech in here..") {
        obj.value = "";
    }
}
//鼠标移动开时
function inputonblur(obj) {
    if (obj.value == "") {
        obj.value = "The input speech in here..";
    }
}
//得到QueryString
function QueryString(fieldName) {
    fieldName = fieldName.toLowerCase();
    var urlString = document.location.search.toLowerCase();
    if (urlString != null) {
        var typeQu = fieldName + "=";
        var urlEnd = urlString.indexOf(typeQu);
        if (urlEnd != -1) {
            var paramsUrl = urlString.substring(urlEnd + typeQu.length);
            var isEnd = paramsUrl.indexOf('&');
            if (isEnd != -1) {
                return paramsUrl.substring(0, isEnd);
            }
            else {
                return paramsUrl;
            }
        }
        else {
            return "";
        }
    }
    else {
        return "";
    }
}
var Offlights = {
    create: function () {
        return function () {
            this.initialize.apply(this, arguments)
        }
    }
}
var OverLay = Offlights.create();
OverLay.prototype = {
    initialize: function (options) {
        this.SetOptions(options);
        this.browser = (function (ua) {
            var a = new Object();
            var b = {
                msie: /msie/.test(ua) && !/opera/.test(ua),
                opera: /opera/.test(ua),
                safari: /webkit/.test(ua) && !/chrome/.test(ua),
                firefox: /firefox/.test(ua),
                chrome: /chrome/.test(ua)
            };
            var vMark = "";
            for (var i in b) {
                if (b[i]) { vMark = "safari" == i ? "version" : i; break; }
            }
            b.version = vMark && RegExp("(?:" + vMark + ")[\\/: ]([\\d.]+)").test(ua) ? RegExp.$1 : "0";
            b.ie = b.msie;
            b.ie6 = b.msie && parseInt(b.version, 10) == 6;
            b.ie7 = b.msie && parseInt(b.version, 10) == 7;
            b.ie8 = b.msie && parseInt(b.version, 10) == 8;
            a.B = vMark;
            a.V = b.version;
            return a;
        })(window.navigator.userAgent.toLowerCase());
        this.isIE = this.browser['B'] == 'msie' ? true : false;
        this.isIE6 = (this.isIE && this.browser['V'] == 6) ? true : false;
        this._K_ = function (id) { return "string" == typeof id ? document.getElementById(id) : id };
        this.Lay = this._K_(this.options.Lay) || document.body.insertBefore(document.createElement("div"), document.body.childNodes[0]);
        this.Color = this.options.Color;
        this.Opacity = parseInt(this.options.Opacity);
        this.zIndex = parseInt(this.options.zIndex);
        with (this.Lay.style) {
            display = "none";
            zIndex = this.zIndex;
            left = top = 0;
            position = "fixed";
            width = height = "100%"
        }
        if (this.isIE6) {
            this.Lay.style.position = "absolute";
            this._resize = this.Bind(this,
            function () {
                this.Lay.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth) + "px";
                this.Lay.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) + "px"
            });
            this.Lay.innerHTML = ''
        }
    },
    Bind: function (object, fun) {
        return function () {
            return fun.apply(object, arguments)
        }
    },
    Extend: function (destination, source) {
        for (var property in source) {
            destination[property] = source[property]
        }
    },
    SetOptions: function (options) {
        this.options = {
            Lay: null,
            Color: "#000",
            Opacity: 100,
            zIndex: 50
        };
        this.Extend(this.options, options || {})
    },
    Show: function () {
        if (this.isIE6) {
            this._resize();
            window.attachEvent("onresize", this._resize)
        }
        with (this.Lay.style) {
            this.isIE ? filter = "alpha(opacity:" + this.Opacity + ")" : opacity = this.Opacity / 100;
            backgroundColor = this.Color;
            display = "block"
        }
    },
    Close: function () {
        this.Lay.style.display = "none";
        if (this.isIE6) {
            window.detachEvent("onresize", this._resize)
        }
    }
};
var LightBox = Offlights.create();
LightBox.prototype = {
    initialize: function (options) {
        this.OverLay = new OverLay(options);
    },
    Show: function (options) {
        this.OverLay.Show();
    },
    Close: function () {
        this.OverLay.Close();
    }
};
//开关灯
var box = new LightBox();
function closelights() {//关灯
    box.Show();
}
function openlights() {//开灯
    box.Close();
}