
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FILE LOCATION: /2008_templates/scripts/textSizer.js
DESCRIPTION: Text sizer control script
DATE of LAST EDIT: August 28, 2008 
CHANGE LOG: 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

// 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 mainContent = document.getElementById("content");
	var smallerLink = document.getElementById("smaller");
	var biggerLink = document.getElementById("bigger");
	
	if (cookie == "-2") {
		size = -2;
		mainContent.style.fontSize = "0.8333em";
		mainContent.style.lineHeight = "1.8em";
		// Disable the "Decrease Text Size" icon link
		smallerLink.removeAttribute("href");
		// Set the "Decrease Text Size" icon to grey
		smallerLink.firstChild.src = "/images/textSizer/minusGrey.gif";
	}	
	if (cookie == "-1") {
		size = -1;
		mainContent.style.fontSize = "0.9167em";
		mainContent.style.lineHeight = "1.6364em"
	}	
	if (cookie == "1") {
		size = 1;
		mainContent.style.fontSize = "1.0833em";
		mainContent.style.lineHeight = "1.3846em";
	}	
	if (cookie == "2") {
		size = 2;
		mainContent.style.fontSize = "1.1667em";
		mainContent.style.lineHeight = "1.2857em";
		// Disable the "Decrease Text Size" icon link
		biggerLink.removeAttribute("href");
		// Set the "Decrease Text Size" icon to grey
		biggerLink.firstChild.src = "/images/textSizer/plusGrey.gif";
	}	
}
	

function textSize(obj) {
	// Preload the greyed out images
	if (document.images) {
    img1 = new Image();
		img1.src = "/images/textSizer/minusGrey.gif";
		img2 = new Image();
		img2.src = "/images/textSizer/plusGrey.gif";
	}
	
	// Declare the content areas
	var mainContent = document.getElementById("content");
	// Declare the incremation values
	var mc_increment = 0.0833;
		
	// Get (or set) the font size
	var mc_currentSize = parseFloat(mainContent.style.fontSize);

	if (!mc_currentSize) {
		mc_currentSize = 1; // same as the size declare in fonts.css
	}

	//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
			mainContent.style.fontSize = (mc_currentSize - mc_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 = "/images/textSizer/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 = "/images/textSizer/minusGrey.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
			mainContent.style.fontSize = (mc_currentSize + mc_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 = "/images/textSizer/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 = "/images/textSizer/plusGrey.gif";
			}
		}
	}
	return true;
}
