$(function () {
	var windowWidth = $(window).width();
	var commaMenu = $('.sf-menu').superfish({
    delay: 0,
    //	animation: {
    //		opacity: 'show'
    //	},
    //	animationOut: {
    //		opacity: 'hide'
    //	},
    speed: 'fast',
    speedOut: 'fast',
    cssArrows: true,
    disableHI: true,
    onBeforeShow: function () {
        //		$('.sf .dropdown-menu').addClass('animated-fast fadeInUp');
    },
    onHide: function () {
        //		$(this).removeClass('animated-fast fadeInUp');
    }
});


var windowScroll = function () {
    var lastScrollTop = 0;
    $(window).scroll(function (event) {
        var header = $('#header'),
            footer = $('#footer'),
            scrlTop = $(this).scrollTop(),
            headerH = header.outerHeight(true);
        if (scrlTop > headerH) {
            header.addClass('navbar-fixed-top animated slideInDown');
        } else {
            if (header.hasClass('navbar-fixed-top')) {
                header.addClass('navbar-fixed-top animated');
                setTimeout(function () {
                    header.removeClass('navbar-fixed-top animated slideInDown');
                }, 500);
            }
        }

    });
}();

// Offcanvas and cloning of the main menu
var offcanvas = function () {
    var commaNav = $('#comma-nav-toggle');
    var body = $('body');
    var $clone = $('#comma-menu').clone();
    $clone.attr({
        'id': 'offcanvas-menu'
    });
    $clone.find('> ul').attr({
        'class': '',
        'id': ''
    });
    $('#comma-page').prepend($clone);
    // click the burger
    commaNav.on('click', function () {
        if (body.hasClass('comma-offcanvas')) {
            $(this).removeClass('is-active');
            body.removeClass('comma-offcanvas');
            document.removeEventListener('touchmove', bodyScroll, false);
        } else {
            $(this).addClass('is-active');
            body.addClass('comma-offcanvas');
            document.addEventListener('touchmove', bodyScroll, false);
            var myScroll = new IScroll('#offcanvas-menu',{
                click: true
            });
        }
    });
    $('#offcanvas-menu').css('height', $(window).height());
    $(window).resize(function () {
        var w = $(window);
        $('#offcanvas-menu').css('height', w.height());
        if (w.width() > 769) {
            if (body.hasClass('comma-offcanvas')) {
                commaNav.removeClass('is-active');
                body.removeClass('comma-offcanvas');
            }
        }
    });

    $(window).scroll(function () {
        var top = $(window).scrollTop();
        $("#offcanvas-menu").css("top", top + "px");
    });

}();



var mobileMenuOutsideClick = function () {
    $(document).click(function (e) {
        var container = $("#offcanvas-menu, .js-comma-nav-toggle");
        if (!container.is(e.target) && container.has(e.target).length === 0) {
            if ($('body').hasClass('comma-offcanvas')) {
                $('#comma-nav-toggle').removeClass('is-active');
                $('body').removeClass('comma-offcanvas');
                document.removeEventListener('touchmove', bodyScroll, false);
            }
        }
    });
}();

var  ofMenuBtn= $('#offcanvas-menu ul>li');

ofMenuBtn.click(function(){
    if($(this).hasClass('active')) {
       $(this).removeClass('active'); 
    } else {
        ofMenuBtn.removeClass('active');
        $(this).addClass('active');
    }
});


	var contentWayPoint = function () {
	var i = 0;
	$('.animate-box').waypoint(function (direction) {
		if (direction === 'down' && !$(this.element).hasClass('animated')) {
			i++;
			$(this.element).addClass('item-animate');
			setTimeout(function () {
				$('body .animate-box.item-animate').each(function (k) {
					var el = $(this);
					setTimeout(function () {
						el.addClass('fadeInUp animated');
						el.removeClass('item-animate');
					}, k * 200, 'easeInOutExpo');
				});
			}, 100);
		}
	}, {
		offset: '95%'
	});
}();

	var honorFlexSlider = function () {
	var honorItemMargin = 0,
		honorItemWidth,
		honorMaxItems;
	if (windowWidth > 1200) {
		honorItemMargin = 30;
		honorItemWidth = 320;
		honorMaxItems = 4;
	}
	$('.honor-flexslider').flexslider({
		animation: "slide",
		animationLoop: true,
		itemWidth: honorItemWidth,
		maxItems: honorMaxItems,
		itemMargin: honorItemMargin,
		directionNav: true,
		touch: true,
		animationLoop: false
	});
}();


var bannerFlexSlider = function () {
	$('.flexslider').flexslider({
		animation: "slide",
		slideshow: true,
		slideshowSpeed: 2000,
		prevText: "",
		nextText: "",
	});
}();


var subordinateFlexSlider = function () {
	var subordinateItemMargin = 0,
		subordinatItemWidth,
		subordinatMaxItems;
	if (windowWidth > 1200) {
		subordinateItemMargin = 30;
		subordinatItemWidth = 410;
		subordinatMaxItems = 3;
	}
	$('.subordinate-flexslider').flexslider({
		animation: "slide",
		animationLoop: true,
		itemWidth: subordinatItemWidth,
		maxItems: subordinatMaxItems,
		itemMargin: subordinateItemMargin,
		directionNav: true,
		touch: true,
	});
}();

	var scrollspy = function () {
	$('body').scrollspy({
		target: '#navbar-scroll',
		offset: $('.navbar-scroll').outerHeight(true)
	});

	$('.navbar-scroll').affix({
		offset: {
			top: function () {
				return (this.top = $('.navbar-scroll').offset().top)
			}
		}
	}).on('affixed.bs.affix', function () {
		$('body').css(
//			"padding-top", $('.navbar-scroll').outerHeight(true)
		);
	}).on('affix-top.bs.affix', function () {
		$('body').css("padding-top", 0);
	});

	$('.navbar-scroll li').click(function () {
		$('html, body').animate({
			scrollTop: $($(this).find('a').attr('href')).offset().top - $('.header').height()
		}, 200);
		return false;
	});
}();

	
	$(window).stellar();
});

 function secBoard(td,tr,m,n,sec1,sec2) //m是选项卡数量,n是当前选项卡序号
{
	//更新选项卡样式
	for(i=0;i<m;i++) { 
	if (i==n) {
		document.getElementById(td+n).className=sec2;
	} else {
		document.getElementById(td+i).className=sec1;}
}

//隐藏和显示行
for(i=0;i<m;i++) {
	if (i==n) {
		document.getElementById(tr+n).style.display="";
	} else {
		document.getElementById(tr+i).style.display="none";}
	}
}
function secBoard_more(td,tr,m,n,sec1,sec2,A,URL) {//m是选项卡数量,n是当前选项卡序号
	if(URL != ""){
		URL_A = URL.split("|")
	}
	//更新选项卡样式
	for(i=0;i<m;i++) { 
		if (i==n) {
			document.getElementById(td+n).className=sec2;
			if(URL != ""){
				document.getElementById(A).href=URL_A[i];
			}
		} else {
			document.getElementById(td+i).className=sec1;
		}
	}
	
	//隐藏和显示行
	for(i=0;i<m;i++) {
		if (i==n) {
			document.getElementById(tr+n).style.display="";
		} else {
			document.getElementById(tr+i).style.display="none";
		}
	}
}