//
// Comfort Station Effects Manager
// Tim Mowrer
// May 30, 2009
//
//
// Wrapper for the Scriptaculous Effects library
// Handles cancellation of any existing effect of similar type (e.g. opacity)
// on the same object.  Multiple calls to Csem.fade() will ensure only one
// Effect.Fade is running at a time.
//
var Csem = {

	duration: .3,

	findEffect: function ( obj, scope )
	{
		Effect.Queues.get(scope).each(function(e)
		{
			if (e.element == obj)
			{
				return e;
			}
		});
		
		return null;
	},
	
	cancelEffect: function ( obj, scope )
	{
		Effect.Queues.get(scope).each(function(e)
		{
			if (e.element == obj)
			{
				e.cancel();
			}
		});	
	},

	fade: function fade( obj, options )
	{
		// Cancel any opacity scoped effects running on this object
		this.cancelEffect( $(obj), 'opacity' );
		new Effect.Opacity( obj, Object.extend( {queue:{scope:'opacity'}, duration:this.duration}, options ) );
	},
	
	fadeIn: function ( obj, options ) {
		this.fade( obj, Object.extend( {to: 1}, options ) );
	},
	
	fadeOut: function ( obj, options )
	{
		this.fade( obj, Object.extend( {to: 0}, options ) );	
	},
	
	appear: function (obj, options)
	{
		// Cancel any opacity scoped effects running on this object
		this.cancelEffect( obj, 'opacity' );
		new Effect.Appear( obj, Object.extend( {queue:{scope:'opacity'}, duration:this.duration}, options ) );
	},
	
	disappear: function (obj, options)
	{
		// Cancel any opacity scoped effects running on this object
		this.cancelEffect( obj, 'opacity' );
		new Effect.Fade( obj, Object.extend( {queue:{scope:'opacity'}, duration:this.duration}, options ) );
	}	

};

