﻿function getWindowInnerHeight()
{
	var x,y;
	if (self.innerHeight) // all except Explorer
	{
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
	{
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body) // other Explorers
	{
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
	
	return y;
}

function getWindowScrollingOffset()
{
	var x,y;
	if (self.pageYOffset) // all except Explorer
	{
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	return y;
}

function getWindowHeight() 
{
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number') 
	{
		windowHeight=window.innerHeight;
	}
	else 
	{
		if (document.documentElement && document.documentElement.clientHeight) 
		{
			windowHeight = document.documentElement.clientHeight;
		}
		else 
		{
			if (document.body&&document.body.clientHeight) 
			{
				windowHeight=document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function setFooter()
{
	// First, retrieve window inner height
	var innerHeight = getWindowInnerHeight();
	
	// Then retrieve window scrolling offset
	var offsetHeight = getWindowScrollingOffset();
	
	// Set the footer top position at Inner Height + Offset Height - Footer Height
	var footerElement = document.getElementById('footer');
	footerElement.style.top=(innerHeight+offsetHeight-30)+'px';
	
	// Reload the footer position each 50 ms.
	window.setTimeout("setFooter()", 50);
}
