function setFontSizeSelect() {

	if (typeof(Storage) !== "undefined") {

		switch (localStorage.bodyFontSize) {

			case "1.236em":
				document.getElementById("fontSizeSelect").selectedIndex = 0;
				break;

			case "1.382em":
				document.getElementById("fontSizeSelect").selectedIndex = 1;
				break;

			case "small":
				document.getElementById("fontSizeSelect").selectedIndex = 2;
				break;

			case "medium":
				document.getElementById("fontSizeSelect").selectedIndex = 3;
				break;

			case "large":
				document.getElementById("fontSizeSelect").selectedIndex = 4;
				break;

			case "x-large":
				document.getElementById("fontSizeSelect").selectedIndex = 5;
				break;

			case "xx-large":
				document.getElementById("fontSizeSelect").selectedIndex = 6;
				break;

			case "xxx-large":
				document.getElementById("fontSizeSelect").selectedIndex = 7;
				break;

		}
	}
}

function setWidthsTo(fontSizeWidth) {

	document.getElementsByTagName("header")[0].style.width = fontSizeWidth;
	document.getElementById("main").style.width = fontSizeWidth;
	//document.getElementsByTagName("nav")[0].style.width = fontSizeWidth;
	//document.getElementById("ref").style.width = fontSizeWidth;
	document.getElementsByTagName("footer")[0].style.width = fontSizeWidth;

}

