/**
 * fuMan - developped by fugu GmbH, Bern, Switzerland, www.fugu.ch
 * Please see licence.txt in the root directory for further information.
 *
 * $Id: documentextension.js,v 1.1 2006-10-24 10:59:16 higi Exp $
 * $Date: 2006-10-24 10:59:16 $
 * $Revision: 1.1 $
 *
 * extension added to the document object
 * IE does not accept extensions to Document object :(
 */

function getDocumentDimensions () {
	var o = new Object ();
	o.document = getDocumentSize ();
	o.viewport = getViewportSize ();
	o.scroll = getScrollOffset ();
	return o;
}
// returns the dimension of the document/its contents
function getDocumentSize () {
	var w = -1, h = -1;
	if (document.documentElement && document.documentElement.scrollWidth) w = document.documentElement.scrollWidth;
	else if (document.body.scrollWidth) w = document.body.scrollWidth;
	if (document.documentElement && document.documentElement.scrollHeight && document.body.scrollHeight) h = Math.max (document.documentElement.scrollHeight, document.body.scrollHeight);
	else if (document.documentElement && document.documentElement.scrollHeight) h = document.documentElement.scrollHeight;
	else if (document.body.scrollHeight) h = document.body.scrollHeight;
	var o = new Object ();
	o.h = h;
	o.w = w;
	return o;
}
// return the dimension of the browser window
function getViewportSize () {
	var w = -1, myHeight = -1;
	// Non-IE
	if (typeof (window.innerWidth) == 'number') {
		w = window.innerWidth;
		h = window.innerHeight;
	}
	// IE 6+ in 'standards compliant mode'
	else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
		w = document.documentElement.clientWidth;
		h = document.documentElement.clientHeight;
	}
	// IE 4 compatible
	else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
		w = document.body.clientWidth;
		h = document.body.clientHeight;
	}
	var o = new Object ();
	o.h = h;
	o.w = w;
	return o;
}
// returns the scrolled offset
function getScrollOffset () {
	var x = -1, y = -1;
	// Netscape compliant
	if (typeof (window.pageYOffset) == 'number') {
		y = window.pageYOffset;
		x = window.pageXOffset;
	}
    // DOM compliant
	else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
		y = document.body.scrollTop;
		x = document.body.scrollLeft;
	}
	// IE6 standards compliant mode
	else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
		y = document.documentElement.scrollTop;
		x = document.documentElement.scrollLeft;
	}
	var o = new Object ();
	o.x = x;
	o.y = y;
	return o;
}

function centerElement (div) {
	var w = 0, h = 0;
	if (div.style.width) w = stripPX (div.style.width);
	if (div.style.height) h = stripPX (div.style.height);
	var d = getDocumentDimensions ();
	div.style.top = ((d.viewport.h - h) / 2) + d.scroll.y + 'px';
	div.style.left = ((d.viewport.w - w) / 2) + d.scroll.x + 'px';
}

