/**
	ler Mais....
	para a página inicial
**/
var addLerMais = new Class(
{
	options :
	{
		height : 40,
		overHeight : 40,
		restOpacity : 0.7,
		clickFn : false
	},
	Implements : [Options],
	initialize : function(containerElement,options)
	{
		this.setOptions(options);
		this.element = containerElement;
		this.elementImage = containerElement.getFirst();
		this.extraText = this.element.getProperty('extraText');
		if (this.element.getProperty('overHeight')) this.setOptions({overHeight:this.element.getProperty('overHeight')});
		this.link = this.element.getProperty('link');
		if (!this.options.clickFn) this.options.clickFn = this.defaultClickFn;
		this.overlay = this.createOverlay();
		this.elementImage.set('morph',{duration:300});
		this.overlay.set('morph',{duration:300});		
		this.adjustElement();
	},
	defaultClickFn : function(obj)
	{	
		if (!obj.link) return false;
		window.location.href = obj.link;
	},
	mouseOverActions : function()
	{
		this.overlay.morph(
		{
			'opacity':1,
			'height':this.options.overHeight
		});
		this.elementImage.morph(
		{
			'opacity':this.options.restOpacity
		});		
		this.adjustOverText();		
	},
	mouseOutActions : function()
	{
		this.overlay.morph(
		{
			'opacity':this.options.restOpacity,
			'height':this.options.height
		}).get('morph').chain(function()
		{
			this.adjustOutText();	
		}.bind(this));
		this.elementImage.morph(
		{
			'opacity':1
		});
		
	},	
	adjustElement : function()
	{
		this.element.addEvents(
		{
			'mouseover': this.mouseOverActions.bind(this),
			'mouseout': this.mouseOutActions.bind(this),
			'click' : this.options.clickFn.pass(this)
		});
		if (this.link)
		{
			this.element.set('styles',
			{
				'cursor':'pointer'
			});
		}		
		if (this.element.get('title') == null)
		{
			//this.element.set('title',this.overlay.get('text'));
		};
		this.overlay.inject(this.element.getParent());
	},
	createOverlay : function()
	{
		var altura = this.options.height;//(this.extraText)?this.options.height*2:this.options.height;
		var el = new Element('div',{'class':'lerMaisOverlay'});
		var c = this.element.getCoordinates();
		el.setStyles(
		{
			'width':c.width,
			'height':altura,
			'position':'absolute',
			'left':0,
			'bottom':0,
			'opacity':this.options.restOpacity
		});
		if (this.link)
		{
			el.set('styles',
			{
				'cursor':'pointer'
			});
		}		
		el.addEvents(
		{
			'mouseover': this.mouseOverActions.bind(this),
			'mouseout': this.mouseOutActions.bind(this),
			'click' : this.options.clickFn.pass(this)
		});
		if (this.extraText)
		{
			var extra = new Element('p',{'class':'lerMaisExtra'});
//			extra.set('html',this.extraText);
			extra.inject(el);
			this.extra = extra;
		};
		if (this.link)
		{
			
			//var sp = new Element('p',{'class':'lerMaisLink'});
			//sp.set('html',_("Seguir leyendo>>"));		
			//sp.inject(el);
			
		}
		this.adjustOutText();
		return el;			
	},
	adjustOutText : function()
	{
		if (!this.extra) return true;
		var texto = _(this.extraText);
		var i = texto.indexOf('##');
		if (i >= 0)
		{//encontrou brake
			tit = texto.substr(0,i)+'...';
		}
		else tit = texto;
		this.extra.set('html',tit);
	},
	adjustOverText : function()
	{
		if (!this.extra) return true;
		var t = _(this.extraText);
		var texto = t.replace("##","");
		this.extra.set('html',texto);
	}	
});