function setWidths() {

	if (typeof(Storage) !== "undefined") {

		// set margins and widths depending on
		// localStorage.bodyFontSize
		switch (localStorage.bodyFontSize) {

			// Day default
			case "1.236em":

				switch (true) {

					// iPhone 4 & 5 Portrait (320) & smaller
					case (window.innerWidth < 350):
						setWidthsTo("13em");
						break;

					// iPhone 6 Portrait (375)
					case (window.innerWidth >= 350) && (window.innerWidth < 400):
						setWidthsTo("15.5em");
						break;

					// iPhone 6 Plus Portrait (414)
					case (window.innerWidth >= 400) && (window.innerWidth < 450):
						setWidthsTo("18em");
						break;

					// iPhone 4 Landscape (480)
					case (window.innerWidth >= 450) && (window.innerWidth < 500):
						setWidthsTo("20.5em");
						break;

					case (window.innerWidth >= 500) && (window.innerWidth < 550):
						setWidthsTo("23em");
						break;

					// iPhone 5 Landscape (568)
					case (window.innerWidth >= 550) && (window.innerWidth < 600):
						setWidthsTo("25.5em");
						break;

					case (window.innerWidth >= 600) && (window.innerWidth < 650):
						setWidthsTo("28em");
						break;

					// iPhone 6 Landscape (667)
					//case (window.innerWidth >= 650) && (window.innerWidth < 700):
						//setWidthsTo("28.625em");
						//break;

					default:
						setWidthsTo(defaultWidth);
				}

				break;

			// Night default
			case "1.382em":

				switch (true) {

					// iPhone 4 & 5 Portrait (320) & smaller
					case (window.innerWidth < 350):
						setWidthsTo("12em");
						break;

					// iPhone 6 Portrait (375)
					case (window.innerWidth >= 350) && (window.innerWidth < 400):
						setWidthsTo("14.25em");
						break;

					// iPhone 6 Plus Portrait (414)
					case (window.innerWidth >= 400) && (window.innerWidth < 450):
						setWidthsTo("16.5em");
						break;

					// iPhone 4 Landscape (480)
					case (window.innerWidth >= 450) && (window.innerWidth < 500):
						setWidthsTo("18.75em");
						break;

					case (window.innerWidth >= 500) && (window.innerWidth < 550):
						setWidthsTo("21em");
						break;

					// iPhone 5 Landscape (568)
					case (window.innerWidth >= 550) && (window.innerWidth < 600):
						setWidthsTo("23.25em");
						break;

					case (window.innerWidth >= 600) && (window.innerWidth < 650):
						setWidthsTo("25.5em");
						break;

					// iPhone 6 Landscape (667)
					case (window.innerWidth >= 650) && (window.innerWidth < 700):
						setWidthsTo("27.75em");
						break;

					// iPhone 6 Plus Landscape (736)
					//case (window.innerWidth >= 700) && (window.innerWidth < 750):
						//setWidthsTo("30em");
						//break;

					default:
						setWidthsTo(defaultWidth);
				}

				break;

			case "small":

				switch (true) {

					// iPhone 4 & 5 Portrait (320) & smaller
					case (window.innerWidth < 350):
						setWidthsTo("20.75em");
						break;

					// iPhone 6 Portrait (375)
					case (window.innerWidth >= 350) && (window.innerWidth < 400):
						setWidthsTo("24.5em");
						break;

					// iPhone 6 Plus Portrait (414)
					case (window.innerWidth >= 400) && (window.innerWidth < 450):
						setWidthsTo("27em");
						break;

					// iPhone 4 Landscape (480)
						/*case (window.innerWidth >= 450) && (window.innerWidth < 500):
						setWidthsTo("18.75em");
						break;

					case (window.innerWidth >= 500) && (window.innerWidth < 550):
						setWidthsTo("21em");
						break;

					// iPhone 5 Landscape (568)
					case (window.innerWidth >= 550) && (window.innerWidth < 600):
						setWidthsTo("23.25em");
						break;

					case (window.innerWidth >= 600) && (window.innerWidth < 650):
						setWidthsTo("25.5em");
						break;

					// iPhone 6 Landscape (667)
					case (window.innerWidth >= 650) && (window.innerWidth < 700):
						setWidthsTo("27.75em");
						break;*/

					// iPhone 6 Plus Landscape (736)
					//case (window.innerWidth >= 700) && (window.innerWidth < 750):
						//setWidthsTo("30em");
						//break;

					default:
						setWidthsTo(defaultWidth);
				}

				break;

			case "medium":

				switch (true) {

					// iPhone 4 & 5 Portrait (320) & smaller
					case (window.innerWidth < 350):
						setWidthsTo("16.75em");
						break;

					// iPhone 6 Portrait (375)
					case (window.innerWidth >= 350) && (window.innerWidth < 400):
						setWidthsTo("19.75em");
						break;

					// iPhone 6 Plus Portrait (414)
					case (window.innerWidth >= 400) && (window.innerWidth < 450):
						setWidthsTo("22.25em");
						break;

					// iPhone 4 Landscape (480)
					case (window.innerWidth >= 450) && (window.innerWidth < 500):
						setWidthsTo("25.75em");
						break;

					case (window.innerWidth >= 500) && (window.innerWidth < 550):
						setWidthsTo("28.75em");
						break;

					// iPhone 5 Landscape (568)
						/*case (window.innerWidth >= 550) && (window.innerWidth < 600):
						setWidthsTo("23.25em");
						break;

					case (window.innerWidth >= 600) && (window.innerWidth < 650):
						setWidthsTo("25.5em");
						break;

					// iPhone 6 Landscape (667)
					case (window.innerWidth >= 650) && (window.innerWidth < 700):
						setWidthsTo("27.75em");
						break;*/

					// iPhone 6 Plus Landscape (736)
					//case (window.innerWidth >= 700) && (window.innerWidth < 750):
						//setWidthsTo("30em");
						//break;

					default:
						setWidthsTo(defaultWidth);
				}

				break;

			case "large":

				switch (true) {

					// iPhone 4 & 5 Portrait (320) & smaller
					case (window.innerWidth < 350):
						setWidthsTo("15em");
						break;

					// iPhone 6 Portrait (375)
					case (window.innerWidth >= 350) && (window.innerWidth < 400):
						setWidthsTo("17.75em");
						break;

					// iPhone 6 Plus Portrait (414)
					case (window.innerWidth >= 400) && (window.innerWidth < 450):
						setWidthsTo("20em");
						break;

					// iPhone 4 Landscape (480)
					case (window.innerWidth >= 450) && (window.innerWidth < 500):
						setWidthsTo("23.25em");
						break;

					case (window.innerWidth >= 500) && (window.innerWidth < 550):
						setWidthsTo("25.25em");
						break;

					// iPhone 5 Landscape (568)
					case (window.innerWidth >= 550) && (window.innerWidth < 600):
						setWidthsTo("28.75em");
						break;

					/*case (window.innerWidth >= 600) && (window.innerWidth < 650):
						setWidthsTo("25.5em");
						break;

					// iPhone 6 Landscape (667)
					case (window.innerWidth >= 650) && (window.innerWidth < 700):
						setWidthsTo("27.75em");
						break;*/

					// iPhone 6 Plus Landscape (736)
					//case (window.innerWidth >= 700) && (window.innerWidth < 750):
						//setWidthsTo("30em");
						//break;

					default:
						setWidthsTo(defaultWidth);
				}

				break;

			case "x-large":

				switch (true) {

					// iPhone 4 & 5 Portrait (320) & smaller
					case (window.innerWidth < 350):
						setWidthsTo("11em");
						break;

					// iPhone 6 Portrait (375)
					case (window.innerWidth >= 350) && (window.innerWidth < 400):
						setWidthsTo("13em");
						break;

					// iPhone 6 Plus Portrait (414)
					case (window.innerWidth >= 400) && (window.innerWidth < 450):
						setWidthsTo("14.5em");
						break;

					// iPhone 4 Landscape (480)
					case (window.innerWidth >= 450) && (window.innerWidth < 500):
						setWidthsTo("17em");
						break;

					case (window.innerWidth >= 500) && (window.innerWidth < 550):
						setWidthsTo("18.75em");
						break;

					// iPhone 5 Landscape (568)
					case (window.innerWidth >= 550) && (window.innerWidth < 600):
						setWidthsTo("21em");
						break;

					case (window.innerWidth >= 600) && (window.innerWidth < 650):
						setWidthsTo("23em");
						break;

					// iPhone 6 Landscape (667)
					case (window.innerWidth >= 650) && (window.innerWidth < 700):
						setWidthsTo("25em");
						break;

					// iPhone 6 Plus Landscape (736)
					case (window.innerWidth >= 700) && (window.innerWidth < 750):
						setWidthsTo("27.5em");
						break;

					// iPad Air Portrait (768)
					case (window.innerWidth >= 750) && (window.innerWidth < 800):
						setWidthsTo("29em");
						break;

					default:
						setWidthsTo(defaultWidth);
				}

				break;

			case "xx-large":

				switch (true) {

					// iPhone 4 & 5 Portrait (320) & smaller
					case (window.innerWidth < 350):
						setWidthsTo("7.5em");
						break;

					// iPhone 6 Portrait (375)
					case (window.innerWidth >= 350) && (window.innerWidth < 400):
						setWidthsTo("9em");
						break;

					// iPhone 6 Plus Portrait (414)
					case (window.innerWidth >= 400) && (window.innerWidth < 450):
						setWidthsTo("10.5em");
						break;

					// iPhone 4 Landscape (480)
					case (window.innerWidth >= 450) && (window.innerWidth < 500):
						setWidthsTo("12em");
						break;

					case (window.innerWidth >= 500) && (window.innerWidth < 550):
						setWidthsTo("13.5em");
						break;

					// iPhone 5 Landscape (568)
					case (window.innerWidth >= 550) && (window.innerWidth < 600):
						setWidthsTo("15em");
						break;

					case (window.innerWidth >= 600) && (window.innerWidth < 650):
						setWidthsTo("16.5em");
						break;

					// iPhone 6 Landscape (667)
					case (window.innerWidth >= 650) && (window.innerWidth < 700):
						setWidthsTo("18em");
						break;

					// iPhone 6 Plus Landscape (736)
					case (window.innerWidth >= 700) && (window.innerWidth < 750):
						setWidthsTo("19.5em");
						break;

					// iPad Air Portrait (768)
					case (window.innerWidth >= 750) && (window.innerWidth < 800):
						setWidthsTo("21em");
						break;

					case (window.innerWidth >= 800) && (window.innerWidth < 850):
						setWidthsTo("22.5em");
						break;

					case (window.innerWidth >= 850) && (window.innerWidth < 900):
						setWidthsTo("24em");
						break;

					case (window.innerWidth >= 900) && (window.innerWidth < 950):
						setWidthsTo("25.5em");
						break;

					case (window.innerWidth >= 950) && (window.innerWidth < 1000):
						setWidthsTo("27em");
						break;

					// iPad Air Landscape (1024)
					case (window.innerWidth >= 1000) && (window.innerWidth < 1050):
						setWidthsTo("28.5em");
						break;

					default:
						setWidthsTo(defaultWidth);
				}

			case "xxx-large":

				switch (true) {

					// iPhone 4 & 5 Portrait (320) & smaller
					case (window.innerWidth < 350):
						setWidthsTo("5.5em");
						break;

					// iPhone 6 Portrait (375)
					case (window.innerWidth >= 350) && (window.innerWidth < 380):
						setWidthsTo("6.5em");
						break;

					// iPhone 12… (390)
					// iPhone 15… (393)
					// iPhone 17… (402)
					case (window.innerWidth >= 380) && (window.innerWidth < 410):
						setWidthsTo("6.75em");
						break;

					// iPhone 6 Plus Portrait (414)
					// iPhone Air (420)
					case (window.innerWidth >= 410) && (window.innerWidth < 425):
						setWidthsTo("7em");
						break;

					// iPhone 14 Plus (428)
					// iPhone 16 Plus (430)
					// iPhone 17 Pro Max (440)
					case (window.innerWidth >= 425) && (window.innerWidth < 450):
						setWidthsTo("7.5em");
						break;

					// iPhone 4 Landscape (480)
					case (window.innerWidth >= 450) && (window.innerWidth < 500):
						setWidthsTo("8.25em");
						break;

					case (window.innerWidth >= 500) && (window.innerWidth < 550):
						setWidthsTo("9em");
						break;

					// iPhone 5 Landscape (568)
					case (window.innerWidth >= 550) && (window.innerWidth < 600):
						setWidthsTo("10em");
						break;

					case (window.innerWidth >= 600) && (window.innerWidth < 650):
						setWidthsTo("11em");
						break;

					// iPhone 6 Landscape (667)
					case (window.innerWidth >= 650) && (window.innerWidth < 700):
						setWidthsTo("12em");
						break;

					// iPhone 6 Plus Landscape (736)
					case (window.innerWidth >= 700) && (window.innerWidth < 750):
						setWidthsTo("13em");
						break;

					// iPad Air Portrait (768)
					case (window.innerWidth >= 750) && (window.innerWidth < 800):
						setWidthsTo("14em");
						break;

					// iPhone X… Landscape (812)
					case (window.innerWidth >= 800) && (window.innerWidth < 825):
						setWidthsTo("15em");
						break;

					// iPhone 14… Landscape (844)
					// iPhone 15… Landscape (852)
					case (window.innerWidth >= 825) && (window.innerWidth < 865):
						setWidthsTo("15.5em");
						break;

					// iPhone 17… Landscape (874)
					case (window.innerWidth >= 865) && (window.innerWidth < 885):
						setWidthsTo("15.75em");
						break;

					// iPhone XR Landscape (896)
					// iPhone Air Landscape (912)
					case (window.innerWidth >= 885) && (window.innerWidth < 920):
						setWidthsTo("16.5em");
						break;

					// iPhone 14 Plus… Landscape (926)
					// iPhone 15 Plus… Landscape (932)
					case (window.innerWidth >= 920) && (window.innerWidth < 950):
						setWidthsTo("17em");
						break;

					// iPhone 17 Pro Max Landscape (956)
					case (window.innerWidth >= 950) && (window.innerWidth < 1000):
						setWidthsTo("17.5em");
						break;

					// iPad Air Landscape (1024)
					case (window.innerWidth >= 1000) && (window.innerWidth < 1050):
						setWidthsTo("18em");
						break;

					default:
						setWidthsTo("20em");
				}

				break;

		}
	}
}

