// JavaScript Document

//variables for the text sizing feature.
var defaultTotalArticles = 7;//this value must be greater than or equal to the total number of articles on the one page with the most article blocks.
var totalArticles = defaultTotalArticles;
var defaultTextSize = 12;
var currentTextSize = defaultTextSize;

//variables for changing the left margin while using the text sizing feature.
var defaultTotalOrderedListsToIndent = 1;//this value must be greater than or equal to the total number of articles on the one page with the most article blocks.
var totalOrderedListsToIndent = defaultTotalOrderedListsToIndent;
var defaultLeftMarginValue = 10;
var leftMarginValue = defaultLeftMarginValue; 

//Intializes the text sizing feature. Called from dropmenu.js.
function initializeTextSizers() {
	var defaultTextSizeLink = document.getElementById("defaultTextSize");
	var decreaseTextBtn = document.getElementById("decreaseTextBtn");
	var increaseTextBtn = document.getElementById("increaseTextBtn");
	
	defaultTextSizeLink.onclick = resetTextSize;
	decreaseTextBtn.onclick = textMinimize;
	increaseTextBtn.onclick = textMaximize;	
}

//text sizing functions (3 functions).
function resetTextSize() {
	
	if(currentTextSize < defaultTextSize || currentTextSize > defaultTextSize) {	
		for (var i=1; i <= totalArticles; i++) {	
			var article = document.getElementById("article" + i);		
			
			if (article != null) {
				article.style.fontSize = defaultTextSize + "px";
			}
			else {
				totalArticles = 0;
			}
		}
		
		for (var j=1; j <= totalOrderedListsToIndent; j++) {
			var orderedListToIndent = document.getElementById("orderedListToIndent" + j);
			
			if (orderedListToIndent != null) {
				orderedListToIndent.style.marginLeft = defaultLeftMarginValue + "px";
			}
			else {
				totalOrderedListsToIndent = 0;	
			}
		}
		
		currentTextSize = defaultTextSize;
		totalArticles = defaultTotalArticles;
		
		leftMarginValue = defaultLeftMarginValue;
		totalOrderedListsToIndent = defaultTotalOrderedListsToIndent;
	}
}

function textMinimize() {
	
	if(currentTextSize > 8) {	
		for (var i=1; i <= totalArticles; i++) {	
			var article = document.getElementById("article" + i);		
			
			if (article != null) {
				article.style.fontSize = currentTextSize - 2 + "px";		
			}
			else {
				totalArticles = 0;
			}
		}
		
		for (var j=1; j <= totalOrderedListsToIndent; j++) {
			var orderedListToIndent = document.getElementById("orderedListToIndent" + j);
			
			if (orderedListToIndent != null) {
				orderedListToIndent.style.marginLeft = leftMarginValue - 2 + "px";
			}
			else {
				totalOrderedListsToIndent = 0;	
			}
		}
		
		currentTextSize -= 2;
		totalArticles = defaultTotalArticles;
		
		leftMarginValue -= 2;
		totalOrderedListsToIndent = defaultTotalOrderedListsToIndent;
	}
}

function textMaximize() {
	
	if(currentTextSize < 24) {
		for (var i=1; i <= totalArticles; i++) {	
			var article = document.getElementById("article" + i);		
			
			if (article != null) {
				article.style.fontSize = currentTextSize + 2 + "px";
			}
			else {
				totalArticles = 0;
			}
		}
		
		for (var j=1; j <= totalOrderedListsToIndent; j++) {
			var orderedListToIndent = document.getElementById("orderedListToIndent" + j);
			
			if (orderedListToIndent != null) {
				orderedListToIndent.style.marginLeft = leftMarginValue + 2 + "px";
			}
			else {
				totalOrderedListsToIndent = 0;	
			}
		}
		
		currentTextSize += 2;
		totalArticles = defaultTotalArticles;
		
		leftMarginValue += 2;
		totalOrderedListsToIndent = defaultTotalOrderedListsToIndent;
	}
}