CenterDiv.divname = '';
CenterDiv.updater = null;
CenterDiv.showing = false;

function CenterDiv(divname)
{
	this.divname = divname;	
	this.divobj = '';
}

function reposeDiv(div)
{
	div.repose();
}

function _get_obj_toppos(obj)
{
	var top = obj.offsetTop;
	while( (obj = obj.offsetParent) != null )
	{
		top += obj.offsetTop;
	}
	return top;
}

CenterDiv.prototype.Ywindow = function()
{
	var scrollY = 0;
	if ( document.documentElement && document.documentElement.scrollTop )
	{
		scrollY = document.documentElement.scrollTop;
	}
	else if ( document.body && document.body.scrollTop )
	{
		scrollY = document.body.scrollTop;
	}
	else if ( window.pageYOffset )
	{
		scrollY = window.pageYOffset;
	}
	else if ( window.scrollY )
	{
		scrollY = window.scrollY;
	}
	return scrollY;
}

CenterDiv.prototype.repose = function()
{
	try
	{
		this.divobj = document.getElementById( this.divname );
		if (this.divobj == null) {
		    return;
		}
	}
	catch(e)
	{
		return;
	}
	
	// Figure width and height
	var my_width  = 0;
	var my_height = 0;

        var doc = document.getElementById("main");
	
	my_height = doc.offsetHeight;
	
	
	if ( typeof( window.innerWidth ) == 'number' )
	{
		my_width  = window.innerWidth;
		
		if(window.innerHeight < my_height)
			my_height = window.innerHeight;			
	}
	else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )
	{
		my_width  = document.documentElement.clientWidth;
		
		if(document.documentElement.clientHeight < my_height)
			my_height = document.documentElement.clientHeight; 
	}
	else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) )
	{
		my_width  = document.body.clientWidth;
		
		if(document.body.clientHeight < my_height)
			my_height = document.body.clientHeight;		
	}
	

	this.divobj.style.position = 'absolute';
	this.divobj.style.zIndex = 99;
	var divheight = parseInt( this.divobj.offsetHeight );
	var divwidth  = parseInt( this.divobj.offsetWidth );
	divheight = divheight ? divheight : 50;
	divwidth  = divwidth  ? divwidth  : 200;
	var scrolly = this.Ywindow();
	var setX = ( my_width  - divwidth  ) / 2;
	var setY = ( my_height - divheight ) / 2 + scrolly;
	setX = ( setX < 0 ) ? 0 : setX;
	setY = ( setY < 0 ) ? 0 : setY;
	this.divobj.style.left = setX + "px";
	this.divobj.style.top  = setY + "px";	
}

CenterDiv.prototype.show = function()
{
	this.repose();
	eval(this.divname + '_obj = this');
	this.updater = setInterval("reposeDiv(" + this.divname + "_obj)", 100);
	$(this.divobj).stop().fadeIn(500);
	this.repose();
}

CenterDiv.prototype.hide = function()
{
    //alert("repose");
	//clearInterval(this.updater);
	//$(this.divobj).stop().fadeOut(500);
}
