$(document).ready(function() {
	// wrap H1 text inside a span
	var h1 = $("h1");
	var h1_text = h1.text();
	h1.html("<span>" + h1_text + "</span>");
	
	// open external links in a new window
	$("a[href^='http']").each(function() {
		var title = $(this).attr("title");
		if (title == "") {
			$(this).attr("title", "Opens in a new window");
		} else {
			$(this).attr("title", title + " (opens in a new window)");
		}
		$(this).click(function(e) {
			e.preventDefault();
			window.open($(this).attr("href"));
		});		
	});
	
	// replace horizontal rules with a div since we cannot remove
	// borders in IE on <hr> elements
	$("#content hr").wrap("<div class='hr'></div>").remove();
	
	// wrap each column of links on Links page
	if ($("body").attr("id") == "page-links") {
		var indices = [];
		var elems = $("#content div.inner").children();
		elems.each(function(i) {
			if ($(this).is("h2")) {
				indices.push(i);
			};
		});
		indices.push(elems.length);
		for (i=1; i < indices.length; i++) {
			if (indices[i] - indices[i-1] != 1) {
				elems.slice((indices[i-1]), indices[i]).wrapAll("<div class='link-list clearfix'></div>");
			};
		};
	};
	$(".link-list").wrapAll("<div class='clearfix'></div>");
	
	
	
});