(function(){

    /**
     * 初始化页面容器大小
     */
    $(window).resize(function () {
        $('.tabSrcollBox').height($(window).height()-61);
        $('#a1').height($(window).height()-60);
        $('.discuss_list2').height($(window).height()-60-187);
    }).resize();


    /**
     * 美化进度条
     */
    $('.tabSrcollBox').each(function(){
        $(this).niceScroll({
            cursorcolor: "#2e3134",
            cursoropacitymax: 1,
            touchbehavior: false,
            cursorwidth: "6px",
            cursorborder: "0",
            cursorborderradius: "30px"
         });
    
    });

    $('.discuss_list2').niceScroll({
        cursorcolor: "#2e3134",
        cursoropacitymax: 1,
        touchbehavior: false,
        cursorwidth: "6px",
        cursorborder: "0",
        cursorborderradius: "30px"
    });

    /**
     * 获取配置信息
     */
    var config = getConfig();
    var courseid = config.courseid;
    var PeriodID = config.PeriodID;
    var templateDir = config.templateDir;

    /**
     * 获取聊天记录
     */
    showplaychat(courseid, PeriodID,0,1,1)

    /**
     * 点赞动画
     */
    $("#chatlists").on('click','.ani',function(){
        if($(this).parent().attr('class')!='zan-hover'){
            $(this).attr('data-time',0);
            var $that = $(this);
            zanAnimate($that);
        }else{
            $(this).attr('class','ani ani_1')
        };
    });

    function zanAnimate(that){
        setTimeout(function(){
            var time = that.attr('data-time');
            time++;
            that.attr('data-time',time)
            that.attr('class','ani ani_'+time)
            if(time<21){
                zanAnimate(that);
            }
        },26)    
    };  

    /**
     * 回复记录执行完成函数 
     */
    window.showplaychatFun = function(){
        $('.imgAuto').each(function() {
            var $thisImg = $(this).find('img');
            var thisHeight = $(this).height();
            var imgHeight = $thisImg.height();
            var thisWidth  = $(this).width();
            if(imgHeight>thisHeight){
                var result = (imgHeight - thisHeight)/2;
                $thisImg.css({marginTop:'-'+result+'px'});
            }else{              
                $thisImg.css({width:'auto',height:thisHeight});
                var imgWidth = $thisImg.width();
                var result = (imgWidth - thisWidth)/2;
                $thisImg.css({marginLeft:'-'+result+'px'});
            };
        });

        //获取赞
        getzan("",599,"list");

    };

    /**
     * 分享笔记
     */
    $('#shareBjClick').click(function(){
        $(this).toggleClass('checked-bt');
    });

    /**
     * 保存笔记
     */
    window.savebj1 = function (schooluserid,id) {
        var Intro = $("#TxtIntro").val();
        var share = $('#shareBjClick').hasClass('checked-bt') ? 1 : 0; // 0不分享  1 分享
        $.ajax({
            url: "/index.aspx?c=course&a=play&action=savebj&schooluserid=" + schooluserid +"&courseid="+courseid+"&share="+share+"&pid=" + id + "&rnd=" + Math.random()+"&Intro=" + escape(Intro), success: function (d) {
                $("#notes_ulist").html(d);      
            }
        });
    } 

    /**
     * 切换我的笔记、他人笔记选项卡
     * 异步获取笔记列表
     */
    $('#noticelist').on('click','li',function(){
        $(this).addClass('curr').siblings().removeClass('curr');
        var index = $(this).index();
        $('.note-tab-box').find('.note-box').eq(index).show().siblings().hide(); 

        /**
         * 获取他人笔记
         */
        if (index==1)
        {
            $.ajax({
                url: "/index.aspx?c=course&a=play&action=noticother&courseid="+courseid+"&pid=" + PeriodID + "&rnd=" + Math.random(), success: function (d) {
                    d != '' ? $("#notes_otherlist").html(d) : $("#notes_otherlist").html('<div class="no-note"></div>');      
                }
            })
        }
    });


    /**
     * 隐藏页面侧栏
     */
    $(".hide_btn").click(function(){
        var rightWidth = $('.right_bigbox').outerWidth();
        if($(this).attr('data-flag')==0){
            $(this).attr('data-flag',1);
            $(this).find('img').attr('src',templateDir+'/images/play/hideicon.png');
            $('.right_bigbox').animate({right:'-'+rightWidth},300);
            $('.live_centerbox').css({marginRight:'0px'});
        }else{
            $(this).attr('data-flag',0);
            $(this).find('img').attr('src',templateDir+'/images/play/showicon.png');
            $('.right_bigbox').animate({right:0},300);
            $('.live_centerbox').css({marginRight:rightWidth+'px'});
        };

    });
    
    /**
     * 切换目录\讨论\资料\笔记选项卡
     */
    $('.live_rightbox').on('click','.tab_name li',function(){
        $(this).addClass('curr').siblings().removeClass('curr');
        $('.tab_con >.tabbox:eq('+$(this).index()+')').show().siblings().hide();    
    });
   
    /**
     * 学员切换
     */
    $(function(){

        var i = 1
        var num = $(".studentlist li").length
        num = Math.ceil(num/8)
    
        //每次切换数值                            
        $(".next").click(function(){
            i++
            if(i>=num) i=num 
            var h = $(".studentlist").height() * i - 400
        
            $(".block02 .student").animate({top:-h},400);
            $(".prve").removeClass("cur")
            if(i==num){
                $(".next").addClass("cur")
            }
        })
        $(".prve").click(function(){
            i--
            if(i<=1) i=1
            var h = $(".studentlist").height() * i - 400
            $(".block02 .student").animate({top:h},400);
            $(".next").removeClass("cur")
            if(i==1){
                $(".prve").addClass("cur")
            }
        })
        
    });
    

    /**
     * 图片放大
     */
    $('#chatlists').on('click','.imgbox img',function(){
        imagesZoomIn(this.src)
    });


    /**
     * 礼物展开收缩
     */
    $('.gifem-btn').click(function(){
        var $gife = $('.gife');
        if($(this).attr('data-flag')==0){
            $(this).attr('data-flag',1);
            $(this).html('<i class="ihide"></i>');
            $gife.addClass('gife-show').animate({bottom:'0px'},300);
        }else{
            $(this).attr('data-flag',0);
            $(this).html('<i class="ishow"></i>');
            $gife.removeClass('gife-show').animate({bottom:'-'+$gife.height()},300);
        };
    }); 

    $(window).load(function(){
        $('#loading').remove()
    })

})();
