lightBox.prototype.init = function(a)
{
	this.imageLoad = null;
	this.description = null;

	this.urlSmall = '/s/';
	this.urlBig = '/b/';

	this.imgs = [];
	this.current=0;

	if(a[1])  this.urlSmall = a[1];
	if(a[2]) this.urlBig = a[2];
	if( a[0].tagName )
	{
		if(a[0].tagName.toLowerCase()=='img')
			return this.toEnlarge(a[0], a[0]);
		else if(a[0].tagName.toLowerCase()=='a') {
			var tg = $t('img', a[0])[0];
			if(!tg) tg = a[0];
			return this.toEnlarge(a[0], tg);
		}
	}

	this.childsToEnlarge(a[0]);
}


lightBox.prototype.createAreaToImages = function(_target)
{
	if(this.area) return;
	this.createArea();

	this.imageLoad = cE('img', this.areaTarget, 'imageLoad');
	this.description = cE('p', this.areaTarget, 'descriptionTextArea');

	this.showHideImage(false);
};

lightBox.prototype.showHideImage = function(sh) {
	if(sh) this.imageLoad.style.display = this.description.style.display = 'block';
	else this.imageLoad.style.display = this.description.style.display = 'none';
};

lightBox.prototype.formatSrc = function(objImg) {
	if(typeof objImg=='string') return objImg;
	var _src = objImg.getAttribute("src");
	_src = (!_src) ? objImg.getAttribute("href") : _src ;
	if(!_src) return false;
	var newSrc = _src.replace(this.urlSmall, this.urlBig);
	return newSrc;
};

lightBox.prototype.enlargeThis = function(_target) {

	var description = (typeof _target!='string') ? _target.getAttribute("title") : '';

	this.createAreaToImages();

	var o = this;
	this.current=_target.index;

	this.showHideImage(false);

	this.area.className = 'loading';

	var _img = new Image();

	_img.onload = function() {
		o.areaTarget.style.opacity=0;

		o.imageLoad.src = this.src;

		o.area.className = '';
		o.showHideImage(true);

		o.description.innerHTML = description;

		o.description.style.width = this.width +'px';
		o.areaTarget.style.display = 'block';
		var h = o.closeButton.offsetHeight+this.height+o.description.offsetHeight;

		o.areaTarget.style.display = 'none';
		var a=getCentralizedValues(null,this.width,h), w = this.width<250?250:this.width;

		if( typeof Animator != 'undefined' )
		{
			var t = new Animator();
			t.addSubject(new NumericalStyleSubject(o.area, 'width', getStyle(o.area,'width'), w));
			t.addSubject(new NumericalStyleSubject(o.area, 'left', getStyle(o.area,'left'), a[0]));
			t.addSubject(new NumericalStyleSubject(o.area, 'height', getStyle(o.area,'height'), h));
			t.addSubject(new NumericalStyleSubject(o.area, 'top', getStyle(o.area,'top'), a[1]));
			t.addSubject(new NumericalStyleSubject(o.areaTarget, 'opacity', 0, 1));
			t.play();
		} else {
			o.areaTarget.style.opacity=1;
			//o.areaTarget.style.filter('alpha(opacity = 100)');
			o.area.style.width = w +'px';
			o.area.style.height = h +'px';
			o.area.style.left = a[0] +'px';
			o.area.style.top = a[1] +'px';
		}

		o.area.style.visibility = 'visible';
		o.createPreviousNext();
		o.showArea(false);
	}
	_img.src = this.formatSrc(_target);
};

lightBox.prototype.childsToEnlarge = function(_target)
{
	var c = $t("a", _target);

	var o = this;
	c.forEach(
		function(e) {
			var _img = $t('img', e)[0];
			if(_img)
			{
				o.imgs[o.imgs.length]=_img;
				_img.index=o.imgs.length;
				e.onclick = function(){ o.enlargeThis(_img); return false; };
			}
		}
	);
};

lightBox.prototype.toEnlarge = function(caller, _target) {
	var o = this;
	caller.onclick = function() {
		o.enlargeThis(_target);
		return false;
	}
}

lightBox.prototype.createPreviousNext = function()
{
	if( this.imgs.length<=1 || this.previousButton ) return;

	this.previousButton = DOM.create('a', { id:'previousLightBoxButton'} );
	this.previousButton.innerHTML = "Anterior";

	this.nextButton = DOM.create('a', { id:'nextLightBoxButton'} );
	this.nextButton.innerHTML = "Próxima";

	var o=this;
	Evt.add(this.previousButton,'click',function(){o.previous();});
	Evt.add(this.nextButton,'click',function(){o.next();});

	DOM.before(this.previousButton,this.closeButton);
	DOM.before(this.nextButton,this.closeButton);
}


lightBox.prototype.next = function() {
	if(!this.imgs[this.current]) return;
	this.enlargeThis(this.imgs[this.current]);
}

lightBox.prototype.previous = function() {
	if(!this.imgs[this.current-2]) return;
	this.enlargeThis(this.imgs[this.current-2]);
}