window.onresize = fitFooter;

function fitFooter()
{
	$footer = document.getElementById('footer');
	$winHeight = getInnerHeight();
	$footerY = findPosY($footer);
	$footerH = $footer.offsetHeight;

	if ( ($footerY+$footerH) < $winHeight )
	{
		$footer.style.marginTop = ($winHeight-$footerY-$footerH)+'px';
	}
}

function getInnerHeight()
{
	if ( window.innerHeight )
	{
		return window.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{
		return document.documentElement.clientHeight;
	}
	else if (document.body) {
		return document.body.clientHeight;
	}
}

function getInnerWidth()
{
	if ( window.innerWidth )
	{
		return window.innerWidth;
	}
	else if (document.documentElement && document.documentElement.clientWidth)
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body) {
		return document.body.clientWidth;
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
