//- Version 2009-07-14

var $hCenterAbsolute = function (obj, bDoNotApply) {
	var obj =$(obj) ;
	if ( $defined(obj) ){
		var coords =obj.getCoordinates () ;
		var scroll =$(document.body).getParent ().getScroll () ;
		var x =(window.getWidth () - coords ['width']) / 2 + scroll.x ;
		if ( x < 0 )
			x =0 ;
		if ( !bDoNotApply )
			obj.setStyle ('left', x) ;
		return (x) ;
	}
} ;

var $vCenterAbsolute = function (obj, bDoNotApply) {
	var obj =$(obj) ;
	if ( $defined(obj) ) {
		var coords =obj.getCoordinates () ;
		var scroll =$(document.body).getParent ().getScroll () ;
		var y =(window.getHeight () - coords ['height']) / 2 + scroll.y ;
		if ( y < 0 )
			y =0 ;
		if ( !bDoNotApply )
			obj.setStyle ('top', y) ;
		return (y) ;
	}
} ;

var $centerAbsolute = function (obj, bDoNotApply) {
	return ({ 'left': $hCenterAbsolute(obj, bDoNotApply), 'top': $vCenterAbsolute(obj, bDoNotApply) }) ;	
} ;

var $autoCenter = function (obj) {
	$centerAbsolute (obj, false) ;
	window.addEvent ('scroll', function (obj) {
		$centerAbsolute(obj, false) ;
	}.pass (obj)) ;
	window.addEvent ('resize', function (obj) {
		$centerAbsolute(obj, false) ;
	}.pass (obj)) ;
} ;

