(function ($) {
	'use strict';
	$(function () {
		// Plugin initialization
		$('.scrollspy').scrollSpy();
		$('.button-collapse').sideNav();
		$('.materialboxed').materialbox();
		$('select').material_select();

		// Floating-Fixed table of contents
		setTimeout(function () {
			var tocWrapperHeight = 0,
				/*Max height of ads.*/ tocHeight = $('.toc-wrapper .table-of-contents').length ? $('.toc-wrapper .table-of-contents').height() : 0,
				socialHeight = $('nav').height(),
				/*Height of unloaded social media in footer.*/ footerOffset = $('body>footer').first().length ? $('body>footer').first().offset().top : 0,
				bottomOffset = footerOffset - socialHeight - tocHeight - tocWrapperHeight;
			if ($('nav').length) {
				$('.toc-wrapper').pushpin({
					top: $('nav').height(),
					width: $('.toc-wrapper').width(),
					bottom: bottomOffset
				});
			} else if ($('#index-banner').length) {
				$('.toc-wrapper').pushpin({
					top: $('#index-banner').height(),
					width: $('.toc-wrapper').width(),
					bottom: bottomOffset
				});
			} else {
				$('.toc-wrapper').pushpin({
					top: 0,
					width: $('.toc-wrapper').width(),
					bottom: bottomOffset,
				});
			}
		}, 100);

	}); // end of document ready
})(jQuery); // end of jQuery name space

// Back to top & Header change
$(document).ready(function ($, document, undefined) {

	'use strict';

	var offset = 300,
		//browser window scroll (in pixels) after which the "back to top" link opacity is reduced
		offset_opacity = 1100,
		//duration of the top scrolling animation (in ms)
		scroll_top_duration = 700,
		//grab the "back to top" link
		$back_to_top = $('.c-button'),

		header_offset = 300,
		//browser window scroll (in pixels) after which "heander change"
		$header_hidden = $('.Sticky'),
		$header_show = $(".PageHeader");

	//hide or show the "back to top" link
	$(window).scroll(function () {
		if ($(this).scrollTop() > offset) {
			$back_to_top.addClass('cd-is-visible');
			$back_to_top.removeClass('cd-fade-out');
		} else {
			$back_to_top.removeClass('cd-is-visible cd-fade-out');
		}
		if ($(this).scrollTop() > offset_opacity) {
			$back_to_top.addClass('cd-fade-out');
		}
		if ($(this).scrollTop() > header_offset) {
			$header_hidden.addClass('is-hidden');
			$header_show.addClass('is-shown');
		} else {
			$header_hidden.removeClass('is-hidden');
			$header_show.removeClass('is-shown');
		}
	});

	//button ripple effice
	var $ripple = $('.js-ripple');

	$ripple.on('click.ui.ripple', function (e) {

		var $this = $(this);
		var $offset = $this.parent().offset();
		var $circle = $this.find('.c-ripple__circle');

		var x = e.pageX - $offset.left;
		var y = e.pageY - $offset.top;

		$circle.css({
			top: y + 'px',
			left: x + 'px'
		});

		$this.addClass('is-active');

		//smooth scroll to top
		if ($(this).hasClass('backtotop')) {
			e.preventDefault();
			$('body,html').animate({
				scrollTop: 0,
			}, scroll_top_duration);
		}
	});

	$ripple.on('animationend webkitAnimationEnd oanimationend MSAnimationEnd', function () {
		$(this).removeClass('is-active');
	});
}); // end of back to top