$(document).ready(function() {
	$(".menu li").addClass("withripple");

	$(".menu li > ul").each(function() {
		$(this).closest('li').addClass('to-upper');
	});

	$(".menu li li").each(function() {
		$(this).parents("li").removeClass("withripple");
	});

	$('#github a').tooltip();

	var tmpa = document.createElement('a');
	$(tmpa).attr('href', window.location.href);
	$('.menu a[href="' + tmpa.href + '"]').parent('li').addClass('active');
	if ($('.menu li.active').length <= 0) {
		$('.menu li').first().addClass('active');
	}

	// Bootstrap the tables
	$(".documentation table").addClass("table table-striped table-bordered table-hover table-condensed");

	// Prettify the <pre> tags
	$(".documentation [class^='language-']").closest("pre").addClass("prettyprint");

	// Dynamic callouts
	$(".documentation blockquote:contains(Attention)").addClass("bs-callout bs-callout-danger");
	$(".documentation blockquote:contains(Danger)").addClass("bs-callout bs-callout-danger");

	$(".documentation blockquote:contains(Warning)").addClass("bs-callout bs-callout-warning");
	$(".documentation blockquote:contains(Notice)").addClass("bs-callout bs-callout-warning");

	$(".documentation blockquote:contains(Info)").addClass("bs-callout bs-callout-info");
	$(".documentation blockquote:contains(Note)").addClass("bs-callout bs-callout-info");

	$(".documentation blockquote:contains(Hint)").addClass("bs-callout bs-callout-success");
	$(".documentation blockquote:contains(Tip)").addClass("bs-callout bs-callout-success");

	// Change h1 to h4 for search results
	$("#search-results h1").replaceWith(function() {
		return "<h4>" + $(this).text() + "</h4>";
	});

	// Create anchor tags on header spans within documentation
	// This can be done better/smarter
	$(".documentation h2, .documentation h3, .documentation h4, .documentation h5, .documentation h6").each(function() {

		// We want to ignore header spans within blockquotes
		if ($(this).parent().get(0).tagName != "BLOCKQUOTE") {
			var anchor = $(this).text().toLowerCase().trim();

			var hyphenNeedle = [/ /g];
			var emptyNeedle = [/\[/g, /\]/g, /\(/g, /\)/g, /\:/g];

			hyphenNeedle.forEach(function(word) {
				anchor = anchor.replace(word, "-");
			});

			emptyNeedle.forEach(function(word) {
				anchor = anchor.replace(word, "");
			});

			$(this).append(" <a class=\"header-anchor\" id=\"" + anchor + "\" href=\"#" + anchor + "\"></a>");
		}

	});
});
