function setProgress(percent) {
    $('input[type="range"]').val(percent).change();
}

function doAction(func) {
    if (func.indexOf("video") != -1) {
        if (func.indexOf("start") != -1) {
            $("#video_btn_start").addClass("hidden");
            $("#video_btn_stop").removeClass("hidden");
            if ($("#full_video_btn_start").length > 0) {
                $("#full_video_btn_start").addClass("hidden");
                $("#full_video_btn_stop").removeClass("hidden");
            }
        }
        if (func.indexOf("stop") != -1) {
            $("#video_btn_start").removeClass("hidden");
            $("#video_btn_stop").addClass("hidden");
            if ($("#full_video_btn_start").length > 0) {
                $("#full_video_btn_stop").addClass("hidden");
                $("#full_video_btn_start").removeClass("hidden");
            }
        }
        callFunc(func, '');
    } else {
        callFunc(func, '');
    }

}

function setVideoPos() {

    var pos = $("#video_pos").val();
    if ($("#full_video_pos").length > 0) {
        pos = $("#full_video_pos").val();
    }


    if (/^(\+|-)?\d+($|\.\d+$)/.test(pos)) {
        slider_current_value = pos;
        callFunc("video_pos", pos);
    }

}

function queryVideoList(videoIds) {
    if (videoIds != null) {
        s1 = $.checkTask.start_time.replace(/-/g, "/");
        var startTime = new Date(s1).getTime() / 1000;
        s1 = $.checkTask.end_time.replace(/-/g, "/");
        var endTime = new Date(s1).getTime() / 1000;

        VideoGetByIds(videoIds, function(data) {
            if (data != null && typeof(data) != "undefined") {
                var pp = {
                    "videoIds": videoIds,
                    "cindex": 10,
                    starttime: startTime,
                    "endtime": endTime,
                    "videos": []
                };

                data.forEach(came => {

                    pp.videos.push({
                        "videoId": came.id,
                        "cametype": came.cameratype,
                        "filetype": came.playtype
                    });

                });
                var pp = {
                    "videoIds": videoIds,
                    "cindex": 1,
                    starttime: startTime,
                    "endtime": endTime,
                    "videos": [{
                        "videoId": curVideo,
                        "cametype": data.cameratype,
                        "filetype": data.playtype
                    }]
                };
                callFunc("findvideolist", JSON.stringify(pp));
            }
        }, function(error) {});
    }

}


function queryVideoList() {

    var videos = $.checkTask.video_id.split(',');

    if (curVideo) {
        s1 = $.checkTask.start_time.replace(/-/g, "/");
        var startTime = new Date(s1).getTime() / 1000;
        s1 = $.checkTask.end_time.replace(/-/g, "/");
        var endTime = new Date(s1).getTime() / 1000;
        //获取当前的index
        var index = 0;

        for (var i = 0; i < videos.length; i++) {

            if (parseInt(videos[i]) == parseInt(curVideo)) {
                index = i;
                break;
            }
        }

        //获取摄像头信息
        VideoGetById(curVideo, function(data) {
            if (data != null && typeof(data) != "undefined") {
                var str = curVideo + '|' + startTime + '|' + endTime + '|' + data.cameratype + '|' + data.playtype + '|' + index;


                var pp = {
                    "videoIds": curVideo,
                    "cindex": 10,
                    starttime: startTime,
                    "endtime": endTime,
                    "videos": [{
                        "videoId": curVideo,
                        "cametype": data.cameratype,
                        "filetype": data.playtype
                    }]
                };
                callFunc("findvideolist", JSON.stringify(pp));
            }
        }, function(error) {

        });

        // alert(curVideo);

    } else {

    }
}

function playVideo(id) {
    callFunc("playvideo", id);
}
var maxVV;

function setProcessValue(maxValue) {
    //alert(maxValue);
    // console.log(max);
    maxVV = maxValue;
    $("#ex1").slider({ step: 5, min: 0, max: maxValue });
    if ($("#full_ex1").length > 0) {
        $("#full_ex1").slider({ step: 5, min: 0, max: maxValue });
    }
}

var slider_current_value = 0;

function setCurrentProcessValue(value) {
    // alert("ddd"+value);
    // console.log(value);

    var vv = maxVV * (value / 100)
    slider_current_value = parseInt(vv);
    $("#ex1").slider('setValue', parseInt(vv));
    if ($("#full_ex1").length > 0) {
        $("#full_ex1").slider('setValue', parseInt(vv));
    }
}

function setVideoProcess(value) {



    // console.log(value);
    var vv = value * 100 / maxVV;
    if (!isNaN(vv) && parseInt(vv).toString() != "NaN") {
        callFunc("setcurrenplayttime", parseInt(vv));
    } else {

    }

}

function callFunc(func, param) {
    var event = document.createEvent('MessageEvent');
    var origin = window.location.protocol + '//' + window.location.host;
    event.initMessageEvent(func, true, true, param, origin, 1234, window, null);
    document.dispatchEvent(event);
}

function playNext(index) {
    $("#video_list").val(index);
}