/* ===================================================================

* ================================================================= */

(function($) {
    "use strict";

    $(document).on('ready', function() {


        /* ==================================================
            # Smooth Scroll
         ===============================================*/
        $("body").scrollspy({
            target: ".navbar-collapse",
            offset: 200
        });
        $('a.smooth-menu').on('click', function(event) {
            var $anchor = $(this);
            var headerH = '75';
            $('html, body').stop().animate({
                scrollTop: $($anchor.attr('href')).offset().top - headerH + "px"
            }, 1500, 'easeInOutExpo');
            event.preventDefault();
        });


        /* ==================================================
            # Banner Animation
        ===============================================*/
        function doAnimations(elems) {
            //Cache the animationend event in a variable
            var animEndEv = 'webkitAnimationEnd animationend';
            elems.each(function() {
                var $this = $(this),
                    $animationType = $this.data('animation');
                $this.addClass($animationType).one(animEndEv, function() {
                    $this.removeClass($animationType);
                });
            });
        }

        //Variables on page load
        var $immortalCarousel = $('.animate_text'),
            $firstAnimatingElems = $immortalCarousel.find('.item:first').find("[data-animation ^= 'animated']");
        //Initialize carousel
        $immortalCarousel.carousel();
        //Animate captions in first slide on page load
        doAnimations($firstAnimatingElems);
        //Other slides to be animated on carousel slide event
        $immortalCarousel.on('slide.bs.carousel', function(e) {
            var $animatingElems = $(e.relatedTarget).find("[data-animation ^= 'animated']");
            doAnimations($animatingElems);
        });

    }); // end document ready function
})(jQuery); // End jQuery


//导航高亮
$(function() {
    var datatype = $(".navbar-nav").attr("data-type");
    $(".navbar-nav>li ").each(function() {
        try {
            var myid = $(this).attr("id");
            if ("index" == datatype) {
                if (myid == "nvabar-item-index") {
                    $("#nvabar-item-index a:first-child").addClass("active")
                }
            } else if ("category" == datatype) {
                var infoid = $(".navbar-nav").attr("data-infoid");
                if (infoid != null) {
                    var b = infoid.split(' ');
                    for (var i = 0; i < b.length; i++) {
                        if (myid == "navbar-category-" + b[i]) {
                            $("#navbar-category-" + b[i] + " a:first-child").addClass("active")
                        }
                    }
                }
            } else if ("article" == datatype) {
                var infoid = $(".navbar-nav").attr("data-infoid");
                if (infoid != null) {
                    var b = infoid.split(' ');
                    for (var i = 0; i < b.length; i++) {
                        if (myid == "navbar-category-" + b[i]) {
                            $("#navbar-category-" + b[i] + " a:first-child").addClass("active")
                        }
                    }
                }
            } else if ("page" == datatype) {
                var infoid = $(".navbar-nav").attr("data-infoid");
                if (infoid != null) {
                    if (myid == "navbar-page-" + infoid) {
                        $("#navbar-page-" + infoid + " a:first-child").addClass("active")
                    }
                }
            } else if ("tag" == datatype) {
                var infoid = $(".navbar-nav").attr("data-infoid");
                if (infoid != null) {
                    if (myid == "navbar-tag-" + infoid) {
                        $("#navbar-tag-" + infoid + " a:first-child").addClass("active")
                    }
                }
            }
        } catch (E) {}
    });
    $(".navbar-nav").delegate("a", "click", function() {
        $(".navbar-nav>li a").each(function() {
            $(this).removeClass("active")
        });
        if ($(this).closest("ul") != null && $(this).closest("ul").length != 0) {
            if ($(this).closest("ul").attr("id") == "menu-navigation") {
                $(this).addClass("active")
            } else {
                $(this).closest("ul").closest("li").find("a:first-child").addClass("active")
            }
        }
    })
});

/*悬浮客服*/
$(function () {
    $('#toolbar dd').bind({
        'mouseenter': function () {
            if ($(this).children('.slide').length) {
                var _this = $(this).children('.slide');
                _this.stop(true, true).animate({ 'width': 180 }, 200);
            } else if ($(this).children('.pop').length) {
                var _this = $(this).children('.pop');
                _this.show().animate({ 'right': 65 }, 200);
            }
        },
        'mouseleave': function () {
            if ($(this).children('.slide').length) {
                var _this = $(this).children('.slide');
                _this.stop(false, false).animate({ 'width': 0 }, 200);
            } else if ($(this).children('.pop').length) {
                var _this = $(this).children('.pop');
                _this.hide().animate({ 'right': 90 }, 200);
            }
        }
    });
    $("#top").click(function () {
        $("body, html").stop().animate({ "scrollTop": 0 });
    });
});
/* 微信提示 */
	var btn=document.getElementById('btn');
	var clipboard=new Clipboard(btn);
	clipboard.on('success', function(e){
		$('#weixin').slideDown().delay(1500).slideUp(500);
		console.log(e);
	});
	clipboard.on('error', function(e){
		$('#weixin').slideDown().delay(1500).slideUp(500);
		console.log(e);
	});
/* 微信弹窗 */
function dkcf(){$('#wxnr').fadeIn("fast");$('#fdwx').fadeOut("fast");}
function gbcf(){$('#fdwx').fadeIn("slow");$('#wxnr').fadeOut("fast");}


$(".moreopen").on('click',function(){	
    $(this).parents().find(".morebox").eq(0).slideToggle();
	$(this).toggleClass("moreon");
	return false;
    });

$(".moreclose").on('click',function(){	
    $(this).parents(".morebox").slideUp();
	$(this).parents(".morebox").prev(".more").removeClass("moreon");
	return false;
    });