$(function () {
    (function() {
        var L_nav = $('#l-nav'),
            $nav_m = L_nav.find('.nav-m');

        $nav_m.css({'height':'0'});
        L_nav.hover(function () {
            $nav_m.stop();
            $nav_m.animate({'height':'518px'},1000);
        },function () {
            $nav_m.stop();
            $nav_m.animate({'height':'0'},1000);
        });
    })();
    (function() {
        /*首页导航*/
        var Kec = $('#kec'),
            UL = Kec.find('ul'),
            $li = UL.find('li'),
            len = $li.length,
            t = '';

        // UL.hover(function(e){
        //     e.stopPropagation();
        // })

        Kec.hover(function () {
            $li.stop();
            clearTimeout(t);
            UL.show();
            for (var i = 0; i < len; i++ ){
                $li.eq(i).animate({
                    'height': '107px'
                },i*120);
            };
            
        },function () {
            $li.stop();
            for (var i = 0; i < len; i++ ){
                $li.eq(i).animate({
                    'height': '1px'
                },i*120);
            };
            t = setTimeout(a,len*120);
        });
        function a() {
            UL.hide();
        };
    })();
    (function () {
        //logo栏的光线效果
        var logo = $('#logo');
        var $top = logo.find('.pic_top');
        var $bottom = logo.find('.pic_bottom');
        a();
        setInterval(a,5000);
        function a() {
            var ww = logo.width();
            var picw = $top.width();
            // console.log(ww);
            $top.css({'left':-picw + 'px'});
            $bottom.css({'left':ww  + 'px'});
            $top.animate({'left':ww + 'px'},5000,function () {
                $top.css({'left':-picw + 'px'});
            });
            $bottom.animate({'left':-picw + 'px'},5000,function () {
                $bottom.css({'left':ww  + 'px'});
            });
        };
    })();

    (function(){
        // 子栏目的显示和隐藏
        $li = $(".t-nav .top"),
        $sub_menu = $(".sub_menu");

        $li.hover(function(){
            $(this).find(".sub_menu").show();
        },function(){
            $(this).find(".sub_menu").hide();
        })
    })();

    // 友情链接切换
    (function(){
        var tab_btn=$(".friendlink .tab_btn span");
        var tab_content=$(".friendlink .tab_content ul");
        tab_btn.hover(function(){
            var btnObj=$(this);
            var index = btnObj.index();
            tab_content.eq(index).show().siblings().hide();
            btnObj.addClass("tab_on").siblings().removeClass("tab_on");
        })
    })();
    // 导航栏的固定和显示
    (function(){
        $(document).mousewheel(function(e,d){
            if ( d < 0 ){
                $(".logo").stop(true,false);    /*stop(stopAll,gotoend)*/
                $(".h_behind").css("margin-top","0px");
                $(".header").css("position","fixed");
                $(".logo").animate({height:'0',paddingTop:'0'},100);

            }else{
                if($(window).scrollTop()>0){
                    $(".logo").stop(true,false);
                    $(".h_behind").css("margin-top","100px");
                    if($(window).scrollTop()<99){
                        $(".header").css("position","relative");
                        $(".h_behind").css("margin-top","0");
                        return;
                    }
                    $(".header").css("position","fixed");
                    $(".logo").animate({height:'100px',paddingTop:'20px'},100);
                }
            };
        });

        $(document).keydown(function(event){
            // 页面向下
            if(event.keyCode==40){
                $(".logo").stop(true,false);    /*stop(stopAll,gotoend)*/
                $(".h_behind").css("margin-top","0px");
                $(".header").css("position","fixed");
                $(".logo").animate({height:'0',paddingTop:'0'},100);
            }
            // 页面向上
            if(event.keyCode==38){
                $(".logo").stop(true,false);
                $(".h_behind").css("margin-top","100px");
                if($(window).scrollTop()<99){
                    $(".header").css("position","relative");
                    $(".h_behind").css("margin-top","0");
                    return;
                }
                $(".header").css("position","fixed");
                $(".logo").animate({height:'100px',paddingTop:'20px'},100);
            }
        })
    })();
});

