/**************************************************************************************************/
/***
/***	TERNSTYLE.US TEMPLATE RESIZER JAVASCRIPT DOCUMENT
/***	-----------------------------------------------------------------------
/***	Written by Matthew Praetzel. Copyright (c) 2006-2008 Matthew Praetzel.
/***	-----------------------------------------------------------------------
/***	All Rights Reserved. Any use of these functions & scripts without written consent is prohibited.
/***
/**************************************************************************************************/

/*                                   **************************                                   */
/************************************   INITIALIZE VARIABLES   ************************************/
/*                                   **************************                                   */
var browser = getBrowserType();
var platform = getPlatformType();
var body_minimum_height = 335;
var elements_for_resize = new Array(new Array("body_background","height"),new Array("advertisement","height"),
									 new Array("tv_lines","height"),new Array("ad_background","height"),
									 new Array("border","height"),new Array("footer","top"),
									 new Array("body_container","height"));
/*                                   **************************                                   */
/************************************    BROWSER FUNCTIONS     ************************************/
/*                                   **************************                                   */
function getBrowserType()
{
	var browser_array = new Array("MSIE","NETSCAPE","FIREFOX","SAFARI");
	for(i=0;i<browser_array.length;i++)
	{
		var browserReg = new RegExp(browser_array[i],"");
		if(browserReg.test(navigator.userAgent.toUpperCase()))
		{
			var browser = browser_array[i];
			break;
		}
		else
		{
			var browser  = "other";
		}
	}
	return browser;
}
function getPlatformType()
{
	var platform_array = new Array("WINDOWS","MAC");
	for(i=0;i<platform_array.length;i++)
	{
		var platformReg = new RegExp(platform_array[i],"");
		if(platformReg.test(navigator.userAgent.toUpperCase()))
		{
			var platform = platform_array[i];
			break;
		}
		else
		{
			var platform  = "other";
		}
	}
	return platform;
}
/*                                   **************************                                   */
/************************************    TEMPLATE FUNCTIONS    ************************************/
/*                                   **************************                                   */
function resizePage()
{
	var page_body_height = getElementSize(document.getElementById("page_body"))[1];
	if(body_minimum_height < page_body_height)
	{
		var resize_height = (page_body_height - body_minimum_height);
		document.getElementById("page_body").style.height = page_body_height;
		for(var i=0;i<elements_for_resize.length;i++)
		{
			if(elements_for_resize[i][1] == "top")
			{
				var coords = getElementCoords(document.getElementById(elements_for_resize[i][0]));
				var incriment = parseInt(coords[1] + resize_height) + "px";
			}
			else if(elements_for_resize[i][1] == "height")
			{
				var element_size = getElementSize(document.getElementById(elements_for_resize[i][0]));
				var incriment = parseInt(element_size[1] + resize_height) + "px";
			}
			setStyle(document.getElementById(elements_for_resize[i][0]),elements_for_resize[i][1],incriment);
		}
	}
}
/*                                   **************************                                   */
/************************************     CLASS FUNCTIONS      ************************************/
/*                                   **************************                                   */
function setStyle(whichElement,style_property,style_value)
{
	if(style_property == "align")
	{
		whichElement.setAttribute("align",style_value);
	}
	else
	{
		if(whichElement.style[style_property])
		{
			whichElement.style[style_property] = style_value;
		}
		else if(browser == "MSIE")
		{
			eval("whichElement.style."+style_property+"='"+style_value+"'");
		}
		else if(whichElement.style.setProperty(style_property,style_value,null))
		{
			whichElement.style.setProperty(style_property,style_value,null);
		}
	}
}
/*                                   **************************                                   */
/************************************    POSITION FUNCTIONS    ************************************/
/*                                   **************************                                   */
function getElementCoords(which_element)
{
	var coords_array = new Array();
	var this_x = 0;
	var this_y = 0;
	if(which_element.offsetParent)
	{
		while(which_element.offsetParent)
		{
			this_x += which_element.offsetLeft;
			this_y += which_element.offsetTop;
			which_element = which_element.offsetParent;
		}
	}
	else if (which_element.x)
	{
		this_x += which_element.x;
		this_y += which_element.y;
	}
	coords_array[0] = this_x;
	coords_array[1] = this_y;
	return coords_array;
}
/*                                   **************************                                   */
/************************************   NODE QUERY FUNCTIONS   ************************************/
/*                                   **************************                                   */
function getElementSize(which_element)
{
	var this_size = new Array();
	if(which_element.innerWidth)
	{
		this_size[0] = which_element.innerWidth;
		this_size[1] = which_element.innerHeight;
	}
	else if(which_element.clientWidth)
	{
		this_size[0] = which_element.clientWidth;
		this_size[1] = which_element.clientHeight;
	}
	else if(which_element.offsetWidth)
	{
		this_size[0] = which_element.offsetWidth;
		this_size[1] = which_element.offsetHeight;
	}
	return this_size;
}