//var usjslibver = ".min.js?v=2.1.0";
var usjslibver = ".js?v=2.5.3";
document.writeln("<script language='javascript' src='/assets2/us/js/modules/usbasic" + usjslibver + "'></script>");
document.writeln("<script language='javascript' src='/assets2/us/js/modules/usalert" + usjslibver + "'></script>");
document.writeln("<script language='javascript' src='/assets2/us/js/modules/usopen" + usjslibver + "'></script>");
document.writeln("<script language='javascript' src='/assets2/us/js/modules/ussave" + usjslibver + "'></script>");
document.writeln("<script language='javascript' src='/assets2/us/js/modules/ushttp" + usjslibver + "'></script>");

function usinit() {
    //时间函数
    $(".usdatatime,span.usdatatimeno").each(function () {
        var options = {};
        var _this = $(this);
        var uscallback = _this.attr("uscallback");
        var dateRange = _this.attr("daterange");//区间选择，1 是
        var btns = _this.attr("btns");//指定按钮
        options["elem"] = this; //指定元素;
        if (dateRange == "1") {
            options["range"] = true;
        }
        else {
            options["range"] = dateRange;
            if (dateRange == "至") {
                var addDay = function (dayNumber, date) {
                    date = date ? date : new Date();
                    var ms = dayNumber * (1000 * 60 * 60 * 24)
                    var newDate = new Date(date.getTime() + ms);
                    return newDate;
                }

                console.debug(dateRange);

                options["extrabtns"] = [
                    { id: 'today', text: '今天', range: [new Date(), new Date()] },
                    { id: 'yesterday', text: '昨天', range: [addDay(-1, new Date()), addDay(-1, new Date())] },
                    { id: 'beforeyesterday', text: '最近7日', range: [addDay(-7, new Date()), new Date()] },
                    { id: 'day30', text: '最近30日', range: [addDay(-30, new Date()), new Date()] },
                    { id: 'day90', text: '近90日', range: [addDay(-90, new Date()), new Date()] },
                    { id: 'day180', text: '近180日', range: [addDay(-90, new Date()), new Date()] },
                    { id: 'day365', text: '近1年', range: [addDay(-365, new Date()), new Date()] }
                ];

            }

        }
        //不让选择清空
        options["btns"] = ['confirm'];

        if (btns != undefined) {
            console.debug(btns);
            btns = eval(btns)
            options["btns"] = btns
        }
        options["done"] = function (value, date, endDate) {
            if (uscallback != null) {
                //value = value.replace(" ", "");
                //value = value.replace(" ", "");
                _this.html(value);
                value = value.replace(" ", "");
                //console.debug(_this)
                var cb = uscallback + "('" + value + "')";
                //console.debug(cb);
                eval(cb);
            }
        };
        laydate.render(options);
    });
}


$(function () {
    usinit();
});

function usgetchartoption() {
    var options = {
        chart: {
            type: 'spline', zoomType: 'x'
        },
        title: {
            text: '得分折线图分析'
        },
        subtitle: {

        },

        yAxis: {
            title: {
                text: '得分'
            },
            labels: {
                formatter: function () {
                    return this.value + '';
                }
            }
        },
        tooltip: {
            crosshairs: true,
            shared: true
        },
        plotOptions: {
            spline: {
                marker: {
                    radius: 4,
                    lineColor: '#666666',
                    lineWidth: 1
                }
            }
        },
        xAxis: { categories: [] },
        series: []
    }
    return options;
}


//videoelement
var _videoelement = "#videoelement";
var _videow = ""; var _videoh = "";
function fullstate(v,chart) {
    var id = $(v).attr("usid");
    console.debug($(v))
    console.debug(chart)
    var usidadd = $(v).attr("usidadd");
    if (id != undefined) {
        var cstate = $(v).attr("cstate");
        var nstate = "";
        var ntext = "";
        if (cstate == "1") {
            //已经全屏
            nstate = "0";
            ntext = "<i class='us-icon'>&#xe62c;<i>";
            delFull(id);
            if (id == "usvideobody") {
                $(_videoelement).attr("width", _videow);
                $(_videoelement).attr("height", _videoh);
            }
        }
        else {
            //没有全屏,点击后，显示全屏，按钮显示退出全屏
            nstate = "1";
            ntext = "<i class='us-icon'>&#xe627;<i>";
            showFull(id);
            if (id == "usvideobody") {
                _videow = $(_videoelement).attr("width");
                _videoh = $(_videoelement).attr("height");
                $(_videoelement).attr("width", "100%");
                $(_videoelement).attr("height", "100%");
            }


        }

        //附加控制
        console.debug(usidadd)
        if (usidadd != undefined) {
            var z = usidadd.split(";")
            if (z.length == 2) {
                //已经全屏
                if (cstate == "1") {
                    $(z[0]).removeClass(z[1]);
                }
                else {
                    $(z[0]).addClass(z[1]);
                }
            }
        }
        $(v).attr("cstate", nstate);
        $(v).html(ntext);

        var select = "#" + id +" .usnboxbody"
        var w = $(select).width();
        var h = $(select).height();
        console.debug(w);
        console.debug(h);
        chart.setSize(w, h, false);
        //chart.reflow();
    }

}

function showFull(id) {
    var full = document.getElementById(id);
    //launchIntoFullscreen(full);
    $("#" + id).addClass("usrtmboxfullbody")
    $("#" + id + " .usrtmbox").addClass("usrtmboxfull");
    $("body").addClass("usrtmbodynoverflow");
}

function delFull(id) {
    $("#" + id).removeClass("usrtmboxfullbody")
    $("#" + id + " .usrtmbox").removeClass("usrtmboxfull");
    $("body").removeClass("usrtmbodynoverflow");
    //exitFullscreen();
}
function launchIntoFullscreen(element) {
    if (element.requestFullscreen) {
        element.requestFullscreen();
    }
    else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    }
    else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen();
    }
    else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    }
}
function exitFullscreen() {
    if (document.exitFullscreen) {
        document.exitFullscreen();
    } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
    }
}