/* Водоплавающий футер :)
   Спешл фор автомир, 2010.

   vorobiev@2sun.ru (c) */

function getClientHeight()
{	// высота окна
	return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientHeight:window.innerHeight;
}

function getElementsHeight()
{	height_total = 0;
	// выбираем все куски контента
	elements = document.getElementById('mega_footer').parentNode.childNodes;
	for (i in elements)
	{	if (elements[i].offsetHeight)
			height_total += elements[i].offsetHeight;
	}
	if (navigator.appName == 'Microsoft Internet Explorer')
		return height_total; // + баннер
	if (navigator.appName == 'Opera')
		return height_total - 25; // + баннер
	else
		return height_total + 100; // + баннер
}

function make_footer_right_way ()
{	// сравниваем высоты окна и элементов контента
	if (getClientHeight() > getElementsHeight())
	{	document.getElementById('mega_footer').style.position = 'absolute';
		document.documentElement.style.height = '100%';
//		alert(1);
	}	
	else	// окно меньше, отлепляем футер
	{	document.getElementById('mega_footer').style.position = 'static';
		document.documentElement.style.height = 'auto';
//		alert(2);
	}
//	alert(getClientHeight() + ': ' + getElementsHeight());
	// всем спасибо, все свободны
	return true;
}

function install ()
{	document.getElementById('mega_footer').style.bottom = '0';
	document.body.height = '100%';
	document.body.minHeight = '100%';
	document.body.position = 'relative';
	make_footer_right_way();
	if (window.addEventListener) window.addEventListener('resize', make_footer_right_way, false);
	else if (window.attachEvent) window.attachEvent('onresize', make_footer_right_way);
}

window.onload = install;
