// A global variable to keep track of the font size (-2,-1,0,1,2)
var size = 0;

function initFontSize() {
	var cookie = readCookie('bcfontsize');
	
	var headerContent = document.getElementById("header");
	var navcolumnContent = document.getElementById("nav-col"); 
	var contentContent = document.getElementById("content");
	var footerContent = document.getElementById("footer"); 
	var smallerLink = document.getElementById("smaller");
	var biggerLink = document.getElementById("bigger");
	
	if (cookie == -2) {	
		size = -2;
		headerContent.style.fontSize = "0.9em";
		navcolumnContent.style.fontSize = "1em";
		contentContent.style.fontSize = "0.9em";
		footerContent.style.fontSize = "0.88em";
		// Disable the "Decrease Text Size" icon link
		smallerLink.removeAttribute('href');
		// Set the "Decrease Text Size" icon to grey
		smallerLink.firstChild.src = "/shared/images/b_minus_grey.gif";
	}	
	if (cookie == -1) {	
		size = -1;
		headerContent.style.fontSize = "0.95em";
		navcolumnContent.style.fontSize = "1.05em";
		contentContent.style.fontSize = "1em";
		footerContent.style.fontSize = "0.89em";
	}	
	if (cookie == 1) {	
		size = 1;
		headerContent.style.fontSize = "1.05em";
		navcolumnContent.style.fontSize = "1.15em";
		contentContent.style.fontSize = "1.2em";
		footerContent.style.fontSize = "0.91em";
	}	
	if (cookie == 2) {	
		size = 2;
		headerContent.style.fontSize = "1.1em";
		navcolumnContent.style.fontSize = "1.2em";
		contentContent.style.fontSize = "1.3em";
		footerContent.style.fontSize = "0.92em";
		// Disable the "Decrease Text Size" icon link
		biggerLink.removeAttribute('href');
		// Set the "Decrease Text Size" icon to grey
		biggerLink.firstChild.src = "/shared/images/b_plus_grey.gif";
	}	
}

function textSize(obj)
{
	// Preload the greyed out images
	if (document.images) {
    img1 = new Image();
    img1.src = "/shared/images/b_minus_grey.gif";
		img2 = new Image();
    img2.src = "/shared/images/b_plus_grey.gif";
	}
	
	// Declare the content areas
	var headerContent = document.getElementById("header");
	var navcolumnContent = document.getElementById("nav-col"); 
	var contentContent = document.getElementById("content");
	var footerContent = document.getElementById("footer"); 
	// Declare the incremation values
	var hc_increment = 0.05; 
	var ncc_increment = 0.05; 
	var cc_increment = 0.1;
	var fc_increment = 0.01;
		
	// Get (or set) the font size
	var hc_currentSize = parseFloat(headerContent.style.fontSize);
	var ncc_currentSize = parseFloat(navcolumnContent.style.fontSize);
	var cc_currentSize = parseFloat(contentContent.style.fontSize);
	var fc_currentSize = parseFloat(footerContent.style.fontSize)

	if (!hc_currentSize) {
 		hc_currentSize = 1; 
	}
	if (!ncc_currentSize) {
 		ncc_currentSize = 1.1; 
	}
	if (!cc_currentSize) {
		cc_currentSize = 1.1;
	}
	if (!fc_currentSize) {
		fc_currentSize = 0.9;
	}
	//Handle text sizing
	// If the "Decrease Text Size" icon is clicked
	if (obj.id == "smaller")
	{
		// If we haven't reached the lower size limit of -2
		if (size > -2) {
			// Decrease the size of text
			headerContent.style.fontSize = (hc_currentSize - hc_increment) + "em";
			navcolumnContent.style.fontSize = (ncc_currentSize - ncc_increment) + "em";
			contentContent.style.fontSize = (cc_currentSize - cc_increment) + "em";
			footerContent.style.fontSize = (fc_currentSize - fc_increment) + "em";
			// Decriment the size tracker
			size -= 1;
			// Make sure the "Increase Text Size" icon link is active
			obj.nextSibling.setAttribute('href', '#');
			// and make sure the "Increase Text Size" icon is blue
			obj.nextSibling.firstChild.src = "/shared/images/b_plus.gif";
			//alert(size);
			// Set the size in a cookie
			createCookie('bcfontsize',size,'1');
			// If we have reaced the lower size limit of -2
			if (size == -2 ) {
				// Disable the "Decrease Text Size" icon link
				obj.removeAttribute('href');
				// Set the "Decrease Text Size" icon to grey
				obj.firstChild.src = "/shared/images/b_minus_grey.gif";
			}
		}
	}
	// If the "Increase Text Size" icon is clicked
	else if (obj.id == "bigger")
	{
		// If we haven't reached the upper size limit of 2
		if (size < 2) {
			// Increase the size of the text
			headerContent.style.fontSize = (hc_currentSize + hc_increment) + "em";
			navcolumnContent.style.fontSize = (ncc_currentSize + ncc_increment) + "em";
			contentContent.style.fontSize = (cc_currentSize + cc_increment) + "em";
			footerContent.style.fontSize = (fc_currentSize + fc_increment) + "em";
			// Incriment the size tracker
			size += 1;
			// Make sure the "Decrease Text Size" icon link is active
			obj.previousSibling.setAttribute('href', '#');
			// and make sure the "Decrease Text Size" icon is blue
			obj.previousSibling.firstChild.src = "/shared/images/b_minus.gif";
			//alert(size);
			// Set the size in a cookie
			createCookie('bcfontsize',size,'1');
			// If we have reached the upper size limit if 2
			if (size == 2) {
				// Disable the "Increase Text Size" icon link
				obj.removeAttribute('href');
				// Set the "Increase Text Size" icon to grey
				obj.firstChild.src = "/shared/images/b_plus_grey.gif";
			}
		}
	}
	return true;
}
