﻿$(document).ready(function(){
	secondaryNav();
				
	try {
	} catch(err) {
		var txt = "There was an error on this page. \n\n Error description: " + err.description + "\n\n Click OK to continue. \n\n";
		//alert(txt);
	}
	removeAnchors();
});


function secondaryNav() {
	
	// for table rows of the leftNav table, add class leftNavSub
	$("table.leftNav>tbody>tr").addClass("leftNavSub");
	// for table rows with an ID that starts with zz2_CurrentNav add class leftNavParent and remove class leftNavSub
	$("table.leftNav tr[id^=zz2_CurrentNav]").addClass("leftNavParent").removeClass("leftNavSub");
	
	// for parent items that are selected, show that parent's leftNavSub
	$("table.leftNav1.leftNavSelected").parents("tr.leftNavParent").next("tr.leftNavSub").addClass("leftNavSubShown");
	
	// for sub items that are selected
	$("table.leftNav2.leftNavSelected").each(function(){
		// for this instance of a table with class leftNav2 and leftNavSelected find parent trs with class leftNavSub, 
		// add class leftNavSubShown, traverse to the previous tr with ID starting with zz2_CurrentNav
		$(this).parents("tr.leftNavSub").addClass("leftNavSubShown").prev("tr[id^=zz2_CurrentNav]").each(function(){
			// for this instance of a tr with ID starting with zz2_CurrentNav find tables with class leftNav1, add the class leftNavSelected,
			// then find anchor tags with class leftNav1 and add class leftNavSelected
			$(this).find("table.leftNav1").addClass("leftNavSelected").find("a.leftNav1").addClass("leftNavSelected");
		});
	});	
	
	// For tables with class leftNav, add class leftNavShown. This will display the left nav table, which is hidden initially in the CSS 
	// while the above script runs to eliminate the "flicker" of leftNav2 items showing and then disappearing based on how they are treated in the script above.
	$("table.leftNav").addClass("leftNavShown");
}

function removeAnchors(){
	$(".removeAnchor a").removeAttr("href").removeAttr("onclick");


}

/* Fix Scroll Issues with Ribbon*/
//set top padding of the workspace to the height of the ribbon
function setTopPadding() {
   var wrkElem = document.getElementById('s4-workspace');
   var ribHeight = document.getElementById('s4-ribbonrow').offsetHeight;
   if (window.location.search.match("[?&]IsDlg=1")) {
      //margin works better for dialogs b/c of scrollbars
      wrkElem.style.marginTop = ribHeight + 'px';
      wrkElem.style.paddingTop = '0px';
   }
   else {
     //padding works better for the main window
     wrkElem.style.paddingTop = ribHeight + 'px';
   }
}

// bind top padding reset to ribbon resize event so that the page always lays out correctly.
ExecuteOrDelayUntilScriptLoaded(function () { SP.UI.Workspace.add_resized(setTopPadding); }, "init.js");

/*End Scroll Fix*/
