function express(){
    $('.notice').find('ul').animate({'marginTop':'-30px'},1000,function(){
        $(this).css('marginTop',0).children('li').eq(0).appendTo($(this));
   });
}
function hmtab(tab, box){
    tab.addClass('on').parent().siblings().children('span').removeClass('on');
    var index = tab.parent().index();
    box.eq(index).stop().fadeIn('fast').siblings().hide()
}
$(document).ready(function() {
    var notice = setInterval(express, 3500);
    $('.notice li').hover(function(){
        clearInterval(notice);
    },function(){
        notice = setInterval(express, 3500);
    });

    $('.hmtab span').click(function() {
        hmtab($(this),$(this).parents('.hmtab').siblings('.tabbox').children())
    });

    $('.searchBtn').click(function(){
        $('.searchbox').fadeToggle('fast');
    }); 
   
    $('.navbtn').click(function(){
        $(this).toggleClass('open');
        $('.nav').toggleClass('open');
    });
    var navbar = $('.navbar li');
    navbar.each(function(){
        var _href = $(this).children('a').attr('href');
        if(_href == _url){
            if($(this).parents('li').length > 0){
                $(this).parents('li').children('a').addClass('cur');
            }else{
                $(this).children('a').addClass('cur');
            }
            
        }
        if($(this).children('ul').length > 0){
            $(this).children('a').after('<em></em>');
        }
    });
    $(".navdot a").click(function(e) {
        e.preventDefault();
        $('.navdot, .navbtn').removeClass('open');
        var obj = $('#'+$(this).data('rel'));
        var offset = obj.offset().top - $('.header').height();        
        $('html,body').animate({scrollTop: offset},300);       
    });

    $('.social .wx').click(function() {
        $(this).siblings('.qr').stop().fadeToggle('fast');
    });

    $('#backTop a').click(function() {
        $("html,body").animate({scrollTop: 0},300);
    });

    if($('.owl-carousel').length > 0){
        $('.owl-carousel').each(function(){
             $(this).on('initialized.owl.carousel', function(e) {
                $(this).siblings('.load').remove();
            });
        });
    }
   
    if($('#slides').length > 0){
       $('#slides').owlCarousel({
            items:1,
            loop:true, 
            mouseDrag:false,
            autoplay:false,
            nav:true,  
            dots:true,
            autoplay:true,
       });
    }

    if($('#hmshow').length > 0){
       $('#hmshow').owlCarousel({
            items:4,
            loop:true,
            margin:15, 
            mouseDrag:false,
            autoplay:true,
            nav:true,  
            dots:true,
            responsiveClass:true,
            responsive:{
                0:{
                    items:2,
                    nav:false,
                    dots:true,
                   
                },
                540:{
                    items:3,
                    nav:false,
                    dots:true,
                },
                769:{
                    items:4,
                    nav:true,
                    dots:false,
                }
            }
       });
    }

    $(window).resize(function(){        
        if($(window).width() > 960){
            navbar.mouseover(function() {
                $(this).children('a').addClass('on');
                if($(this).find('li').length > 0){
                    $(this).children('ul').show();
                }
            }).mouseleave(function() {
                $(this).children('a').removeClass('on').siblings('ul').hide();
            }); 
        }else{
            navbar.off('mouseover mouseleave');
        }
    }).trigger('resize');
    navbar.children('em').click(function(){
        $(this).siblings('ul').stop().slideToggle('fast').parent().siblings().children('ul').stop().slideUp('fast');
    });


    $(window).scroll(function() {
        var scrollTop = $(window).scrollTop();
        if (scrollTop > 0) {
            $(".header, .blank").addClass("fixed")
        } else {
            $(".header, .blank").removeClass("fixed")
        }
        if (scrollTop > 300) {
            $("#backTop").fadeIn()
        } else {
            $("#backTop").fadeOut()
        }
    });
    
    $('.searchbox .submit').click(function(){
        if($(this).siblings('.text').val() == '' || $(this).siblings('.text').val() == '输入搜索关键词'){
            alert('请输入关键词搜索！');
            return false;
        }
    });
    $('#divSearchPanel input[type="submit"]').click(function(){
        if($(this).siblings('input').val() == ''){
            alert('请输入关键词搜索！');
            return false;
        }
    });
});