function layoutFixes_fixSectionsWithGradients() {
	var sectionHeaders = document.getElementsByClassName('section-header');
	for (var i = 0; i < sectionHeaders.length; i++) {
		// get widths of all section header divs, except for the first one
		var iSectionHeaderWidth = sectionHeaders[i].clientWidth;
		var iSectionHeaderInflectionWidth = sectionHeaders[i].getElementsByClassName('section-header-inflection')[0].clientWidth; // 12
		var iSectionHeaderH2Width = sectionHeaders[i].getElementsByTagName('h2')[0].clientWidth;

		//	set the first section header div's width the calculated value
		sectionHeaders[i].getElementsByClassName('section-header-start')[0].style.width = (iSectionHeaderWidth - iSectionHeaderH2Width - iSectionHeaderInflectionWidth) + 'px';
	}
}

function layoutFixes_fixSectionsWithMenus() {
	// get the navigation item selected on window load
	var oNavigationItemSelectedOnWindowLoad = layoutFixes_getNavigationItemByHref(window.location.href);

	// process each section with menu
	var oaSectionsWithMenu = document.getElementsByClassName('section-with-menu');
	for (var i = 0; i < oaSectionsWithMenu.length; i++) {
		var iSelectedNavigationItemIndex = -1; // initialize selected navigation item index

		var oaSectionsWithMenuNavigationItems = oaSectionsWithMenu[i].getElementsByClassName('section-with-menu-navigation')[0].getElementsByTagName('li');
		var oaSectionsWithMenuTexts = oaSectionsWithMenu[i].getElementsByClassName('section-main')[0].getElementsByClassName('section-text');

		for (var j = 0; j < oaSectionsWithMenuNavigationItems.length; j++) {
			// add click event to the current navigation item
			oaSectionsWithMenuNavigationItems[j].onclick = layoutFixes_sectionWithMenuNavigationItemClick;

			// hide the current text
			if (oaSectionsWithMenuTexts[j]) {
				oaSectionsWithMenuTexts[j].style.display = 'none';
			}

			// save the index of the menu item selected on window load
			if (oNavigationItemSelectedOnWindowLoad == oaSectionsWithMenuNavigationItems[j]) {
				iSelectedNavigationItemIndex = j;
			}
		}

		// if no item was selected on window load, pick the first one
		if (iSelectedNavigationItemIndex == -1) {
			iSelectedNavigationItemIndex = 0;
		}

		// select the navigation item, show the associated text
		oaSectionsWithMenuNavigationItems[iSelectedNavigationItemIndex].className = 'selected';
		oaSectionsWithMenuTexts[iSelectedNavigationItemIndex].style.display = 'block';
	}
}

function layoutFixes_sectionWithMenuNavigationItemClick() {
	if (!this.hasClassName('selected')) {
		var oaSectionsWithMenuNavigationItems = this.parentNode.getElementsByTagName('li');
		var oaSectionsWithMenuTexts = this.parentNode.parentNode.getElementsByClassName('section-main')[0].getElementsByClassName('section-text');
		for (var k = 0; k < oaSectionsWithMenuNavigationItems.length; k++) {
			if (this == oaSectionsWithMenuNavigationItems[k]) {
				// select current navigation item and show the text
				oaSectionsWithMenuNavigationItems[k].className = 'selected';
				oaSectionsWithMenuTexts[k].style.display = 'block';
			} else {
				// deselect navigation item and hide the text
				oaSectionsWithMenuNavigationItems[k].className = '';
				oaSectionsWithMenuTexts[k].style.display = 'none';
			}
		}
	}
}

function layoutFixes_getNavigationItemByHref(sLocationHref) {
		var iHashPosition = sLocationHref.indexOf('#');
		if (iHashPosition > 0) {
			var sSectionName = sLocationHref.substr(iHashPosition + 1, sLocationHref.length - iHashPosition);
			return document.getElementById(sSectionName);
		} else {
			return null;
		}
}

function layoutFixes_showFeedBurnerWidget() {
	if (document.getElementById('feedburner-readers')) {
		document.getElementById('feedburner-readers').getElementsByTagName('img')[0].src = 'http://feeds.feedburner.com/~fc/snowcat?bg=800000&amp;fg=000000&amp;anim=1';
	}
}

function layoutFixes_AddSwmiLinksClick() {
	// get current page href to compare with the swmi links
	var sCurrentPageHref = window.location.href;
	if (sCurrentPageHref.indexOf('#') > -1) {
		sCurrentPageHref = sCurrentPageHref.substring(0, sCurrentPageHref.indexOf('#'));
	}

	var oaLinks = document.getElementsByTagName('a');
	for (var i = 0; i < oaLinks.length; i++) {
		if (oaLinks[i].href.search('#swmi-') > -1) {
			// add special onclick only for links pointing to the current page
			if (oaLinks[i].href.substring(0, oaLinks[i].href.indexOf('#')) == sCurrentPageHref) {
				oaLinks[i].onclick = layoutFixes_SwmiLinkClick;
			}
		}
	}
}

function layoutFixes_SwmiLinkClick() {
	var oNavigationItemLi = layoutFixes_getNavigationItemByHref(this.href);
	if (oNavigationItemLi) {
		oNavigationItemLi.onclick();
	}
}

function layoutFixes_init() {
	layoutFixes_fixSectionsWithGradients();
	layoutFixes_fixSectionsWithMenus();
	layoutFixes_showFeedBurnerWidget();
	layoutFixes_AddSwmiLinksClick();
}