var AnimationActor = new Class({
	/* Actors perform their own animations, and are controlled by the Scene.
		Each Actor is aware of the Stage.
	 */
	Implements: [Options,Events, Chain], 						  

	options: {
		/* DOM element */
		stage : '',
		/* DOM element */
		actor : '',
		/* length of anim in ms */
		animDuration : 'long'
		
	}, 
	
	log: function(){
		return false;
		//if('console' in window && 'log' in window.console) console.log.apply(console, arguments);
	},
	
	initialize: function(options){ 
		/* EVENTS 
			animComplete : fired when final chain anim is complete
		*/
		
		this.setOptions(options);
		
		/* DOM element */
		this.ActorElement;
		/* pixel offset (integer) */
		this.animDistance = 30;
		
		var r = false;
		
		if(this.options.actor){
			this.ActorElement = this.options.actor;
				
			/* coordinates, plus dimensions */
			this.Origin = this.ActorElement.getCoordinates(this.ActorElement.getOffsetParent());
			
			/* hide */
			this.ActorElement.fade('hide');
			
			this.resetChain();
			
			r = this;
		}
		
		return r;
		
	},
	/*
	called when using document.id with this class as parameter
	*/
	toElement : function (){
		return this.ActorElement;
	},
	
	/*
	creates the animation sequence via Chain
	$params[''] () : 
	*/
	resetChain : function (){
		/* the animation sequence */
		this.chain(this.performAnimation.bind(this,{'in':true}));
		this.chain(this.performAnimation.bind(this,{'in':false}));
		
	},
	
	/*
	$params['in'] (bool) : whether we are transitioning in or out 
	*/
	performAnimation : function (params){
		/* apply animations based on CSS classes */
		
		var css = this.ActorElement.getProperty('class');
		var morphParams = {};
		/* default */
		var onComplete = function(){};
		var ease = 'quad';
		var morphTransition = ease + ':out';
		
		
		if(css.contains('from-bottom')){
			if(params['in']){
				/* Transition to origin pos from bottom of stage */
				morphParams['top'] = [ this.Origin['top'].toInt() + this.animDistance, this.Origin['top'] ];
				/* fade in */
				morphParams['opacity'] = [0,1];
				
			}else{
				/* Transition from origin pos to bottom of stage */
				morphParams['top'] = [ this.Origin['top'], this.Origin['top'].toInt() + this.animDistance ];
				/* fade out */
				morphParams['opacity'] = [1,0];
				
			}
 			//this.log('morphParams=',morphParams);
		}
		
		if(css.contains('from-right')){
			if(params['in']){
				/* Transition to origin pos from right of stage */
				morphParams['left'] = [ this.Origin['left'].toInt() + this.animDistance, this.Origin['left'] ];
				/* fade in */
				morphParams['opacity'] = [0,1];
				
			}else{
				/* Transition from origin pos to right of stage */
				morphParams['left'] = [ this.Origin['left'], this.Origin['left'].toInt() + this.animDistance ];
				/* fade out */
				morphParams['opacity'] = [1,0];
				
			}
 			//this.log('morphParams=',morphParams);
		}
		
		/* fire anim complete event */
		if(params['in']){
			
		}else{
			morphTransition = ease + ':in';
			onComplete = this.animComplete.bind(this);
		}
		
		this.FxMorph = new Fx.Morph(this.ActorElement, {'duration':this.options.animDuration,'transition':morphTransition});
		
		if(morphParams)this.FxMorph.start(morphParams).chain(onComplete);
		
	},
	
	/*
	runs when all anims complete
	$params[''] () : unused
	*/
	animComplete : function (){
		this.fireEvent('animComplete');
		//this.log('animComplete');
		this.resetChain();
	}
	
});
