$(document).ready(function(){
  SetWindow();
  StyleLinks();
  RemoveCurrentLinks();
  BuildNav();
});
/*BUILD SIDE NAVIGATION*/
function BuildNav() {
				//add back to top links before each H2
				if($('#content').find("h2").size()>1){
					$('#content h2').before('<div class="top"><a href="#top" onclick="$(\'#top\').ScrollTo(500)">back to top</a></div>');
					TargetDiv=$('#sidenav');
					TargetDiv.append('<p>On this page:</p><ul>');
					//Loop through all H2's
					$('#content h2').each(function(i){	
						//add a unique id to each H2
						if (!this.getAttribute("id")){this.setAttribute("id",("anchor_"+i))};
						Target="#"+this.getAttribute("id");
						//build navigation
						TargetDiv.append('<li><a href="'+Target+'" onclick="$(\''+Target+'\').ScrollTo(500);$(\''+Target+'\')">'+this.innerHTML+'</a></li>');
						});
					TargetDiv.append('</ul>');
	}}
	
/*SET DEFUALT THICKBOX WINDOW SIZE*/
function SetWindow() {
	$('a.thickbox').each(function(){
					var url=this.href;
					var urlString = /\.jpg|\.jpeg|\.png|\.gif|\.html|\.htm|\.php|\.cfm|\.asp|\.aspx|\.jsp|\.jst|\.rb|\.txt|\.bmp/g;
					var urlType = url.toLowerCase().match(urlString);		
					if(urlType != '.jpg' && urlType != '.jpeg' && urlType != '.png' && urlType != '.gif' && urlType != '.bmp' && (url.indexOf('TB_iframe') == -1)){
						this.href+='?TB_iframe=true&height=400&width=600';
						}
				    })
	}


/*STYLE EXTERNAL LINKS*/
function StyleLinks() {
	$('#content a').each(function(){
					var myDomain=document.domain;
					if (this.href.indexOf(myDomain) == -1){
						$(this).addClass("external");
						}					
				   })	
}
/*REMOVE CURRENT LINK FROM SUBNAV*/
function RemoveCurrentLinks() {
	$('#subnav a').each(function(){
					if (this.href==document.location.href){
						this.parentNode.innerHTML=this.innerHTML;						
						}
					})	
}
