// returns an element by its ID
function getElement(elementId) {
	var element = null;
	
	if (document.getElementById) {
		// this is the way the standards work
		element = document.getElementById(elementId);
	} else if (document.all) {
		// this is the way old msie versions work
		element = document.all[elementId];
	} else if (document.layers) {
		// this is the way nn4 works
		element = document.layers[elementId];
	}
	
	return element;
	
}


function alignme() {

  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }

	//alert(getElement('outerdiv').style);
	
	if (myWidth > 802) {	
		var marg = Math.round((myWidth - 802) / 2);
		getElement('maincontainer').style.marginLeft = marg + 'px';
		getElement('footercontainer').style.marginLeft = marg + 'px';
	} else {
		var marg = 0;
		getElement('maincontainer').style.marginLeft = marg + 'px';
		getElement('footercontainer').style.marginLeft = marg + 'px';
	}
//	getElement('outerdiv').style.top = Math.round(myHeight / 2) + 'px';
}


//DOM-ready watcher
function domReady()
{
	//start or increment the counter
	this.n = typeof this.n == 'undefined' ? 0 : this.n + 1;
	
	//if DOM methods are supported, and the body element exists
	//(using a double-check including document.body, for the benefit of older moz builds [eg ns7.1] 
	//in which getElementsByTagName('body')[0] is undefined, unless this script is in the body section)
	//>>> and any elements the script is going to manipulate exist
	if
	(
		typeof document.getElementsByTagName != 'undefined' 
		&& (document.getElementsByTagName('body')[0] != null || document.body != null)
		//>>> && document.getElementById('something') != null 
	)
	{
	//>>>-- DOM SCRIPTING GOES HERE --<<<
	
	
		//alignme();
		//window.onresize = alignme;


	//>>>-----------------------------<<<
	}

	//otherwise if we haven't reached 60 (so timeout after 15 seconds)
	//in practise, I've never seen this take longer than 7 iterations [in kde 3.2.2 
	//in second place was IE6, which takes 2 or 3 iterations roughly 5% of the time]
	else if(this.n < 60)
	{
		//restart the watcher
		//using the syntax ('domReady()', n) rather than (domReady, n)
		//because the latter doesn't work in Safari 1.0
		setTimeout('domReady()', 1);
	}
};
//start the watcher
domReady();