(function($) {

    //主导航
    $.fn.mainMenuFun = function(Compart, Current) {
        var domainID = $.getURLParam(window.location.href, $.domain_id_key);
        var domainParam = "";
        if(domainID != null) {
            domainParam = "?domain_id=" + domainID;
        }
        if (document.URL == "http://" + document.location.host + "/" + domainParam) {
            this.prepend("<li class=" + Current + "><a href=\"/" + domainParam + "\">首页</a></li>");
            this.find("li").after("<li class=" + Compart + "></li>");
            this.find("li:last").remove();
        } else {
            this.prepend("<li><a href=\"/" + domainParam + "\">首页</a></li>");
            this.find("li").after("<li class=" + Compart + "></li>");
            this.find("li:last").remove();
        }
        this.find("li." + Current).prev().remove();
        this.find("li." + Current).next().remove();
    };

    //副导航
    $.fn.subMenuFun = function(Compart) {
        this.find("li").after("<li class=" + Compart + ">|</li>");
        $(this).find("li:last").remove();
    };

    //热点视频
    $.fn.hotVideosSkin = function(list, length, bIsAddTrail) {
        var ul = this.find("ul");
        var lis = this.find("li");
        lis.each(function(i) {
            if ($(this).find("a")[0].innerHTML.length > length) {
                $(this).children("a").subStrs(length, bIsAddTrail);
            }
            $(this).prepend("<img src=\"/media/image/listNum_" + (i + 1) + ".gif\" alt=\"\" class=\"left pad4px\" />");
            $(this).after($(this).clone().attr("rel", "moreinfo").css({ lineHeight: '18px', height: '75px' }).hide());
            $(this).next().after("<li class=\"crossLine1 w180px\"></li>");
            $(this).children("a").css("color", "#0090b9").mouseover(function() {
                ul.skinChange(this);
            });
            if (i == 0) {
                $(this).css("display", "none");
            }
        });
        ul.find("li[rel='moreinfo']").each(function(i) {
            $(this).find("img:first").addClass("top27px")
            var anchors = $(this).find("a:first");
            anchors.after(anchors.clone());
            $(this).append("<div class=\"left w120px h75px left5px top5px\"></div>");
            anchors.html("<img src=\"/media/thumbs/" + list.videos[i].file_name + "_80x60.jpg\" class=\"pic_80_60 top7px left\" />");
            anchors = $(this).find("a:last");
            $(this).find("div").append(anchors);
            anchors.after("<br /><span class=\"left cff9700\">\u7247\u957f\uff1a" + list.videos[i].duration + "</span><br />\
                <span class=\"left cff9700\">\u65e5\u671f\uff1a" + list.videos[i].date + "</span>");
            if (i == 0) {
                $(this).css("display", "block");
            }
        });
        ul.children("li:last").remove();
    };

     //最新视频
    $.fn.todayNewsSkin = function(list, containerID, arrWH, bAutoPlay, length, bIsAddTrail) {
        var lis = this.find("li");
        lis.each(function(i) {
            if ($(this).find("a")[0].innerHTML.length > length) {
                $(this).children("a").subStrs(length, bIsAddTrail);
            }
            $(this).append("<div class=\"left\"></div>")
            $(this).children("div").html($(this).children("a").text());
            $(this).children("div").append("<br /><span class=\"left\">\u7247\u957f\uff1a" + list.videos[i].duration + "</span><br /><span class=\"left\">\u65e5\u671f\uff1a" + list.videos[i].date + "</span><span style=\"display:none;\" class=\"right\"></span>");
            $(this).children("a").text("[ \u8be6\u7ec6 ]").appendTo($(this).find("span[class='right']"));
            $(this).children("div").before("<img src=\"/media/thumbs/" + list.videos[i].file_name + "_100x75.jpg\" class=\"pic_100_75 left\" />");
            $(this).addClass("hand").click(function() {
                $.videoPlay(list.videos, list.videos[i], containerID, arrWH, 1, length, bIsAddTrail);
            });
            $.videoPlay(list.videos, list.videos[0], containerID, arrWH, bAutoPlay, length, bIsAddTrail);
        });
    };

    //相关视频
    $.fn.relatingVideosSkin = function(list, containerID, arrWH, bAutoPlay, length, bIsAddTrail) {
        var lis = this.find("li");
        lis.each(function(i) {
            if ($(this).find("a")[0].innerHTML.length > length) {
                $(this).children("a").subStrs(length, bIsAddTrail);
            }
            $(this).append("<div class=\"left\"></div>")
            $(this).children("div").html($(this).children("a").text());
            $(this).children("div").append("<br /><span class=\"left\">\u7247\u957f\uff1a" + list.videos[i].duration + "</span><br /><span class=\"left\">\u65e5\u671f\uff1a" + list.videos[i].date + "</span><span style=\"display:none;\" class=\"right\"></span>");
            $(this).children("a").text("[ \u8be6\u7ec6 ]").appendTo($(this).find("span[class='right']"));
            $(this).children("div").before("<img src=\"/media/thumbs/" + list.videos[i].file_name + "_100x75.jpg\" class=\"pic_100_75 left\" />");
            $(this).addClass("hand").click(function() {
               // $.videoPlay2(list.videos, list.videos[i], containerID, arrWH, 1, length, bIsAddTrail);
            });
           // $.videoPlay2(list.videos, list.videos[0], containerID, arrWH, bAutoPlay, length, bIsAddTrail);


        $("#todayNews").find("li").each(function(i) {
            $(this).css({ 'border': 'none', 'cursor': 'pointer' });
            $(this).click(function() {
                $.videoPlay2(vObjs, vObjs[i], containerID, arrWH, 1, length, bIsAddTrail)
            });
            $(this).find("span[class='right']").css("display", "none");

        var urlstr = window.location.href;

        if (urlstr.search("videoshow/"+$(this).find("a").attr("rel")) != -1) {

                $(this).unbind("click");
                $(this).css({ 'border': '1px solid #fc8231', 'cursor': 'default' });
                $(this).find("span[class='right']").toggle();

        }


        });

        });
    };


    //推荐
    $.fn.RecommandVideosSkin = function(list, mainTitleLength, mainContentLength, length, bIsAddTrail) {
        var ul = this.find("ul");
        var lis = this.find("li");
        ul.before($(lis[0]).children("a").html("<img src=\"/media/thumbs/" + list.videos[0].file_name + "_250x188.jpg\" class=\"pic_250_188\" />"));
        $(lis[0]).remove();
        $(list.videos[0]).remove();
        ul.prev().append("<h1 class=\"tIndent20px\">" + list.videos[0].name + "</h1><p class=\"tIndent2em\">" + list.videos[0].descript + "</p>");
        if (this.find("h1")[0].innerHTML.length > mainTitleLength) {
            this.find("h1").subStrs(mainTitleLength, bIsAddTrail);
        }
        if (this.find("p")[0].innerHTML.length > mainContentLength) {
            this.find("p").subStrs(mainContentLength, bIsAddTrail);
        }
        ul.before("<div class=\"crossLine1 w250px pad4px\"></div>");
        lis.find("a").each(function() {

            if ($(this).text().length > length) {
                $(this).subStrs(length, bIsAddTrail);
            }
            $(this).parent().css({ 'float': 'left', 'width': '125px' });
            $(this).prepend("·");
        });
    };

    //最新
    $.fn.LatestVideosSkin = function(list, length, bIsAddTrail) {
        var lis = this.find("li");
        lis.each(function(i) {
            $(this).css("float", "left");
            if ($(this).children("a").text().length > length) {
                $(this).children("a").subStrs(length, bIsAddTrail);
            }
            $(this).children("a").html("<span>" + $(this).children("a").text() + "</span>")
            $(this).children("a").prepend("<img src=\"/media/thumbs/" + list.videos[i].file_name + "_128x96.jpg\" class=\"pic_128_96\" /><br />");
        });
    };

    //边栏
    $.fn.sideList = function(list, length, bIsAddTrail) {
        this.children("ul").addClass("left");
        var lis = this.find("li");
        lis.each(function(i) {
            $(this).css("float", "left");
            if ($(this).children("a").text().length > length) {
                $(this).children("a").subStrs(length, bIsAddTrail);
            }
            $(this).children("a").html("<span>" + $(this).children("a").text() + "</span>")
            $(this).children("a").prepend("<img src=\"/media/thumbs/" + list.videos[i].file_name + "_200x150.jpg\" class=\"pic_200_150\" /><br />");
        });
    };

    //播放
    $.videoPlay = function(vObjs, vObj, containerID, arrWH, bAutoPlay, length, bIsAddTrail) {
        var container = $(containerID);
        $.getScript("http://" + document.location.host + "/videoshow_remote/" + vObj.id + "/" + arrWH[0] + "/" + arrWH[1] + "/" + bAutoPlay + "/0/", function() {
            container.html(video_show_ctrl);
        });
        container.next().text(vObj.name);
        if (vObj.name.length > length) {
            container.next().subStrs(length, bIsAddTrail);
        }
        container.next().text(container.next().text() + " -\u4e0a\u4f20\u65f6\u95f4\uff1a  " + vObj.date);
        $("#todayNews").find("li").each(function(i) {
            $(this).css({ 'border': 'none', 'cursor': 'pointer' });
            $(this).click(function() {
                $.videoPlay(vObjs, vObjs[i], containerID, arrWH, 1, length, bIsAddTrail)
            });
            $(this).find("span[class='right']").css("display", "none");
            if ($(this).find("a").attr("rel") == vObj.id) {
                $(this).unbind("click");
                $(this).css({ 'border': '1px solid #fc8231', 'cursor': 'default' });
                $(this).find("span[class='right']").toggle();
            }
        });
    };


    //频道（一级）
    $.fn.channelVLists = function(vObjs, length, bIsAddTrail){
        var strExec = /\d{1,2}/;
        var thisId = strExec.exec(vObjs.id);
        var thisCon = $(this.children("ul:first").children("li")[thisId]);
        thisCon.addClass("block");
        thisCon.prepend("<div class=\"vList"+ thisId +" left w710px\" style=\"height:25px;padding:4px 0;\" ></div>");//频道
        thisCon.children("span").css({'color':'#84898d','font-size':'14px','font-weight':'bold'}).appendTo(".vList"+ thisId);
        thisCon.children("a").appendTo(".vList"+ thisId);
        thisCon.children("ul").children("li:first").find("a").insertAfter(".vList"+ thisId).wrap("<div class=\"vList"+ thisId +"f\"></div>");//第一个视频
        thisCon.children("ul").children("li:first").remove();
        thisCon.find(".vList"+ thisId).prepend("<img src=\"/media/image/box2_titlePoint.gif\" class=\"left pad4px\" />");
        var lineImg = $("<img src=\"/media/image/box2_titleLine3.gif\" class=\"left pad8px left10px\" />");
        thisCon.find(".vList"+ thisId).find("span").after(lineImg.width(610 - (thisCon.find(".vList"+ thisId).find("span").text().length)*15));
        thisCon.find(".vList"+ thisId).find("a").html("<img src=\"/media/image/more1.gif\" class=\"right\" />");
        thisCon.find(".vList"+ thisId +"f").addClass("left").width(270);
        thisCon.find("ul").addClass("left w435px");
        thisCon.find(".vList"+ thisId +"f").find("a").html("<h1 class=\"tIndent5px\">"+ vObjs.videos[0].name +"</h1><p class=\"tIndent5px\">"+ vObjs.videos[0].descript +"</p>")
        thisCon.find(".vList"+ thisId +"f").find("a").prepend("<img src=\"/media/thumbs/" + vObjs.videos[0].file_name + "_250x188.jpg\" class=\"pic_250_188\" />");
        vObjs.videos.shift();
        thisCon.find("li").each(function(i){
            if (vObjs.videos[i].name.length > length) {
                $(this).children("a").subStrs(length, bIsAddTrail);
            }
            $(this).children("a").prepend("<img src=\"/media/thumbs/" + vObjs.videos[i].file_name + "_128x96.jpg\" class=\"pic_128_96\" /><br />");
        }).addClass("tCenter left left7px");
    };

    //频道（二级）
    $.fn.channelRVList = function(vObjs, length, bIsAddTrail){
        this.addClass("w700px left")
        this.find("li").addClass("tCenter left").css({'margin':'5px 0 0 17px','display':'inline'});
        this.children("ul:first").find("a").each(function(i){
            if (vObjs.videos[i].name.length > length) {
                $(this).subStrs(length, bIsAddTrail);
            }
            $(this).prepend("<img src=\"/media/thumbs/" + vObjs.videos[i].file_name + "_150x112.jpg\" class=\"pic_150_112 top10px\" /><br />");
            if((i+1)%4 == 0 && (vObjs.videos.length < 12 || $("#ssubChannelList").find("dl").length > 0)){
                $(this).parent().after("<li class=\"crossLine1 left w700px top5px\"></li>");
            }
        });
    };

    //频道列表
    $.fn.channelList = function(Current){
        var flag = true;
        var currentChannel = $(".mainMenu").children(".liCurrent").children("a").attr("href");//当前父频道URL
        if(this.find("li[class=\""+ Current +"\"]").length > 0)
            flag = false;
        flag ? this.before("<div class=\""+ Current +"\"><a href=\"" + currentChannel + "\">\u5168\u90e8</a></div>"):this.before("<div><a href=\"" + currentChannel + "\">\u5168\u90e8</a></div>");
    };

    //搜索结果
    $.fn.searchResult = function(vObjs, mainContentLength, length, bIsAddTrail){
        this.find("li").find("a").each(function(i){
            if (vObjs.videos[i].name.length > length) {
                $(this).subStrs(length, bIsAddTrail);
            }
            $(this).after($(this).clone()).html("<img src=\"/media/thumbs/" + vObjs.videos[i].file_name + "_150x112.jpg\" class=\"pic_150_112 left\" />").next().wrap("<div class=\"left clearfix left5px w503px\"></div>").parent().after("<br style=\"clear:both;\" />");
            $(this).next().find("a:first").addClass("f14px cMaroon").after("<p><span class=\"fB c807f7f\">视频来源：</span></p>").after("<p><span class=\"fB c807f7f\">播放时长：</span></p>").after("<p><span class=\"fB c807f7f\">视频标签：</span></p>").after("<p><span></span></p>");
        });
        this.find("li").css({'padding-bottom':'10px'}).each(function(i){
            var text = $(this).find("span");
            for(j=0;j<text.length;j++)
                switch(j){
                    case 0:$(text[j]).after(vObjs.videos[i].descript);
                        break;
                    case 1:$(text[j]).after(vObjs.videos[i].tags);
                        break;
                    case 2:$(text[j]).after("<span class=\"cff9700\">" + vObjs.videos[i].duration + "</span>&nbsp;");
                        break;
                    case 3:$(text[j]).after(vObjs.videos[i].domain.name);
                        break;
                }
            if (vObjs.videos[i].descript.length > mainContentLength) {
                $(this).find("p:first").subStrs(mainContentLength, bIsAddTrail);
            }
            $(this).find("p:first").prepend("<span class=\"fB c807f7f\">视频介绍：</span>");
            $(this).after("<li class=\"crossLine1 left w680px top5px\" style=\"padding-bottom:10px\"></li>");
        });
    };



    //系列视频
    $.fn.relatingVideosSkin = function(list, containerID, arrWH, bAutoPlay, length, bIsAddTrail) {
        var lis = this.find("li");
        lis.each(function(i) {
            if ($(this).find("a")[0].innerHTML.length > length) {
                $(this).children("a").subStrs(length, bIsAddTrail);
            }
            $(this).append("<div class=\"left\"></div>")
            $(this).children("div").html($(this).children("a").text());
            $(this).children("div").append("<br /><span class=\"left\">\u7247\u957f\uff1a" + list.videos[i].duration + "</span><br /><span class=\"left\">\u65e5\u671f\uff1a" + list.videos[i].date + "</span><span style=\"display:none;\" class=\"right\"></span>");
            $(this).children("a").appendTo($(this).find("span[class='right']")).html("<span style='float:right; margin-right:10px; display:inline;'><img src='/media/image/videoshow_playicon.gif' /></span>");
            $(this).find("a").removeAttr("href");
            $(this).find("a").removeAttr("target");
            $(this).children("div").before("<img src=\"/media/thumbs/" + list.videos[i].file_name + "_100x75.jpg\" class=\"pic_100_75 left\" />");
            $(this).addClass("hand").click(function() {
            });



            $("#relatingVideos").find("li").each(function(i) {
                $(this).css({ 'border': 'none', 'cursor': 'pointer' });
                $(this).click(function() {
                    window.location.href='/videoshow/'+list.videos[i].id;
                });
                $(this).find("span[class='right']").css("display", "none");

                var urlstr = window.location.href;

                if (urlstr.search("videoshow/"+$(this).find("a").attr("rel")) != -1) {

                    if(336 < (i+1)*78){
                        var vid =  document.getElementById("relatingVideos");
                        vid.scrollTop = (i+1)*65;
                    }

                    $(this).unbind("click");
                    $(this).css({ 'border': '1px solid #fc8231', 'cursor': 'default','background-color':'#F2F2F2' });
                    $(this).find("span[class='right']").toggle();

                }

            });

        });

        $("#videoextern").find("span").css({ 'font-weight': 'bold','width': 65,'float': 'left','text-align':'right'});
        $("#videoextern").find("li").each(function(i){
            switch(i){
                case 0: ;
                    break;
                case 1: ;
                    break;
                case 2:   $(this).html($(this).find("a").text("点击查看来源页"));
                          $(this).find("a").before("   [").after("]");
                          $(this).prev().append($(this).html());
                          $(this).remove();
                    break;
                default: break;
            }
        });
    };








})(jQuery);