
(function (config) {

    /**
     * 配置信息
     */
    var courseid = config.courseid;
    var PeriodID = config.PeriodID;

    /**
     * 道具相关
     */
    var pp = 1;                                    //校验一次登录状态
    var strs = new Array();                        //数据存储
    var turninfo = new Array();                    //数据存储    大转盘需要
    var propcourseid = config.courseid;
    var propperiod = config.PeriodID;
    var ismobiletype = config.ismobiletype;        //判断手机的标志
    var gametimes = 0;                             //触发游戏的时间点
    /**
     * 试听需要的配置
     */
    var isbuy = config.isbuy || 0;                 //是否购买的判断
    var listenseconds = config.listenseconds || 0; // 试听的时间
    //var listenseconds = config.loginstatus ;     // 登陆状态

    
    var outFlag = true;                            //离开本页面是否提示 
     
    /**
     * 定义播放器监听方法
     */
    var pm;
    var saveFlag = true;
    var listenMonitor = true;
    function loadPm(){
        
        var playerType = Number(config.playerType);
        if(playerType === 0){
            
            if(typeof player === 'undefined' && typeof CKobject !== 'undefined'){
                player = CKobject.getObjectById('ckplayer_a1');
            }
            if(!player){
                player = document.getElementById('ckplayer_a1')
            }
           
        }else if(typeof player === 'undefined'){
            
            /**
             * 未找到播放器对象，可能还处于加载中
             * 进行轮询等待
             */
            setTimeout(function() {
                loadPm()
            }, 100);
            return false
        }
        pm = new playerMonitor(player,playerType,{
            ready:function(){
                console.log('媒体已准备就绪')

                /**
                 * 判断道具信息是否显示
                 * 没显示则执行方法
                 */
                if ($("#daojuinfo").is(":hidden")) {
                    var info = $("#propcontent").val();
                    if (info != "") {
                        strs = info.split("&&");
                        setInterval(function () {
                            diaoyongdaoju()
                        }, 100)
                    }
                }
                /**
                 * 校验试听
                 */ 
                setInterval(function () {
                    listenMonitor && CheckListen();
                }, 100)
                /**
                 * 恢复上次播放
                 */

               //  pm.seek(config.learnCount)

                setInterval(function(){
                    saveFlag && setsave()
                },config.saveSpeed)
            
            },
            play:function(){
                console.log('开始播放');
				window.onbeforeunload = function(event){
                    setsave(null,1);
                    if(outFlag){
					    
                        return '确认退出吗？'
                    }
                };
                $('course-keshi').on('click','.keshi-url',function(){
                    if($(this).attr('href')){
                        outFlag = false
                    }
                })
                saveFlag = true;
            },
            pause:function(){
                console.log('暂停')
                saveFlag = false;
                setsave(null,1)
            },
            over:function(){
                console.log('播放结束');
                setsave(function(){
                     /**
                     * 保存学习进度后跳到下一个课时
                     */
                    if (dropurl != '#') {
                        location.href = dropurl;
                    }
                })
            },
            seek:function(){
                console.log('进度调整')
                
            },
            error:function(){
                console.log('视频出错')
            }
        })
    };
    
    loadPm();
    
    /**
     * 保存学习进度
     */
    
    function setsave(fn,savetodb)
    {
        var totaltime = pm.getDuration();
        var time = pm.getCurrentTime();
        /**
         * savetodb 是否是通过手动控制播放器事件，比如暂停、播放
         */
        if (savetodb == undefined) savetodb = 0;
        $.ajax({
            type: 'Post', 
            url: "/index.aspx?c=course&a=play&action=save&courseid=" + courseid + "&pid="+PeriodID+"&costype="+config.Teachway+"&time=" + parseInt(time) + "&totaltime=" + parseInt(totaltime)+"&savetodb="+savetodb,
            success: function (msg) {
                typeof fn === 'function' && fn();
                if(msg == "nopower")
                {
                    saveFlag = false;
                    
                    KesionJS.Alert("对不起，您的学习次数已到，无权进入学习",'location.href = \''+config.courseViewUrl+'\'');
                }else if(msg === 'failmutilogin'){
                    saveFlag = false;
                    KesionJS.Alert("对不起，账号在其它地方登录",'location.href = \'/\'');
                }
            }
        });
    }
    
    
    /**
     * 调用时间点
     */
    function diaoyongdaoju()
    {
        gametimes = pm.getCurrentTime(); 
        
        var time = gametimes;
        for (var i = 0; i < strs.length; i++) {

            //判断课时相等时   在判断时间
            if (strs[i].split("||")[0] == propperiod) {
                //时间相等时
                if (parseInt(time) == parseInt(strs[i].split("||")[2]) && parseInt(time) != 0) {
                    var proptype = strs[i].split("||")[1];//获取道具类型
                    var times = strs[i].split("||")[2];//时间点
                    var propinfo = strs[i].split("||")[3];//道具关联的id信息   获取的积分
                    var worknum = strs[i].split("||")[4];//做题数量
                    var loadtype = strs[i].split("||")[5];//  视频播放状态                    道具加载方式
                    var propid = strs[i].split("||")[6];//道具id
                    //alert("Ajax前测试出发！" + times + "||" + propcourseid + "||" + propperiod + "||" + propperiod + "||" + propinfo + "||" + worknum + "||" + proptype);
                    jQuery.ajax({
                        type: "post",
                        url: "/plus/course/CourseAjax.ashx?action=provingProps&shijian=" + times + "&courseid=" + propcourseid + "&periodid=" + propperiod + "&propid=" + propid + "&bindid=" + propinfo + "&wordnum=" + worknum + "&proptype=" + proptype + "&ismobiletype=" + ismobiletype,
                        success: function (data) {
                            //登录和道具是否使用的校验
                            if (data.indexOf("login") != -1)//检测登录
                            {
                                
                                if (pp == 1) {
                                    pp++;
                                    status = 1;
                                    
                                    pm.pause()
                                    
                                    KesionJS.Alert('您未登录，请登录！', 'showuserlogin();');
                                }
                            } else {
                                if (data.indexOf("==1==") != -1) {//使用过  不操作
                                } else {//否则没使用 
                                        if (loadtype == 1) {
                                            //视频暂停
                                            pm.pause()
                                        }
                                        tishi(proptype, times, propinfo, worknum, propid, propcourseid, propperiod, data);
                                }
                            }
                        }
                    })
                }
            }

        }
    }

    /**
     * 试听校验
     */
    function CheckListen()
    { 
        gametimes = pm.getCurrentTime();
        //试听判断   
        if (parseInt(isbuy) == 10000 && parseInt(listenseconds) > 0 && parseInt(listenseconds) <= parseInt(gametimes)) {

            pm.pause();
            outFlag = false;
            listenMonitor = false;
            KesionJS.Alert('试听结束，请前往购买！');
            setTimeout(function(){
                location.href = config.courseViewUrl
            },1000)
        }

    }


    /**
     * 标记已学
     */
    window.setmark = function(el) {
       
        var totaltime = 0,time = 0;
        if(pm){
            totaltime = pm.getDuration();
            time = pm.getCurrentTime();
        }
        
        var $el = $(el);
        $.ajax({
            type: 'Post',
            url: "/index.aspx?c=course&a=play&pid="+PeriodID+"&action=setmark&courseid="+courseid+"&cosType="+config.Teachway+"&time=" + parseInt(time) + "&totaltime=" + parseInt(totaltime),
            success: function (msg) {
                if (msg==1)
                {
                    $el.val("已学");
                    $el.prop("onclick",null).off("click");
                    
                }else{
                    showuserlogin();   
                }
            }
        });
    }
    
    
    /**
     * 道具的使用方法
     */
    function tishi(type, times, bindid, worknum, propid,courseid,lessonid,data)
    {
        $("#answerBox").hide();
        $("#turnBox").hide();//大转盘游戏显示
        $("#redrain").hide();//红包
        $("#examhomeBox").hide();//考试 
        $("#voteBox").hide();//答题
        $("#svoteBox").hide();//答完题
        $("#CurrpromotBox").hide();//商品
        $("#propinfo").hide();//积分  公告
        $("#questionBox").hide();//问卷
        $("#failBox").hide();//大转盘未抽到奖
        $("#successBox").hide();//抽到奖
        if (ismobiletype == 1) {//手机端 
            $("#zhuanpan").hide();
            $("#gonggao").hide();
            $("#sj").hide();
        }
        if (worknum == "") { worknum = 0; }//默认为零
        setTimeout(function () {
            $('.innercon').each(function () {
                //超出的滚动条
                $(this).niceScroll({
                    cursorcolor: "rgba(0,0,0,0.1)",
                    cursoropacitymax: 1,
                    touchbehavior: false,
                    cursorwidth: "6px",
                    cursorborder: "0",
                    cursorborderradius: "5px"
                });
            }); 
        }, 1000);
        //type = "6";
        switch (type)
        {
            case "0"://积分
                var shijan = parseInt(times) / 60
                var jifen = "";
                if (ismobiletype == 1) {
                    jifen = "<div class='integral stopclick' ><div class='in-num'> " + bindid + "<i>分</i> </div><div class='receive-btn'><a href='javascript:;' onclick=recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ") >点击领取</a></div></div>";
                } else {
                    jifen = "<div class='a-con' ><div class='a-Num'>" + bindid + "</div><div class='a-tips'>您已观看了" + shijan + "分钟，获得奖励积分</div><input type=button class=a-btn value=领取 class=button onclick=recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ") /></div>";
                }
                $("#propinfo").html(jifen);
                $("#questionBox,#examhomeBox,#voteBox,#svoteBox,#CurrpromotBox").hide();//问卷
                $("#propinfo").show();
                break;
            case "1"://问卷
                
                $("#questionBox").html("<div class='questionnaire stopclick'>"+data+"</div>");

                $("#propinfo").hide();
                $("#voteBox").hide();
                $("#svoteBox").hide();
                $("#CurrpromotBox").hide();
                $("#examhomeBox").hide();
                $("#questionBox").show();
                
                break;
            case "2"://公告
                var gonggao = "";
                if (ismobiletype == 1) {
                    gonggao = "<div class='marquee-box' onclick=recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ") ><marquee scrollamount='4'>" + data + "</marquee></div>";
                    $("#gonggao").html(gonggao);
                }
                else
                {
                    gonggao = "<div class='noticeBox' ><div class='n-con'><div class='n-innercon innercon'><p>" + data + "</p></div><div class='n-btn'><a href='javascript:;' onclick=recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ") ></a></div></div></div>";
                    $("#propinfo").html(gonggao);
                }

                $("#questionBox").hide();//问卷
                $("#examhomeBox").hide();
                $("#voteBox").hide();
                $("#svoteBox").hide();
                $("#CurrpromotBox").hide();
                $("#propinfo").show();
                
                break;
            case "3"://投票
                var toupiao = "";
                if (ismobiletype == 1) {//手机端
                    toupiao = "<div class='vote stopclick'>"+data+"<div class='votebtn'><a href='javascript:;' onclick='tjtoupiao();recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ")' >确定投票</a></div></div></div>";
                }
                else {//PC端
                    toupiao = data + "<div class='v-submit-btn' ><input type='image' src='/sysimg/prop/tpbtn.png' onclick='tjtoupiao();recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ")'  /></div></div>";
                }
                $("#voteBox").html(toupiao);

                $("#questionBox").hide();//问卷
                $("#examhomeBox").hide();
                $("#svoteBox").hide();
                $("#propinfo").hide();
                $("#CurrpromotBox").hide();
                $("#voteBox").show();
                
                break;
            case "4"://试卷
                $("#questionBox").hide();//问卷
                $("#voteBox").hide();
                $("#svoteBox").hide();
                $("#propinfo").hide();
                $("#CurrpromotBox").hide();
                var shop="";
                if (data != "0") {
                    if (ismobiletype == 1) {//手机端
                        $("#sj").show();
                        shop = "<a href='" + data + "' class='test-btn' onclick=recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ")></a>";
                    } else {
                        shop = "<div class='e-con clearfix'><a href='" + data + "' target='_blank'  class='answerBtn ' onclick=recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ") ><em class='earrow'></em></a><a href=javascript:; onclick=closetoupiao(4);recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ") class='noanswerBtn'><em class='earrow'></em></a></div>";
                    }
                    $("#examhomeBox").html(shop);
                }
                $("#examhomeBox").show();
                    
                break;
            case "5"://商品 
                $("#voteBox").hide();
                $("#svoteBox").hide();
                $("#propinfo").hide();
                $("#questionBox").hide();//问卷
                var shop ="";
                if (data != "0") {
                    if (ismobiletype == 1) {
                        shop = data+"";
                    } else
                    {
                        shop = "<span class='closeBtn2' title='关闭' onclick=recordprop(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ") ></span><div class='clearfix'>" + data + "</div>";
                    }
                    $("#CurrpromotBox").html(shop);
                } else {
                    $("#CurrpromotBox").html("商品已过期或被移除！");
                }
                $("#CurrpromotBox").show();
                    
                break;
            case "6"://游戏  
                if (data.indexOf("红包") != -1) {//红包信息  
                    
                    var info = new Array();//数据存储
                    info = data.split("#&#");
                    if (ismobiletype == 1) {  
                        $("#redrain").show();
                        var hongbao = info[1] + "<div class='receive-btn'><a href='javascript:;' onclick=closetoupiao(6) >点击领取</a></div>";
                    } else {
                        var hongbao = info[1] + "<a href='javascript:;' title='关闭' class='shareBtn' onclick=closetoupiao(6) ></a>";
                    }

                    $("#hongbao").html(hongbao);
                    $("#hongbao").show();
                    $("#turnBox").hide();//大转盘游戏隐藏
                    $("#redrain").show();

                    $(".redrainBox").on('click', '.redBtn', function () {
                        $(".redrainBox").addClass("shake2");
                        setTimeout(function () {
                            $(".redrainBox").removeClass("animated zoomIn shake2");
                            $(".redrainBox").css("opacity", "0.3");
                            $(".redrainBox").addClass("disabled");
                            $(".openRedBox").fadeIn();
                        }, 1000);
                    });
                    cavasLoad();
                    
                } else if (data.indexOf("抢答题") != -1) {//抢答题目
                    var info = new Array();//数据存储
                    info = data.split("&#&");
                    var qaingda="";
                    if (ismobiletype == 1) {
                        $("#money").hide();//红包
                        qaingda = "<div class='questionnaire stopclick'><span class='quest-icon'></span>" + info[1] + "<div class='quest-schedule'><div class='schedule-text'><input type='button' value='提交' class='quest-subt' onclick=return(addcheck(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ")); ></div></div>";
                    } else {
                        qaingda = info[1] + "<div class='anBtn'><input type='button' value='确定' onclick=return(addcheck(" + propid + "," + type + "," + bindid + "," + times + "," + worknum + "," + courseid + "," + lessonid + ")); ></div></div></div></div>";
                    }
                    $("#turnBox").hide();//转盘
                    $("#answerBox").html(qaingda);//抢答题
                    $("#answerBox").show();
                }
                else {//大转盘游戏
                    var game = "";
                    if (ismobiletype == 1) {
                        $("#money").hide();
                        $("#zhuanpan").show();
                        game =" <div class='shade-btn'  ><a href='javascript:;' ></a></div><div class='slyder-gift' ><ul > "+data+"</ul><div>";
                    } else {
                        game="<div class='turntable-bg'><div class='pointer' >" + data + "</div>";
                    }
                    $("#answerBox").hide();
                    $("#hongbao").hide();
                    $("#turnBox").html(game);//选项填充
                    $("#turnBox").show();//游戏显示

                    if (ismobiletype == 1) {//手机的大转盘
                        
                        //大转盘
                        var turnplate = {
                            restaraunts: ["再接再厉", "一等奖", "谢谢参与", "三等奖", "幸运奖", "二等奖"],				//大转盘奖品名称
                            colors:  ["#ff625f", "#fec353", "#ff625f", "#fec353", "#ff625f", "#fec353"],					//大转盘奖品区块对应背景颜色
                            outsideRadius: 185,			//大转盘外圆的半径
                            textRadius: 155,				//大转盘奖品位置距离圆心的距离
                            insideRadius: 60,			//大转盘内圆的半径
                            startAngle: 0,				//开始角度
                            bRotate: false				//false:停止;ture:旋转
                        };

                        drawRouletteWheel();//添加渲染

                        //动态添加大转盘的奖品与奖品区域背景颜色
                        //turnplate.restaraunts = ["再接再厉", "一等奖", "谢谢参与", "三等奖", "幸运奖", "二等奖"];
                        //turnplate.colors = ["#ff625f", "#fec353", "#ff625f", "#fec353", "#ff625f", "#fec353"];
                        
                        var rotateTimeOut = function () {
                            $('#wheelcanvas').rotate({
                                angle: 0,
                                animateTo: 2160,
                                duration: 8000,
                                callback: function () {
                                    alert('网络超时，请检查您的网络设置！');
                                }
                            });
                        };
                        //旋转转盘 item:奖品位置; txt：提示语;
                        var rotateFn = function (item, txt) {
                            var angles = item * (360 / turnplate.restaraunts.length) - (360 / (turnplate.restaraunts.length * 2));
                            if (angles < 270) {
                                angles = 270 - angles;
                            } else {
                                angles = 360 - angles + 270;
                            }
                            $('#wheelcanvas').stopRotate();
                            $('#wheelcanvas').rotate({
                                angle: 0,
                                animateTo: angles + 1800,
                                duration: 8000,
                                callback: function () {
                                    addgame(txt);//转圈圈    加载奖励信息
                                    turnplate.bRotate = !turnplate.bRotate;
                                }
                            });
                        };

                        $('.pointer').click(function () {
                            if (turnplate.bRotate) return;
                            turnplate.bRotate = !turnplate.bRotate;
                            //获取随机数(奖品个数范围内) 
                            var item = rnd(1, turnplate.restaraunts.length);
                            //奖品数量等于10,指针落在对应奖品区域的中心角度[252, 216, 180, 144, 108, 72, 36, 360, 324, 288]
                            jQuery.ajax({
                                type: "post",
                                url: "/plus/course/CourseAjax.ashx?action=addgame&gameid=" + bindid + "&propid=" + propid + "&ismobiletype=" + ismobiletype,
                                success: function (data) {
                                    turninfo = data.split("&#&");
                                    rotateFn(turninfo[0], turninfo[1]);
                                }
                            });
                            
                        }); 
                        function drawRouletteWheel() {
                            var canvas = document.getElementById("wheelcanvas");
                            if (canvas.getContext) {
                                //根据奖品个数计算圆周角度
                                var arc = Math.PI / (turnplate.restaraunts.length / 2);
                                var ctx = canvas.getContext("2d");
                                //在给定矩形内清空一个矩形
                                ctx.clearRect(0, 0, 422, 422);
                                //strokeStyle 属性设置或返回用于笔触的颜色、渐变或模式  
                                ctx.strokeStyle = "#ff5c5d";
                                //font 属性设置或返回画布上文本内容的当前字体属性
                                ctx.font = 'bold 1.2rem Microsoft YaHei';
                                for (var i = 0; i < turnplate.restaraunts.length; i++) {
                                    var angle = turnplate.startAngle + i * arc;
                                    ctx.fillStyle = turnplate.colors[i];
                                    ctx.beginPath();
                                    //arc(x,y,r,起始角,结束角,绘制方向) 方法创建弧/曲线（用于创建圆或部分圆）    
                                    ctx.arc(211, 211, turnplate.outsideRadius, angle, angle + arc, false);
                                    ctx.arc(211, 211, turnplate.insideRadius, angle + arc, angle, true);
                                    ctx.stroke();
                                    ctx.fill();
                                    //锁画布(为了保存之前的画布状态)
                                    ctx.save();

                                    //----绘制奖品开始----
                                    ctx.fillStyle = "#fff";
                                    var text = turnplate.restaraunts[i];
                                    var line_height = 30;
                                    //translate方法重新映射画布上的 (0,0) 位置
                                    ctx.translate(211 + Math.cos(angle + arc / 2) * turnplate.textRadius, 211 + Math.sin(angle + arc / 2) * turnplate.textRadius);

                                    //rotate方法旋转当前的绘图
                                    ctx.rotate(angle + arc / 2 + Math.PI / 2);

                                    /** 下面代码根据奖品类型、奖品名称长度渲染不同效果，如字体、颜色、图片效果。(具体根据实际情况改变) **/
                                    if (text.indexOf("M") > 0) {//流量包
                                        var texts = text.split("M");
                                        for (var j = 0; j < texts.length; j++) {
                                            ctx.font = j == 0 ? 'bold 1.2rem Microsoft YaHei' : '16px Microsoft YaHei';
                                            if (j == 0) {
                                                ctx.fillText(texts[j] + "M", -ctx.measureText(texts[j] + "M").width / 2, j * line_height);
                                            } else {
                                                ctx.fillText(texts[j], -ctx.measureText(texts[j]).width / 2, j * line_height);
                                            }
                                        }
                                    } else if (text.indexOf("M") == -1 && text.length > 6) {//奖品名称长度超过一定范围 
                                        text = text.substring(0, 6) + "||" + text.substring(6);
                                        var texts = text.split("||");
                                        for (var j = 0; j < texts.length; j++) {
                                            ctx.fillText(texts[j], -ctx.measureText(texts[j]).width / 2, j * line_height);
                                        }
                                    } else {
                                        //在画布上绘制填色的文本。文本的默认颜色是黑色
                                        //measureText()方法返回包含一个对象，该对象包含以像素计的指定字体宽度
                                        ctx.fillText(text, -ctx.measureText(text).width / 2, 30);
                                    }
                                    //把当前画布返回（调整）到上一个save()状态之前 
                                    ctx.restore();
                                    //----绘制奖品结束----
                                }
                            }
                        }
                    }
                    else
                    {
                        //大转盘
                        var rotateTimeOut = function () {
                            $('#rotate').rotate({
                                angle: 0,
                                animateTo: 2160,
                                duration: 8000,
                                callback: function () {
                                    alert('网络超时，请检查您的网络设置！');
                                }
                            });
                        };
                        var bRotate = false;
                        var rotateFn = function (awards, angles, txt) {
                            bRotate = !bRotate;
                            $('#rotate').stopRotate();
                            $('#rotate').rotate({
                                angle: 0,
                                animateTo: angles + 1800,
                                duration: 8000,
                                callback: function () {
                                    addgame(txt);//转弯
                                    bRotate = !bRotate;
                                }
                            })
                        };
                        $('.pointer').click(function () {
                            if (bRotate) return;
                            var items = rnd(0, 20);
                            var angle = new Array(10, 50, 127, 185, 235, 287);//数据存储
                            jQuery.ajax({
                                type: "post",
                                url: "/plus/course/CourseAjax.ashx?action=addgame&gameid=" + bindid + "&propid=" + propid + "&ismobiletype=" + ismobiletype,
                                success: function (data) {
                                    turninfo = data.split("&#&");
                                    rotateFn(turninfo[0], angle[parseInt(turninfo[0])], turninfo[1]);
                                }
                            });
                        // rotateFn(5, 287, '谢谢参与'); 
                        });
                    }
                    function rnd(n, m) {
                        return Math.floor(Math.random() * (m - n + 1) + n)
                    };
                } 
                $("#examhomeBox").hide();//考试 
                $("#voteBox").hide();//答题
                $("#svoteBox").hide();//答完题
                $("#CurrpromotBox").hide();//商品
                $("#propinfo").hide();//积分  公告
                $("#questionBox").hide();//问卷
                break;
        }
        if (type == "6" && ismobiletype == 1 && data.indexOf("红包") != -1) {//手机红包才单独拿出来
            $("#daojuinfo").hide();
        } else {
            $("#daojuinfo").show();
            document.getElementById('daojuinfo').style.display = 'block';
        }
        
        //执行提示回调
        typeof tishiFun === 'function' && tishiFun()

    }
    
    //记录道具的使用情况-课程id -课时id -道具id -道具类型  -内容  -时间点
    window.recordprop = function(propid,proptype,propinfo,times,worknum,courseid,lessonid)
    {
        //抢答题答案
        jQuery.ajax({
            type: "post",
            url: "/plus/course/CourseAjax.ashx?action=recordprops&shijian=" + times + "&propid=" + propid + "&proptype=" + proptype + "&propinfo=" + propinfo + "&worknum=" + worknum + "&courseid=" + courseid + "&lessonid=" + lessonid ,
            success: function (data) {
                if (proptype == 3) {//不等于投票时执行下面

                } else if (proptype == 1) {//不等于问卷执行下面

                } else if (proptype == 6) {//不等于游戏执行下面

                } else{
                    pp = 1;
                    pop = 1;
                    document.getElementById('daojuinfo').style.display = 'none';//隐藏道具信息
                    //恢复播放
                    pm.play()
                }
            }
        });
    }


    
    /************************************提交投票信息  并显示结果***************************************************/
    window.tjtoupiao = function()
    {
        var data = "action=showtoupiao&ismobiletype="+ismobiletype;//传递的答案集合
        var sid = 0;//答案编号
        var num = document.getElementsByName("voption").length;
        var voteid = document.getElementsByName("voteid")[0].value;
        var votetype = document.getElementsByName("votetype")[0].value;
        //获取答案集合
        for (var i = 0; i < num; i++) {
            var KS = document.getElementsByName("voption")[i];
            if (KS.checked == true) {//选中状态
                sid = KS.value;
            }
            data += "&sv" + i + "=" + sid;
            sid = 0;
        }
        data += "&num=" + num + "&voteid=" + voteid + "&votetype=" + votetype; 
        jQuery.ajax({
            type: "post",
            url: "/plus/course/CourseAjax.ashx",
            data: data,
            success: function (data) { 
                $("#voteBox").html("");
                if (ismobiletype == 1) {
                    $("#svoteBox").html("<div class='vote stopclick' ><div class='voteBox'><div class='votesuccess'><span class='vote-icon'></span><span class='vote-title'>投票成功</span></div>" + data + "</div></div>");
                }
                else {
                    $("#svoteBox").html("<div class='sv-con innercon'>" + data + "</div>");
                }

                $("#svoteBox").show();
                $("#propinfo").hide();
                $("#CurrpromotBox").hide();
                $("#voteBox").hide();
            }
        });
    }


    //关闭道具信息
    window.closetoupiao = function(type)
    {
        if (type == 6)//游戏
        {
            if (ismobiletype == 1) {
                $("#money").hide();
            } else {
                clearInterval(liuxingsetT);//清除流行的特效
            } 
            $("#hongbao").hide();//红包隐藏
            $("#hongbao").html("");
            $(".openRedBox").fadeOut()
            $(".redrainBox").css("opacity", "1");
            $(".redrainBox").removeClass("disabled");
        }


        pp = 1;
        deleteCookieProp("recordtims");//清除cookie
        pop = 1;

        document.getElementById('daojuinfo').style.display = 'none';//隐藏道具信息
        //恢复播放
        pm.play()
    }

    /***************切换下一题  问卷*****************/
    window.nextwenjuan = function(i,worknum)
    { 
        //切换样式时  判断是否选择答案了
        //全部隐藏   最后显示需要的信息
        for (var j = 1; j < worknum;j++)
        {
            document.getElementById('wenjuan'+j).style.display = 'none';//隐藏道具信息
        }
        i++; 
        document.getElementById('wenjuan' + i).style.display = 'block';//显示道具信息
    }
    /*****提交问卷保存答案信息*****/
    window.tjwenjuan = function(worknum,sjid)
    {
        var data = "action=addwenjuan&ismobiletype=" + ismobiletype;//传递的答案信息
        if (worknum > 0) {
            for (var i = 1; i <= worknum; i++) {//总题目数量
                if (document.getElementsByName("tmtype" + i)[0].value != 5) {/****单选或多选***/
                    var optionnum = document.getElementsByName("optionmum" + i)[0].value;//选项个数
                    var ans = null;//声明一个接受答案的变量
                    for (var j = 0; j < optionnum; j++)//获取选中的答案信息
                    {
                        var KS = document.getElementsByName("Satisfied" + i)[j];
                        if (KS.checked == true) {//选中状态   区分多种情况
                            if (ans == null) {
                                ans = KS.value;
                            } else { ans += "," + KS.value; }
                        }
                    }
                    data += "&num" + i + "=" + ans;//传递答案信息

                } else {//问答题
                    data += "&num" + i + "=" +document.getElementsByName("content" + i)[0].value;
                }
                data += "&tmtype" + i + "=" + document.getElementsByName("tmtype" + i)[0].value + "&tmid" + i + "=" + document.getElementsByName("tmid" + i)[0].value;
            }
        }
        data += "&sjid=" + sjid + "&worknum=" + worknum;
        
        jQuery.ajax({
            type: "post",
            url: "/plus/course/CourseAjax.ashx",
            data: data,
            success: function (data) {
                $("#questionBox").html(data);
                $('.innercon').each(function () {
                    //超出的滚动条
                    $(this).niceScroll({
                        cursorcolor: "rgba(0,0,0,0.1)",
                        cursoropacitymax: 1,
                        touchbehavior: false,
                        cursorwidth: "6px",
                        cursorborder: "0",
                        cursorborderradius: "5px"
                    });
                });
                $("#propinfo").hide();
                $("#voteBox").hide();
                $("#svoteBox").hide();
                $("#CurrpromotBox").hide();
                $("#examhomeBox").hide();
                $("#questionBox").show();
            }
        });
    }
    /****获取的奖励信息****/
    window.addgame = function(data)
    { 
        $("#zhuanpan").hide();
        $("#turnBox").hide();//游戏隐藏
        $("#turnBox").html("");//游戏隐藏
        if (data.indexOf("获取奖品")!= -1) {
            $("#successBox").html(data);//获奖 
            $("#successBox").show();//游戏显示
            $("#failBox").hide();//游戏显示
        } else {
            $("#failBox").html(data);//未获奖
            $("#failBox").show();//游戏显示
            $("#successBox").hide();//游戏显示
        }

        //抢答失败的右侧滚动列表（新加的）
        var time = setInterval('autoScroll("#a-coursetop")', 2000);
        $("#a-coursetop").hover(function () {
            clearInterval(time)
        }, function () {
            time = setInterval('autoScroll("#a-coursetop")', 2000);
        });
        
    }
    
    /********记录选项答案信息*******/
    window.addcheck = function(propid, proptype, propinfo, times, worknum, courseid, lessonid)
    { 
        var sid=0;
        for (var i = 0; i < document.getElementsByName("aoption").length; i++) {
            var KS = document.getElementsByName("aoption")[i];
            if (KS.checked == true) {
                sid = KS.value;//获取答案信息
            }
        }
        if (sid != 0) {
            var data = "courseid=" + courseid + "&periodid=" + lessonid + "&proptype=" + proptype + "&shijian=" + times + "&bindid=" + propinfo;
            jQuery.ajax({
                type: "post",
                url: "/plus/course/CourseAjax.ashx?action=addqd&propid=" + propid + "&sid=" + sid + "&ismobiletype=" + ismobiletype,
                data: data,
                success: function (data) {
                    $("#answerBox").html(data);
                    $("#answerBox").show();

                    $("#turnBox").hide();//大转盘游戏显示
                    $("#redrain").hide();//红包
                    $("#examhomeBox").hide();//考试 
                    $("#voteBox").hide();//答题
                    $("#svoteBox").hide();//答完题
                    $("#CurrpromotBox").hide();//商品
                    $("#propinfo").hide();//积分  公告
                    $("#questionBox").hide();//问卷
                }
            });
        } else
        {
            alert("请选择答案信息！");
            return false;
        }
    }

    window.autoScroll = function(obj) {
        var h = $("#a-coursetop li").height()
        $(obj).find("ul").animate({ marginTop: "-" + h + "px" }, 500, function () {
            $(this).css({ marginTop: "0px" }).find("li:first").appendTo(this);
        });
    };

})(getConfig());




