//------------------------------------------------
// Global Variables
//------------------------------------------------
var str;
var tags;
var pixelArray =  new Array('10','11','14','16','18','20');
//var emArray =  new Array('0.7','0.9','1.0','1.5');
var initSize = 0;
var cookie_name = 'osler_font_size';
str = location.href;
tags = new Array('div', 'td', 'ul', 'strong', 'p', 'i', 'a', 'h1', 'em', 'font', 'span', 'tr', 'table', 'tbody', 'b', 'ol');

//for Mozilla browsers 
if (document.addEventListener) {
	document.addEventListener("DOMContentLoaded", init_font, false);
}

document.onreadystatechange = init_font;

/*Initializes the font sizing.
	Won't initialize until the page has loaded.*/
//Removed readyState = completed check - Not supported by Firefox
//added event handler, see above

function init_font()
{
		var cookie_font = getCookie(cookie_name);
		if(cookie_font)
		{
			initSize = cookie_font;
			changeFontSize(cookie_font,'px');
		}
}

function getCookie(NameOfCookie)
{ 
	if (document.cookie.length > 0)
	{ 
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1)
		{ 
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1) 
				end = document.cookie.length;
		return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return null;
}

function setCookie(NameOfCookie, value)
{ 
	var ExpireDate = new Date ();
	var expiredays = 30;
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) +
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie)
{ 
	if (getCookie(NameOfCookie)) 
	{
		document.cookie = NameOfCookie + "=" +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

//------------------------------------------------
// Main portion of the script, performs resizing
//------------------------------------------------
function fontSizer(inc,unit) 
{
	if (!document.getElementById) 
		return;
	var size = parseInt(initSize,10);
		size += inc;
   
    	
	if (size < 0 ) 
	{
	    size = 0;
	}
 
	if (size > pixelArray.length - 1) 
	{
		size = pixelArray.length - 1;
	}

 	setCookie(cookie_name,size);
	initSize = size;
	changeFontSize(size,unit);	
	
}
function changeFontSize(size,unit)
{
	//Gets all of the elements in the array starting from where the content block begins
	mainDiv = document.getElementById('res');
 
	if(mainDiv)
	{
		//Loops through the entire 'tags' array
		for (i = 0 ; i < tags.length ; i++ ) 
		{
			//Looks at the current tag, based on the position in the loop
				getallTags = mainDiv.getElementsByTagName(tags[i]);
				
				for (k = 0 ; k < getallTags.length ; k++)			
			//Checks to see if it is a subnav link, if it is, dont resize green and black tabs
			if(getallTags[k].className != 'subnav' && getallTags[k].id != 'subnavLink' && getallTags[k].className != 'subnavLink') 
			{
				//Resize all elements in the array on the page within "res" tags
				//getallTags[k].style.fontSize = (unit=='px') ? pixelArray[size]+unit: emArray[size]+unit;
				getallTags[k].style.fontSize = pixelArray[size]+unit;
			}			
		}
	}
}
