$(function () {

    //删除视频
    $("a[rel='del']").click(function () {
        var $delObject = $(this);
        if (confirm("确定要删除 [ " + $delObject.attr("title") + " ] 吗？")) {
            $.ajax({
                type: "POST",
                url: "Ajax/Video.ashx",
                data: { 'com': 'delvideo', 'videoid': $delObject.attr("href"), 'videotitle': $delObject.attr("title"), 'videofile': $delObject.attr("rev") },
                datatype: "json",
                beforeSend: function (data, textStatus) {
                    showMsg("[ " + $delObject.attr("title") + " ] 正在删除中 ", true);
                },
                success: function (data, textStatus) {
                    if (data == "1") {
                        $delObject.parent().parent("tr").remove();
                    } else {
                        alert("删除失败!");
                    }
                    showMsg("", false);
                },
                error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
            })
        }
        return false;
    });

    //操作属性
    $("a[rel='attribute']").click(function () {
        var $Object = $(this);
        var nowID = $Object.attr("name");
        var numberID = $Object.attr("href");
        $.ajax({
            type: "POST",
            url: "Ajax/Video.ashx",
            data: { 'com': 'attribute', 'videoid': $Object.attr("rev"), 'number': numberID, 'now': nowID, 'log': $Object.text() + "《" + $Object.attr("title") + "》" },
            datatype: "json",
            beforeSend: function (data, textStatus) {
                showMsg("[ " + $Object.attr("title") + " ] 正在改变属性中 ", true);
            },
            success: function (data, textStatus) {
                if (data == "1") {
                    var retText = "";
                    switch (numberID) {
                        case "1":
                            retText = "头条";
                            break;
                        case "2":
                            retText = "推荐";
                            break;
                        case "3":
                            retText = "置顶";
                            break;
                    }

                    if (nowID == "0") {
                        $Object.attr("name", "1");
                        $Object.text("取消" + retText);
                        $Object.attr("class", "Q underline");

                    } else {
                        $Object.attr("name", "0");
                        $Object.text(retText);
                        $Object.attr("class", "F underline");
                    }
                } else {
                    alert("操作失败!");
                }
                showMsg("", false);
            },
            error: function (e) { alert("连接失败,请向Eoyoo官方技术人员反馈!"); }
        })

        return false;
    });

    //播放器层
    $("a[rel='playvideo']").click(function () {
        $object = $(this);
        

        var showHtml = "";
        showHtml += "<div class=\"title\">视频播放</div>";
        showHtml += "<p>";
        showHtml += "<div style=\"height:280px;\" id=\"videoPlayBox\"></div>";
        showHtml += "</p>";
        $("#ouBox .video").html(showHtml);

        //播放器赋值
        $f("videoPlayBox", "/Plugin/flowplayer/flowplayer-3.2.14.swf", {
            clip: {
                url: $object.attr("href"),
                autoPlay: true,
                autoBuffering: true
            }
        });

        if ($("#ouBox").is(":hidden")) $("#ouBox").slideToggle(60);
        return false;
    });

    //关闭层停止播放
    $("#ouBox a[class='close']").click(function () {
        $f("videoPlayBox").stop();
    })
});