﻿// javascript fix to background not properly extending to 100% of document length in all browsers
// sergey zarouski june 28.2010

function fixMainBg() {
	var d = document;
	var docBody = d.body;
	var container = d.getElementById('container');
	
	var viewportheight;
	var property;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerHeight != 'undefined')
	{
		viewportheight = window.innerHeight;
		property = "min-height";
	}
	
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
	&& typeof document.documentElement.clientWidth !=
	'undefined' && document.documentElement.clientWidth != 0)
	{
		viewportheight = document.documentElement.clientHeight;
		property = "height";
	}
	
	// older versions of IE
	else
	{
		viewportheight = document.body.clientHeight;
		property = "height";
	}

	if(container && docBody && (docBody.offsetHeight > container.offsetHeight)) {
		container.style.cssText = property+":"+viewportheight+"px";
	} else {
		container.style.cssText = "";
	}
}

function addfixMainBgEvent(elem, type, handler){
	if (elem.addEventListener){
	elem.addEventListener(type, handler, false)
	} else {
	elem.attachEvent("on"+type, handler)
	}
}

addfixMainBgEvent(window, 'load', fixMainBg);

if(navigator.appVersion.search('MSIE 6') === -1) {
	addfixMainBgEvent(window, 'resize', fixMainBg);
}
