var fontScaling = new clsFontScaling;

Math.roundTo = function _roundTo(value, dec)
{
	var mag = Math.pow(10, dec);
	return	Math.round(value * mag) / mag;
};

fontScaling.setBaseFontSize();

onDomReady(addEvent(window, "resize", fontScaling.setBaseFontSize, true));

function clsFontScaling()
{
	this.minFontScale = 65;
	this.maxFontScale = 95;

	this.minContentWidth = 740;
	this.maxContentWidth = 1400;

	this.contentMargins = 66;

	this.setBaseFontSize = _setBaseFontSize;
	this.cc_fontScale = _cc_fontScale;

	this.baseRule = getCSSRule('#t_allContent');
	this.contentRule = getCSSRule('.t_columnWrapper');
	
	function _setBaseFontSize()
	{
		var contentWidth = getInnerWidth() - fontScaling.contentMargins;
		
		if (contentWidth < fontScaling.minContentWidth)
		{
			contentWidth = fontScaling.minContentWidth;
		}
		if (contentWidth > fontScaling.maxContentWidth)
		{
			contentWidth = fontScaling.maxContentWidth;
		}
		
		//Calculate new scales
		fontScaling.scalePercentage = (contentWidth - fontScaling.minContentWidth) / (fontScaling.maxContentWidth - fontScaling.minContentWidth);
		
		fontScaling.ccScale = fontScaling.cc_fontScale();
		fontScaling.newScale = (fontScaling.maxFontScale - fontScaling.minFontScale) * fontScaling.scalePercentage + fontScaling.minFontScale;
		fontScaling.newScale = (fontScaling.newScale / fontScaling.ccScale * 100);

		//Apply new scales
		fontScaling.baseRule.style.fontSize = fontScaling.ccScale + "%";
		fontScaling.contentRule.style.fontSize = fontScaling.newScale + "%";
	}
	
	function _cc_fontScale()
	{
		if (window.innerWidth)
			{
			 width = window.innerWidth
			 height = window.innerHeight
			}
		else
			{if (document.documentElement.clientWidth) 
				{if (document.documentElement.clientWidth > 0) 
					{prefix = document.documentElement} 
				else 
					{prefix = document.body}
				} 
			 else 
				{prefix = document.body}
			 width = prefix.clientWidth
			 height = prefix.clientHeight
			}
		WidthSize = width / 1150
		HeightSize = height / 688
		BaseFontSize = ((WidthSize < HeightSize) ? WidthSize  : HeightSize) * 140
	 // alert ("Width : " + width + "px; " + "BaseFontSize : " + BaseFontSize + "%") 
		if (BaseFontSize < 100) BaseFontSize = 100
	
		return BaseFontSize;
	// alert ("Document.Writeln ()s complete ...")
	}
	
}

function getInnerWidth()
{
	if (typeof window.innerWidth != 'undefined')
	{
		return window.innerWidth;
	}
	if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0)
	{
		return document.documentElement.clientWidth;
	}		 
	else
	{
		return document.getElementsByTagName('body').clientWidth;
	}
}

function getInnerHeight()
{
	if (typeof window.innerHeight != 'undefined')
	{
		return window.innerHeight
	}
	if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientHeight != 'undefined' && document.documentElement.clientHeight != 0)
	{
		return document.documentElement.clientHeight;
	}		 
	else
	{
		return document.getElementsByTagName('body')[0].clientHeight;
	}
}