var centred_div_id;
var window_width;
var window_height;
var centred_div_width;
var centred_div_height;
var centring_timer = 0;

function centre_div( div_id, div_width, div_height )
{
	centred_div_id = div_id;
	centred_div_width = div_width;
	centred_div_height = div_height;

	window_width = document_width();
	window_height = document_height();

	set_display_position();

	if ( centring_timer == 0 )
	{
		centring_timer = window.setInterval( "check_window_size()", 20 );
	}
}

function document_width()
{
	var width;

	if ( window.innerWidth != null )
	{
		width = window.innerWidth;
	}
	else if ( document.documentElement && document.documentElement.clientWidth )
	{
		width = document.documentElement.clientWidth;
	}
	else if ( document.body != null )
	{
		width = document.body.clientWidth
	}
	else
	{
		width = 0;
	}

	return width;
} 

function document_height()
{
	var height;

	if ( window.innerHeight != null )
	{
		height = window.innerHeight;
	}
	else if ( document.documentElement && document.documentElement.clientHeight )
	{
		height = document.documentElement.clientHeight;
	}
	else if ( document.body != null )
	{
		height = document.body.clientHeight
	}
	else
	{
		height = 0;
	}

	return height;
} 

function set_display_position()
{
	var width;
	var left_offset;
	var height;
	var top_offset;
	var element;

	width = document_width();
	height = document_height();

	if ( width < centred_div_width )
	{
		left_offset = 0;
	}
	else
	{
		left_offset = ( width - centred_div_width ) / 2;
	}

	if ( height < centred_div_height )
	{
		top_offset = 0;
	}
	else
	{
		top_offset = ( height - centred_div_height ) / 2;
	}

	element = document.getElementById( centred_div_id );

	element.style.left = left_offset;
	element.style.top = top_offset;
}

function check_window_size()
{
	var width;
	var height;

	width = document_width();
	height = document_height();

	if ( ( width != window_width ) || ( height != window_height ) )
	{
		window_width = width;
		window_height = height;

		set_display_position();
	}
}


