window.onload;
$(window).resize(wah);

function wah() {

}

layui.use(['layer', 'form', 'element'], function(){
    var layer = layui.layer,form = layui.form,element = layui.element;
});

$(window).scroll(function(event) {
    // if ($(window).scrollTop() > 0) {
    //     $('.head-box').addClass('active');
    // } else {
    //     $('.head-box').removeClass('active');
    // }
    if ($(window).scrollTop() > 400) {
        $('.gotop').fadeIn();
    } else {
        $('.gotop').fadeOut();
    }
})

$(window).on("load", function() {
    setTimeout(function() {
        $('.loading').fadeOut();
    }, 4000)
})

$(function() {

    $('.nav_btn').click(function() {
        if ($('.nav_btn').attr('class') == 'nav_btn cur') {
            $('.nav_btn').removeClass('cur');
            $('.nav').removeClass('active');
            $('body').css('overflow', 'inherit');
        } else {
            $('.nav_btn').addClass('cur');
            $('.nav').addClass('active');
            $('body').css('overflow', 'hidden');
        }
    });
    
    $('.home-box1 .center-block li').hover(function(){
        if($(this).attr('class') != 'active'){
            $('.home-box1 .center-block li').removeClass('active').eq($(this).index()).addClass('active')
        }
    })
    
    $('.about-box2 .top-box .fr span').removeClass('active').eq(0).addClass('active')
    $('.about-box2 .lower-box').hide().eq(0).show();
    $('.about-box2 .top-box .fr span').click(function(){
        if($(this).attr('class') != 'active'){
            $('.about-box2 .top-box .fr span').removeClass('active').eq($(this).index()).addClass('active')
            $('.about-box2 .lower-box').hide().eq($(this).index()).show();
        }
    })
    $('.about-box2 .lower-box').each(function(){
        var that = $(this)
        that.find('.pull-right ul li').removeClass('active').eq(0).addClass('active')
        that.find('.pull-left ul li').hide().eq(0).show();
        that.find('.pull-right ul li').click(function(){
            if($(this).attr('class') != 'active'){
                that.find('.pull-right ul li').removeClass('active').eq($(this).index()).addClass('active')
                that.find('.pull-left ul li').hide().eq($(this).index()).show();
            }
        })
    })
    
    $('.marketing-box2 .center-block ul li').each(function(){
        var that = $(this)
        that.find('.top-box').click(function(){
            if(that.attr('class') != 'active'){
                that.addClass('active')
                that.find('.top-box .pull-right').text('收起')
                that.find('.lower-box').stop(true,false).slideDown()
            }else{
                that.removeClass('active')
                that.find('.top-box .pull-right').text('展开')
                that.find('.lower-box').stop(true,false).slideUp()
            }
        })
    })
    
    $('.about-box5 .video-box').click(function(){
        $(this).find('i').fadeOut()
        $(this).find('video').get(0).play()
    })


    $('.ewm_tc').click(function() {
        $(this).fadeOut();
    })

    if ($(window).width() <= 768) {
        $('.home-box1 .center-block li').addClass('active')
    } else {

    }


    $(".gotop").click(function() {
        var anh = $("body").offset().top;
        $("html,body").stop().animate({
            scrollTop: anh
        }, 1000);
        scrollAnh = 0;
        scrollNum = 0;
    });

    // 留言提交
    $('#message-submit').click(function () {
        var companyName = $("#message-form input[name='company_name']").val();
        var name = $("#message-form input[name='name']").val();
        var phone = $("#message-form input[name='phone']").val();
        var email = $("#message-form input[name='email']").val();
        var content = $("#message-form textarea[name='content']").val();
        var url = $("#message-form").data('action');
        var token = $('#token').attr('content');
        if(companyName.length == 0 && name.length == 0) {
            layer.msg('公司名称和联系人署名至少需要填写一个');
            return;
        }
        if(companyName.length > 0 && (companyName.length < 2 || companyName.length > 100)) {
            layer.msg('司名称长度限制为2~100个字符');
            return;
        }
        if(name.length > 0 && (name.length < 2 || name.length > 100)) {
            layer.msg('联系人署名长度限制为2~100个字符');
            return;
        }
        if(phone.length == 0 && email.length == 0) {
            layer.msg('联系电话和邮箱至少需要填写一个');
            return;
        }
        if(content.length == 0 || (content.length < 6 || content.length > 500)) {
            layer.msg('请输入4 ~ 500字符的咨询事项内容');
            return;
        }

        $.ajax({
            dataType: "json",
            type: "post",
            async:true,
            url:  url,
            data: {
                'company_name':companyName,
                'name':name,
                'phone':phone,
                'email':email,
                'content':content,
                '_token':token,
            },
            success: function(data) {
                if(data.code == 0) {
                    layer.msg('提交成功, 感谢您的反馈!');
                    $("#message-form input").val('');
                    $("#message-form textarea").val('');
                } else {
                    layer.msg(data.msg);
                }
            },
            error: function (data) {
                layer.msg('提交失败,请稍后再试');
            }
        });
    });

});