var FCCCTextResizer = {
	cookieName: "FCCCTextSize",
	
	containerElementID: null,
	
	_textSizes: ["50%", "75%", "100%", "125%", "150%"],
	
	_currentSizeIndex: 2,
	
	_initialize: function(containerID) {
		this._generateTextSizes(50, 300, 25);
		this.containerElementID = containerID.toString();
		this._readCookie();
		
		var oldOnLoad = window.onload;
		var myOnLoad = function() { FCCCTextResizer._apply(); };
		
		if (oldOnLoad)
		{
			if (typeof oldOnLoad == "function")
			{
				window.onload = function() {
					oldOnLoad();
					myOnLoad();
				};
			}
			else
			{
				window.onload = function() {
					eval(oldOnLoad);
					myOnLoad();
				};
			}
		}
		else
		{
			window.onload = myOnLoad;
		}
	},
	
	_generateTextSizes: function(from, to, by) {
		var result = new Array();
		var hundredPercentIndex = -1;
		
		if (to < from)
		{
			var temp = from;
			from = to;
			to = temp;
		}
		
		by = Math.abs(by);
		
		result.push(from + "%");
		
		for (var step = from + by; step < to; step += by)
		{
			result.push(step + "%");
			if (step < 100 && (step + by) > 100)
			{
				result.push("100%");
				this._currentSizeIndex = result.length - 1;
			}
			else if (step == 100)
			{
				this._currentSizeIndex = result.length - 1;
			}
		}
		
		result.push(to + "%");
		
		this._textSizes = result;
	},
	
	_readCookie: function() {
		var cookies = window.document.cookie.split("; ");
		var bFoundCookie = false;
		
		for (var index = 0; index < cookies.length; index++)
		{
			if (cookies[index].indexOf(this.cookieName) == 0)
			{
				this._currentSizeIndex = Number(cookies[index].substr(this.cookieName.length + 1));
				//window.alert("Cookie value for " + this.cookieName + " = " + this._currentSizeIndex);
				break;
			}
		}
	},
	
	_storeCookie: function() {
		window.document.cookie = this.cookieName + "=" + this._currentSizeIndex + "; path=/";
	},
	
	_apply: function() {
		var container = window.document.getElementById(this.containerElementID);
		
		container.style.fontSize = this._textSizes[this._currentSizeIndex];
	},
	
	increment: function() {
		var bChanged = false;
		
		if (this._currentSizeIndex >= this._textSizes.length - 1)
		{
			this._currentSizeIndex = this._textSizes.length - 1;
		}
		else
		{
			this._currentSizeIndex++;
			bChanged = true;
		}
		
		this._storeCookie();
		
		if (bChanged)
		{
			this._apply();
		}
	},
	
	reset: function() {
		var hundredPercentIndex = this._textSizes.indexOf("100%");
		
		if (hundredPercentIndex != -1 && this._currentSizeIndex != hundredPercentIndex)
		{
			this._currentSizeIndex = hundredPercentIndex;
			this._storeCookie();
			this._apply();
		}
	},
	
	decrement: function() {
		var bChanged = false;
				
		if (this._currentSizeIndex <= 0)
		{
			this._currentSizeIndex = 0;
		}
		else
		{
			this._currentSizeIndex--;
			bChanged = true;
		}

		this._storeCookie();

		if (bChanged)
		{
			this._apply();
		}
	}
}

FCCCTextResizer._initialize("content");