
var font =
{
	defaultFontSize: 1.0,
	currentFontSize: 0,
	increment: .1,
	max: 8,
	imagesDirectory: "images/site/",
	

	init: function()
	{	
		var fontsize = document.getElementById("textResize");
		var anchors = fontsize.getElementsByTagName("a");
		
		for (var i = 0; i < anchors.length; i++)
		{	
			switch(anchors[i].title)
			{	

				case "Smaller":
				
					anchors[i].onclick = font.down;
					break;
				
				case "Larger":

					anchors[i].onclick = font.up;
					
					break;
					
				default:
				
					anchors[i].onclick = font.reset;
			}
		}
		
		font.currentFontSize = readCookie('fontsizecookie');
		document.getElementById("mainWrap").style.fontSize = font.defaultFontSize + (font.currentFontSize * font.increment) + "em";
		return true;
	},
	
	up: function()
	{
		if (font.currentFontSize < font.max)
		{
			
			font.currentFontSize++;
			createCookie('fontsizecookie',font.currentFontSize);
			document.getElementById("mainWrap").style.fontSize = font.defaultFontSize + (font.currentFontSize * font.increment) + "em";
			
		}
		
		return false;
	},
	
	down: function()
	{
		if (font.currentFontSize > -font.max)
		{
			font.currentFontSize--;
			createCookie('fontsizecookie',font.currentFontSize);
			
			document.getElementById("mainWrap").style.fontSize = font.defaultFontSize + (font.currentFontSize * font.increment) + "em";
		}
		
		return false;
	},
	
	reset: function()
	{
		font.currentFontSize = 0;
		createCookie('fontsizecookie',font.currentFontSize);
		
		document.getElementById("mainWrap").style.fontSize = font.defaultFontSize + "em";
		
		
		return false;
	}
};


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();	
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function schedule(objectID, functionCall, iteration)
{
	if (iteration == null)
	{
		iteration = 0;
	}
	
	if (objectID == "window")
	{
		var oldonload = window.onload;
		
		if (typeof window.onload != "function")
		{
			window.onload = functionCall;
		}
		else
		{
			window.onload = function()
			{
				oldonload();
				functionCall();
			}
		}
	}
	else if (document.getElementById(objectID))
	{
		functionCall();
	}
	else if (iteration < 1000)
	{
		setTimeout(function(){schedule(objectID, functionCall, iteration + 1)}, 10);
	}
	
	return true;
}


schedule("window", font.init);
