/*
* @Author: Dodo
* @Date:   2018-07-02 16:12:57
* @Last Modified by:   DoDo
* @Last Modified time: 2019-07-29 09:22:13
*/
$(function(){

    var wW = $(window).width();
    var wH = $(window).height();
    var win_t = 0;
    var b_t = 0;
    var header_bream = null;
    var liAttr = null;

    if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
        var msViewportStyle = document.createElement('style');
        msViewportStyle.appendChild(
            document.createTextNode(
                '@-ms-viewport{width:auto!important}'
            )
        );
        document.querySelector('head').appendChild(msViewportStyle);
    };

    $('.nav-list li').each(function(){
        var _thisnH = $(this).find('.nav-down .div-01').height()+24;
        $(this).attr('data-height',_thisnH);
    });

    $('.nav li').hover(function(){
        $(this).find('.nav-down').css('height',$(this).attr('data-height'));
    },function(){
        $(this).find('.nav-down').css('height',0);
    });

    $('.nav-search-up').click(function(){
        $('.nav-search-tc').stop(true,false).slideToggle();
        $('.nav-search-tc .put-01').focus();
    });

    $('.header-bream').click(function(){
        var header_bream = $(this).attr('data-off');
        if( header_bream == 0 ){
            $(this).attr('data-off',1);
            console.log($(this).attr('data-off'))
            b_t = win_t;
        }else{
            $(this).attr('data-off',0);
            console.log($(this).attr('data-off'))
            $('body,html').animate({
                scrollTop: b_t
            },0)
        }
        $('.nav,.header-bream').toggleClass('on');
    });

    /* tab */ 
    $('.index-product-tab .span-01').click(function(){
        $(this).addClass('on').siblings().removeClass('on');
        $('.index-product-nr').find('.index-product-nr-01').eq($(this).index()).addClass('on').siblings().removeClass('on');
    });
    /* 育婴知识tab */ 
    $('.index-knowledge-tab .span-01').click(function(){
        $(this).addClass('on').siblings().removeClass('on');
        $('.index-knowledge-nr').find('.index-knowledge-nr-01').eq($(this).index()).show().siblings().hide();
    });

    /*  */ 
    $('.special-way-01').mouseover(function(){
        $(this).addClass('on');
        $(this).siblings().removeClass('on');
    });

    $('.special-place-tcup-cf').click(function(){
        $('body,html').addClass('on');
        $('.special-place-tc-cf,.special-place-mc').fadeIn();
    });
    $('.special-place-tcup-jy').click(function(){
        $('body,html').addClass('on');
        $('.special-place-tc-jy,.special-place-mc').fadeIn();
    });

    /* 返回顶部 */ 
    $('.return-top').click(function(){
        $('body,html').animate({
            scrollTop: 0
        },500)
    });

    $('.prodes-tab .span-01').click(function(){
        $(this).addClass('on').siblings().removeClass('on');
        $('.prodes-nr-01').eq($(this).index()).show().siblings().hide();
    })

    function resizeChange(){
        wW = $(window).width();
        wH = $(window).height();

        $('.li-down').each(function(){
            liAttr = $(this).attr('data-href');
            if(wW>=1200){
                $(this).find('.bdo-01 a').attr('href',liAttr);
            }else{
                $(this).find('.bdo-01 a').removeAttr('href');
            }
        });

        $("html *").click(function(e){ 
            e = window.event || e;
            obj = $(e.srcElement || e.target);
            if (!$(obj).is(".nav-search-up,.nav-search-up *,.nav-search-tc,.nav-search-tc *")){
                if(wW>768){
                    $('.nav-search-tc').stop(true,false).slideUp();
                    $('.nav-search-tc .put-01').blur();
                }
            } 
        });

        $("html *").click(function(e2){ 
            e2 = window.event || e2;
            obj2 = $(e2.srcElement || e2.target);
            if (!$(obj2).is(".special-place-tc-cont,.special-place-tc-cont *,.special-place-tcup,.special-place-tcup *")){
                $('.special-place-tc,.special-place-mc').fadeOut();
                $('body,html').removeClass('on');
            } 
        });

        /* 首页关于图片 */ 
        if($('.index-about-img .a-img').length>0){
            var off_lef = $('.index-about-img').offset().left;
            var inab_w = $('.index-about-img').width();
            $('.index-about-img .a-img').width(off_lef+inab_w);
        };
        /* 首页育婴知识 */ 
        if($('.index-knowledge-img .a-img').length>0){
            var off_lef2 = $('.index-knowledge-img').offset().left;
            $('.index-knowledge-img .a-img').width( wW - off_lef2 );
        };
        
        /* 二级页面导航 */ 
        $('.about-nav-cont a').each(function(){
            if($(this).hasClass('on')){
                var anol = $(this).offset().left-20;
                $('.about-nav-cont').scrollLeft(anol);
            }
        });
        $('.news-year-tab a').each(function(){
            if($(this).hasClass('on')){
                var anol2 = $(this).offset().left-20;
                $('.news-year-tab').scrollLeft(anol2);
            }
        });
        $('.knowledge-tab a').each(function(){
            if($(this).hasClass('on')){
                var anol3 = $(this).offset().left-20;
                $('.knowledge-tab').scrollLeft(anol3);
            }
        });

    };
    resizeChange();
    function aa(){
        $('.special-six-a1').each(function(){
            var i_h = $(this).find('i').height();
            $(this).find('.bdo-details').attr('data-height',i_h);
        });
        $('.special-six-a1').hover(function(){
            var bdo_H = parseInt($(this).find('.bdo-details').attr('data-height'));
            $(this).find('.bdo-details').height(bdo_H);
        },function(){
            $(this).find('.bdo-details').height(0);
        })
    }
    $(window).resize(function(){
        wW = $(window).width();
        wH = $(window).height();
        resizeChange();
        aa();
    });

    $(window).scroll(function(){
        win_t = $(window).scrollTop();

        if($('header').hasClass('xf')){
            if(wW > 767){
                if(win_t<=$('.header').height()){
                    $('.header').removeClass('xf');
                }
            }else{
                $('.header').removeClass('xf');
            }
        }else{
            if(wW > 767){
                if(win_t>$('.header').height()-58){
                    $('.header').addClass('xf');
                }
            }
        }
        
    });


    $(window).load(function(){
        aa();
        $('.index-product-nr-01').eq(1).show();
        $('.index-product-nr-01').hide();
        if($('header').hasClass('xf')){
            if(wW > 767){
                if($(window).scrollTop()<=$('.header').height()){
                    $('.header').removeClass('xf');
                }
            }else{
                $('.header').removeClass('xf');
            }
        }else{
            if(wW > 767){
                if($(window).scrollTop()>$('.header').height()-58){
                    $('.header').addClass('xf');
                }
            }
        }
    })

    


    
});