// Document Ready
jQuery(document).ready(function() { 

	//Create a linked list of all <h2> tags in the .entry part of the page; display at the top of the sidebar
	if (jQuery("ul.sidebar").attr("id") == "pagenav") { 
		jQuery("<li class='widget'><img src='http://indianachristianacademy.org/wp-content/themes/ica/images/pagelinks-top.gif' width='241' height='40'><ul class='pagelinks'></ul><img height='16' width='241' src='http://indianachristianacademy.org/wp-content/themes/ica/images/quicklinks-btm.gif' /></li>").prependTo("ul.sidebar");

		jQuery("div.entry > h2").each(function(i) {
			var $this = jQuery(this);
			var $h2Id = i + "anchor";
			var $h2Text = jQuery(this).text();
			var $h2ListItem = "<li><a href='#" + $h2Id + "'>" + $h2Text + "</a></li>";
			
			jQuery($h2ListItem).appendTo("ul.pagelinks");
			
			var backToTop = jQuery("<span>&nbsp;</span><a class='top-link' href='#page-top'>(back to top)</a>");
			if(i > 0) {jQuery(backToTop).appendTo($this);}
			
			$this.attr("id", $h2Id);
		});  //end each()
	} //end if
	
	//Add a pdf icon to all PDF links
	jQuery("a[href$=.pdf]").after("<img src='http://indianachristianacademy.org/wp-includes/images/pdficon_small.gif' width='12' height='12'/>&nbsp;");
	
	/*
	//Add an external link icon to all external links
	$('a').filter(function() {
	//Compare the anchor tag's host name with location's host name
	return this.hostname && this.hostname !== location.hostname;
	  }).append("&nbsp;<img src='http://gracetoanderson.com/newsite/ica/wp-includes/images/external.png' width='10' height='10'/>");
	*/
});