
var SimpleReveal = Class.create({
	initialize : function(container, options){
		this.container = $(container);
		this.options = Object.extend({toggleClass:'active', oLinkSel:'.open', cLinkSel:'.close', contentSel:'.content', duration:.5, cb:function(){}}, options || {});
		this.setup();
	},
	setup : function(){
		if (this.options.tLinkSel)
			this.toggles = this.container.select(this.options.tLinkSel).invoke('observe', 'click', this.open.bind(this));
		else{
			this.container.select(this.options.oLinkSel).invoke('observe', 'click', this.open.bind(this));
			this.container.select(this.options.cLinkSel).invoke('observe','click', this.close.bind(this));
		}
		this.content = this.container.select(this.options.contentSel).first().hide();
	},
	open : function(e){
		e.stop();
		if (this.effect != null) return;
		this.effect = new Effect.toggle(this.content, 'blind', {duration:this.options.duration, afterFinish:function(){this.effect=null;}.bind(this)});
		this._cleanUp();
	},
	close : function(e){
		e.stop();
		if (this.effect != null) return;
		this.effect = new Effect.BlindUp(this.content, {afterFinish:this._cleanUp.bind(this, true), duration:this.options.duration});
	},
	_cleanUp : function(reset){
		this.container.toggleClassName(this.options.toggleClass);
		this.options.cb.apply(this);
		if (reset) this.effect = null;
	}
});



document.observe('dom:loaded', function() {

		if ($$('.viewAll').length){
			$$('.reveal').each(function(el){
				new SimpleReveal(el, {tLinkSel:'.viewAll', contentSel:'p', cb : function(){
					var open = this.toggles.first().innerHTML.indexOf('More') != -1;
					if(open) this.toggles.invoke('update', open ? 'Less Info' : 'More Info');
				}});
			});
		}

});
