$(document).ready(function() {
    $("#pc-menu>div").mouseenter(function(event) {
        /* Act on the event */
        var top = $(this).position().top;
        var left = $(this).position().left;
        var w=$(this).width();
        var h=$(this).height();
        $(this).find('ul').css({
            top:top+h,
            left: left+w
        });
    });


    $(".show-mobile-menu").click(function(){
        var h=$(this).parent().height();
        if($(this).hasClass('open-menu')){
            $(this).removeClass("open-menu");

            $(this).find('i').addClass('fa fa-bars').removeClass("fa-times-circle");
            $("#mobile-menu").addClass("d-none");
        }else{
            $(this).addClass('open-menu');
            $(this).find('i').removeClass('fa fa-bars').addClass("fa fa-times-circle");
            $("#mobile-menu").removeClass("d-none");
            $("#mobile-menu").css({
                top: h,
                property2: 'value2',
                height:$("body").height()
            });
        }

    });

    choudi();
    $(".choudi .imgbox").click(function(event) {
        /* Act on the event */
        var w = $(this).parent().width();
        var n = $(".choudi .imgbox").length - 1;
        var lose = n * 45;

        $(this).siblings().animate({
            width: "45px"
        })
        $(this).animate({
            width: w - lose + "px",
        })
    });

    //遮罩
    $("#zhezhao .item").mouseenter(function(event) {
        event.preventDefault();
        $(this).css('position', 'relative');
        var title = $(this).data('title');
        var logo= $(this).data('logo');
        var user = $(this).data('user');
        var area = $(this).data('area');
        var link = $(this).data('link');
        var w = $(this).find('img').width();
        var h = $(this).find('img').height();
        var left = $(this).find('img').position().left;

        zhe = $("<div class='zhe'></div>");
        zhe_logo=$("<div class='zhe_logo'></div>");
        zhe_title = $("<div class='zhe_title'></div>");
        zhe.css({
            position: 'absolute',
            top: '0',
            left: left,
            width: w,
            height: h,
            background: 'rgba(0,0,255,.3)',
            "animation": "fadeIn",
            "animation-duration": "1s"
        });


        zhe_logo.css({
            position: 'absolute',
            width: w,
            "font-size": "2em",
            "text-align": "center",
            top: '30px',
            left: left,
            color: 'white',
            "animation": "fadeInBottomLeft",
            "animation-duration": "1s"

        });


        zhe_title.css({
            position: 'absolute',
            width: w,
            "font-size": "2em",
            "text-align": "center",
            bottom: '30px',
            left: left,
            color: 'white',
            "animation": "fadeInBottomLeft",
            "animation-duration": "1s"

        });


        zhe_logo.html("<img src=\""+logo+"\" width=\"98%\" >");
        zhe_title.html(title+'<br>'+'<br><span>'+area+'</span>');
        zhe_title.find('span').css('font-size', '24px');


        $(this).append(zhe);
        $(this).append(zhe_logo);
        $(this).append(zhe_title);
    });
    $("#zhezhao").on('mouseleave', '.item', function(event) {
        event.preventDefault();

        $(this).find('.zhe,.zhe_logo,.zhe_title').animate({ "height": "0" }, 300, function() {
            $(this).remove();
        });


    });


    $(".list-img ul").width($(".list-img li").outerWidth() * 16);
    $(".list-img li").click(function() {
        index = $(this).index();
        showImg(index);
    });

    var xmoveTimer=setInterval("xmove()",3000);

    $("#xmove").mouseenter(function(){
        clearInterval(xmoveTimer);
    });
    $("#xmove").mouseleave(function(){
        xmoveTimer=setInterval("xmove()",3000);
    });

    //尺寸变化
    $(window).resize(function() {
        choudi();
        xmove();
    });
    //通用链接事件
    $("body").on("click",".ajaxurl", function () {
        var url=$(this).attr('href');
        var data=$(this).data("params");
        $.ajax({
            type: "get",
            url: url,
            data: data,
            dataType: "json",
            success: function (response) {
                alert(response.msg);
                window.location.href=response.url;
            }
        });
        return false;
    });
});

//抽屉
function choudi() {
    bw = 45; //边框宽度
    pw = $(".choudi").width(); //容器宽度
    n = $(".choudi .imgbox").length - 1;
    lose = n * 45;
    $(".choudi").find('img').width(pw - lose);
    $(".choudi .imgbox").width(bw);
    $(".choudi .imgbox").last().width(pw - lose);
}

function showImg(index) {
    rollW = $(".list-img li").first().outerWidth();
    console.log(rollW);

    $(".list-img ul").animate({ "left": -rollW }, 1000,function(){
        $(".list-img li").first().appendTo('.list-img ul');
        $(".list-img ul").css({"left":0});
    });
}
function xmove(){
    xw=$("#xmove>div").first().outerWidth();
    $("#xmove>div:first").animate({"margin-left":-xw},800,function(){
        $(this).appendTo("#xmove").css({"margin-left":0});
    });
}


function vdouterdivfn(thisVideo){
//点击video出现弹出层
            var oVideo = thisVideo;
            var vdsrc = oVideo.getAttribute("src");
            var postersrc = oVideo.getAttribute("poster");
            var ovdinnerdiv = document.getElementById('vdinnerdiv');
            var ovideo = ovdinnerdiv.children[1]; 
            ovideo.setAttribute('src', vdsrc);
            //ovideo.setAttribute('poster', postersrc);
            var windowW = $(window).width();//获取当前窗口宽度  
            var windowH = $(window).height();//获取当前窗口高度
            var t = 0.1*windowH;
            var r = 0.1*windowW;
            var h = 0.8*windowH;
            var w = 0.8*windowW;
            $(vdinnerdiv).css({"top":t, "right":r,"width":w,"height":h});
            $(vdouterdiv).fadeIn("fast");  
            ovideo.play();
}; 

function vdclosefn(ovdclose){
//点击x暂停且淡出消失弹出层
            var thisclose = ovdclose;
            var ovdinnerdiv = thisclose.parentNode;
            var ovideo = ovdinnerdiv.children[1];
            ovideo.pause();
            $(vdouterdiv).fadeOut("fast");  
}
//阅读四个文档
function readword(id,jump){
    $.ajax({
        type: "get",
        url: "/index/api/readword.html",
        data: {id:id},
        dataType: "json",
        success: function (response) {
            if(jump==1){
                console.log(response);
                window.location.href=response.url;
            }
        },
        error : function(e){
            console.log(e.status);
            console.log(e.responseText);
            window.location.href='/index/register.html';
        }
        
    });
}