///*************页面的样式信息*****************/

$(function () {
    //弹窗动画	
    $(".maskbg .prop").removeClass('opacity-0').addClass("animated zoomIn");
    $(".maskbg .redrainBox").removeClass('opacity-0').addClass("animated zoomIn");
     
    //考题选择
    $(".e-con a").hover(function () {
        $(this).addClass("curr").siblings().removeClass("curr");
    })

    //投票系统
    $(".voteBox .v-submit-btn").click(function () {
        $(".svoteBox").fadeIn();
        $(".voteBox").fadeOut();
    })
    $(".svoteBox .v-submit-btn").click(function () {
        $(".maskbg").fadeOut();
    })

    //重要通知
    $("#noticeBox").click(function () {
        $(".maskbg").fadeOut();
    });
    $(".noticeBox").click(function (event) {
        event.stopPropagation();
    });

    //问卷调查
    $(".q-finish-btn").click(function () {
        $(".maskbg").fadeOut();
    })
})
 
//弹窗动画
$(function () {
    $(".maskbg .prop").removeClass('opacity-0').addClass("animated zoomIn");
    $(".maskbg .redrainBox").removeClass('opacity-0').addClass("animated zoomIn");

})

//红包雨
$(function () {

    $(".shareBtn").click(function () {
        //$(this).parent().fadeOut();
        $(".maskbg").fadeOut()
        $(".openRedBox").fadeOut()
        $(".redrainBox").css("opacity", "1");
        $(".redrainBox").removeClass("disabled");
    })

})


