// ===[DEBUGGER]====================================================

  runDBug = false;

  function debugTests(){
    displayDBugWarning();
    debug_showDeadLinks();    
  }

// ===[END DEBUGGER]================================================


jQuery(document).ready(function(){
  tweakNav();
	tweakStaffListing();
	tweakNews();
	tweakCalendars();
});


function tweakNav(){

  jQuery('#topNav a:first').addClass('first');

	replaceElement('#subNav a:first','h1');

  jQuery('#topNav a.active, #footer a.active, #sideNav a.active').each(
    function(){
      if(jQuery(this).parents('#sideNav').length == 0){ // if this element is in sideNav then it may be a parent of the active page (if parents get active class)
        jQuery(this).attr('title','You are viewing this page');
      }
      if(jQuery(this).attr('href') == '/'){ // don't give active state to home link on home page (could just hide it)
        jQuery(this).removeClass('active').addClass('homeActive');
        jQuery(this).attr('title','You are viewing this page'); // Ensures home link in #sideNav (omitted above) gets this
      }
    }
  );

	setupSectionMenu();

} // end function tweakNav()


function setupSectionMenu(){
	
	jQuery('#sectionMenu a').each(function(ind){
		if(jQuery(this).attr('id') == 'sn'+jQuery('#padder').attr('class')){
			jQuery(this).addClass('active');
		}
		jQuery(this)
			.addClass('sectionLink_'+eval(ind+1))
			.css('z-index',eval(100-(ind+1)))
			.show();
	}); // #sectionMenu a .each

	jQuery('#sectionMenu a:not(.active)').each(function(){
		jQuery(this)
			.hover(
				function(){
					jQuery(this).stop().animate({top:'7px'},'fast');
				},
				function(){
					jQuery(this).stop().animate({top:0},'fast');
				}
			) // .hover
		;
	}); // #sectionMenu a.base .each

	// Start depressed when page loads, then go back to normal (Mantis: #8678)
	// First .animate does nothing as it's animating to where tab already is, but without it second animate is barely noticeable
	jQuery('#sectionMenu a.active').animate({top:'7px'},'slow').animate({top:0},'fast');
}


function tweakNews(){
	replaceElement('.news_content_list .news_content_title, .news_headline_list .newsContentTitleText','h1');
	replaceElement('.article_table .summary_html h1','b');
	//.article_table .summary_html
}

function tweakCalendars(){
	replaceElement('.calendar_list h3.heading','h1');
}

function tweakStaffListing(){
	jQuery("#staff_directory .staffListing .staffInfo .position:contains('N/A')").remove();
	jQuery("#staff_directory .building_heading:gt(0)").addClass('bhSubsequent');
}

function replaceElement(targetEl,newElType){
	// ToDo: add optional third parameter which is an array of attributes to transfer, such as class & id
	jQuery(targetEl).each(
		function(){
			jQuery(this).parent().append('<'+newElType+'>'+jQuery(this).html()+'</'+newElType+'>');
			jQuery(this).remove();
		}
  );
	
}

