bodyLoad.add( function() { addCss(URL + 'js/core/lightBox/css/lightBox.css') } );
var lightBox = function()
{
	this.parentArea = null;
	this.area = null;
	this.areaTarget = null;
	this.closeButton = null;
	this.onContent = function(){ return; };

	if(arguments.length>0) this.init( arguments );

};

lightBox.prototype.createArea = function( $content , $target )
{
	if(this.area) return;
	$t('select').forEach(function(el){ el.style.visibility='hidden';});
	var $target = isset($target) ? $target : document.body;

	if(!$('divForRightHeight')) {
		var d=$(cE("div", $target, 'divForRightHeight'));
		d.style.clear='both';
	}

	var ua = usefullArea() , hh=$t('html')[0].offsetHeight;
	var h = hh>ua['y']  ? hh : ua['y'];
	var tempH = document.body.offsetHeight;
	if( tempH > h ) h = tempH;

	this.parentArea =  cE("div", $target, 'parentLightBoxArea');
	this.parentArea.style.width = document.body.offsetWidth + 'px';
	this.parentArea.style.height = h + 'px';

	this.area =  $(cE("div", $target, 'lightBoxArea'));

	this.closeButton = cE('a', this.area, 'closeLightBoxArea');
	this.closeButton.innerHTML = "fechar";

	var o = this;
	this.closeButton.onclick = this.parentArea.onclick = function(){o.close();}

	centralizeElement(this.area);

	this.areaTarget = $(cE('div', this.area, 'lightBoxAreaTarget'));
	this.areaTarget.style.display='none';

	if($content)
		this.contents($content);

};

lightBox.prototype.close = function(){
	$t('select').forEach(function(el){el.style.visibility='visible';});
	DOM.rem(this.area);
	DOM.rem(this.parentArea);
	this.area=this.previousButton=this.nextButton=null;
}

lightBox.prototype.contents = function( $content )
{
	if($content.substring(0,7)=='http://' && typeof Ajax=='function')
	{
		var a = new Ajax(),o=this;
		a.onComplete = function(r){
			/*o.contents( '<div class="contents">'+ r[0] +'</div>');*/
			var dc = DOM.create( 'div', { 'class': 'contents' });
			DOM.inside( dc, o.areaTarget );
			a.setTarget(dc);
			a.content( r );
			o.showArea( true );
		}
		a.callServer($content);
		return;
	}

	this.areaTarget = this.areaTarget.replaceHTML($content);

	this.showArea( true );

}

lightBox.prototype.showArea = function( c )
{
	this.areaTarget.style.display='block';
	this.areaTarget.style.cssFloat='left';

	if( c )
	{

		var w = this.areaTarget.scrollWidth;
		var h = this.closeButton.scrollHeight+this.areaTarget.scrollHeight+10;
		var a=getCentralizedValues(null,w,h);

		if( Animator != undefined )
		{
			var t = new Animator();
			t.addSubject(new NumericalStyleSubject(this.area, 'width', getStyle(this.area,'width'), w));
			t.addSubject(new NumericalStyleSubject(this.area, 'left', getStyle(this.area,'left'), a[0]));
			t.addSubject(new NumericalStyleSubject(this.area, 'height', getStyle(this.area,'height'), h));
			t.addSubject(new NumericalStyleSubject(this.area, 'top', getStyle(this.area,'top'), a[1]));
			t.addSubject(new NumericalStyleSubject(this.areaTarget, 'opacity', 0, 1));
			t.play();

		} else {
			this.area.style.width = w +'px';
			this.area.style.height = h +'px';
			this.area.style.left = a[0] +'px';
			this.area.style.top = a[1] +'px';
			if( isMSIE ) this.areaTarget.style.filter = 'alpha(opacity=100)';
			else this.areaTarget.style.opacity=1;
		}
	}

	this.onContent( this.area );
}