browser = {
  
  agent: navigator.userAgent.toLowerCase(),
  isIe:    (navigator.userAgent.indexOf('msie')!=-1)&&(!this.is_opera)&&(!this.is_safari)&&(!this.is_webtv),
  isOpera: (navigator.userAgent.indexOf('opera')!=-1),       
  isMoz:   (navigator.product=='Gecko'),
  isNs:    ( (navigator.userAgent.indexOf('compatible') == -1) && (navigator.userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_safari) )

}

function centerdiv(div_id)
{
	this.divname = div_id || '';
	this.divobj  = '';
	this.shimobj = '';
}

/*-------------------------------------------------------------------------*/
// Main run function
/*-------------------------------------------------------------------------*/

centerdiv.prototype.move = function()
{
	try
	{
		if(parent.document.getElementById(this.divname)){
			this._document = parent.document;
			this._window   = parent.window;
		}
	}
	catch(e)
	{
		return;
	}
	
	this.divobj = this._document.getElementById(this.divname);
	
	// Figure width and height
	
	var my_width  = 0;
	var my_height = 0;
	
	if(typeof(this._window.innerWidth) == 'number')
	{
		// Non IE
		my_width  = this._window.innerWidth;
		my_height = this._window.innerHeight;
	}
	else if(this._document.documentElement && ( this._document.documentElement.clientWidth || this._document.documentElement.clientHeight ) )
	{
		// IE 6+		
		my_width  = this._document.documentElement.clientWidth;
		my_height = this._document.documentElement.clientHeight;
	}
	else if(this._document.body && ( this._document.body.clientWidth || this._document.body.clientHeight )){
		// Old IE
		my_width  = this._document.body.clientWidth;
		my_height = this._document.body.clientHeight;
	}
	
	// Show (but behind the zIndex...
	
	this.divobj.style.position = 'absolute';
	this.divobj.style.display  = 'block';
	this.divobj.style.zIndex   = -1;
	
	if(browser.isIe){
		var layer_html      = this.divobj.innerHTML;
		var full_html 		= "" + layer_html;
		
		this.divobj.innerHTML = full_html;
	}		

	//----------------------------------
	// Stop IE showing select boxes over
	// floating div [ 2 ]
	//----------------------------------
	
	if(browser.isIe){
	
		this.shimobj               = this._document.getElementById( this.divname + "-shim" );
		this.shimobj.style.width   = (parseInt(this.divobj.offsetWidth) -5) + "px";
		this.shimobj.style.height  = this.divobj.offsetHeight;
		this.shimobj.style.zIndex  = this.divobj.style.zIndex - 1;
		this.shimobj.style.top     = this.divobj.style.top;
		this.shimobj.style.left    = this.divobj.style.left;
		this.shimobj.style.display = "block";
	}		
	
	//----------------------------------
	// Get div height && width
	//----------------------------------
	
	var divheight = parseInt( this.divobj.style.height ) ? parseInt( this.divobj.style.height ) : parseInt( this.divobj.offsetHeight );
	var divwidth  = parseInt( this.divobj.style.width )  ? parseInt( this.divobj.style.width )  : parseInt( this.divobj.offsetWidth );
	
	divheight = divheight ? divheight : 200;
	divwidth  = divwidth  ? divwidth  : 400;
	
	//----------------------------------
	// Get current scroll offset
	//----------------------------------
	
	var scrolly = this.getYscroll();
	
	//----------------------------------
	// Finalize...
	//----------------------------------

	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";
	
	//----------------------------------
	// Show for real...
	//----------------------------------
	
	this.divobj.style.zIndex = 99;
};

/*-------------------------------------------------------------------------*/
// Hide div
/*-------------------------------------------------------------------------*/

centerdiv.prototype.hide = function(){
	try{
		if (!this.divobj ){
			return;
		}
		else{	
			this.divobj.style.display  = 'none';
		}
	}
	catch(e){
		return;
	}
};

/*-------------------------------------------------------------------------*/
// Get YScroll
/*-------------------------------------------------------------------------*/

centerdiv.prototype.getYscroll = function(){
	var scrollY = 0;
	
	if( this._document.documentElement && this._document.documentElement.scrollTop){
		scrollY = this._document.documentElement.scrollTop;
	}
	else if( this._document.body && this._document.body.scrollTop){
		scrollY = this._document.body.scrollTop;
	}
	else if ( this._window.pageYOffset ){
		scrollY = this._window.pageYOffset;
	}
	else if ( this._window.scrollY ){
		scrollY = this._window.scrollY;
	}
	
	return scrollY;
};