var WINDOW_WIDTH = $(window).width();
var WINDOW_HEIGHT = $(window).height();
var canvas, context;
var num = 500;
var stars = [];
var mouseX = WINDOW_WIDTH / 2;
var mouseY = WINDOW_HEIGHT / 2;
var rnd;
var liuxingsetT;
function cavasLoad() {

    WINDOW_WIDTH = $(window).width();
    WINDOW_HEIGHT = $(window).height();
    mouseX = WINDOW_WIDTH / 2;
    mouseY = WINDOW_HEIGHT / 2;
    stars = [];
    rnd = 0;
    canvas = document.getElementById('canvas');
    if(canvas){
        canvas.width = WINDOW_WIDTH;
        canvas.height = WINDOW_HEIGHT;
        context = canvas.getContext('2d');

        addStar();
        liuxingsetT = setInterval(render, 33);
        liuxing();
    }

}

$(window).resize(function () {
    cavasLoad();
});

function liuxing() {
    var time = Math.round(Math.random() * 3000 + 33);
    setTimeout(function () {
        rnd = Math.ceil(Math.random() * stars.length)
        liuxing();
    }, time)
}


function render() {
    context.fillStyle = 'rgba(0,0,0,0.1)';
    context.fillRect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
    // context.clearRect(0,0,WINDOW_WIDTH,WINDOW_HEIGHT)
    for (var i = 0; i < num ; i++) {
        var star = stars[i];
        if (i == rnd) {
            star.vx = -20;
            star.vy = 20;
            context.beginPath();
            context.strokeStyle = 'rgba(255,255,255,' + star.alpha + ')';
            context.lineWidth = star.r;
            context.moveTo(star.x, star.y);
            context.lineTo(star.x + star.vx, star.y + star.vy);
            context.stroke();
            context.closePath();
        }
        star.alpha += star.ra;
        if (star.alpha <= 0) {
            star.alpha = 0;
            star.ra = -star.ra;
            star.vx = Math.random() * 0.2 - 0.1;
            star.vy = Math.random() * 0.2 - 0.1;
        } else if (star.alpha > 1) {
            star.alpha = 1;
            star.ra = -star.ra
        }
        star.x += star.vx;
        if (star.x >= WINDOW_WIDTH) {
            star.x = 0;
        } else if (star.x < 0) {
            star.x = WINDOW_WIDTH;
            star.vx = Math.random() * 0.2 - 0.1;
            star.vy = Math.random() * 0.2 - 0.1;
        }
        star.y += star.vy;
        if (star.y >= WINDOW_HEIGHT) {
            star.y = 0;
            star.vy = Math.random() * 0.2 - 0.1;
            star.vx = Math.random() * 0.2 - 0.1;
        } else if (star.y < 0) {
            star.y = WINDOW_HEIGHT;
        }
        context.beginPath();
        var bg = context.createRadialGradient(star.x, star.y, 0, star.x, star.y, star.r);
        bg.addColorStop(0, 'rgba(255,255,255,' + star.alpha + ')')
        bg.addColorStop(1, 'rgba(255,255,255,0)')
        context.fillStyle = bg;
        context.arc(star.x, star.y, star.r, 0, Math.PI * 2, true);
        context.fill();
        context.closePath();
    }
}

function addStar() {
    for (var i = 0; i < num ; i++) {
        var aStar = {
            x: Math.round(Math.random() * WINDOW_WIDTH),
            y: Math.round(Math.random() * WINDOW_HEIGHT),
            r: Math.random() * 2,
            ra: Math.random() * 0.05,
            alpha: Math.random(),
            vx: Math.random() * 0.2 - 0.1,
            vy: Math.random() * 0.2 - 0.1
        }
        stars.push(aStar);
    }
}
