readMore = Class.create({
	des: false,
	fullText: false,
	truncText: false,
	truncLimit: 490,
	truncLimitNarrow: 250,
	duration: .3,
	toggleState: 0,
	needMore: true,
	offset: 0,
	
	initialize: function(containerID, truncBool) {
		this.Content = $(containerID);
		if(this.Content){
			this.des = this.Content.childElements()[0];
			this.trigger = $(containerID + '-toggle');
			this.truncBool = truncBool;
			this.truncHeight = this.Content.getHeight();
			this.Content.setStyle({'height':this.truncHeight});
			
			if(this.truncBool) { this._trunc(); } else { if ((this.truncHeight+5) >= this.des.getHeight()) this.trigger.style.display='none'; }
			if(this.needMore) { this.setEvents(); } else { this.trigger.style.display='none'; }
		}
	},
	
	setEvents: function(){
		if(this.trigger){
			this.trigger.observe('click', function(e) {
				Event.stop(e);
				if(this.toggleState) {
					this._hide();
				} else {
					this._show();
				}
			}.bind(this));
		}
	},
	
	toggle: function(bool){
		this.toggleState = bool;
		
		if(bool){
			this.trigger.innerHTML = 'Less';
			this.trigger.addClassName('up');
		} else {
			this.trigger.innerHTML = 'More';
			this.trigger.removeClassName('up');
		}
	},
	
	_show: function(){
		if(this.truncBool) this.des.innerHTML = this.fullText;
		
		fullHeight = this.des.getHeight();
		fullHeight += this.offset;
		
		new Effect.Morph(this.Content, { style:'height:'+fullHeight+'px;', duration: this.duration, afterFinish:function() {
			this.toggle(1);
		}.bind(this)});
	},
	
	_hide: function(){
		new Effect.Morph(this.Content, { style:'height:'+this.truncHeight+'px;', duration: this.duration, afterFinish:function() {
			if(this.truncBool) this.des.innerHTML = this.truncText;
			this.toggle(0);
		}.bind(this)});
	},
	
	_trunc: function(){
		this.des = this.Content.down('p');
		this.fullText = this.des.innerHTML;
		if(this.Content.up('.grid3col')) this.truncLimit = this.truncLimitNarrow;
		if(this.fullText.length <= this.truncLimit) this.needMore = false;
		this.truncText = this.des.innerHTML.truncate(this.truncLimit, '&nbsp;...');
		this.des.innerHTML = this.truncText;
		
		this.offset = this.truncHeight - this.des.getHeight();
	}
});