function delayedSetWidths() {
	setTimeout(setWidths, 100)
}

function changeFontSize(selectTag) {

	if (typeof(Storage) !== "undefined") {

		// set localStorage.bodyFontSize according to selected value
		if (selectTag.options[selectTag.selectedIndex].text == "☀️ default size") {
			localStorage.bodyFontSize = "1.236em";
		}
		else if (selectTag.options[selectTag.selectedIndex].text == "🌙 default size") {
			localStorage.bodyFontSize = "1.382em";
		}
		else {
			localStorage.bodyFontSize = selectTag.options[selectTag.selectedIndex].text;
		}

		setWidths();

		document.body.style.fontSize = localStorage.bodyFontSize;

	}
}

// on page load
if (typeof(Storage) !== "undefined") { // check browser support for localStorage

	// if necessary, initialize localStorage.bodyFontSize
	if (!localStorage.bodyFontSize) {
		if (localStorage.theme == "night") {
			localStorage.bodyFontSize = "1.382em";
		}
		else {
			localStorage.bodyFontSize = "1.236em";
		}
	}

	var defaultWidth = "30em";

	setWidths();

	document.body.style.fontSize = localStorage.bodyFontSize;

	setFontSizeSelect();

	window.addEventListener("resize", delayedSetWidths);

}
