var TruncatedBox = Class.create({

	initialize: function(element) {
		this.element = element;
		this.initialHeight = 35;
		this.text = this.element.select('.text')[0];
		this.more = this.element.select('.more')[0];
		this.moretext = this.more.innerHTML;
		this.textClone = this.text.cloneNode(true);
		this.textClone.setStyle({
			'display':'none',
			'height':'auto',
			'overflow':'auto'
		});
		this.text.insert({
			after:this.textClone
		});
		this.newHeight = parseInt(this.text.getStyle('height'));//this.textClone.getDimensions().height
		this.text.setStyle({
			height:this.initialHeight+'px'
		});
		this.opened = false;
		this.textClone.remove();
		this.element.select('.more')[0].observe('click',this.open.bind(this))
	},

	open: function(){
		var height;
		this.opened = !this.opened;
		if (this.opened)
			height = this.newHeight;
		else height = this.initialHeight;		
		this.text.morph('height:'+height+'px');
		if (this.opened)
			this.more.innerHTML = "&laquo;&laquo;";
		else this.more.innerHTML = this.moretext;
	}
});
document.observe('dom:loaded', function(){
	$$('.truncatedBox').each(function(el){
		new TruncatedBox(el);
	}.bind(this));
})

