var AnimationScene = new Class({
	/* Dictates what the Actors will do */
	Implements: [Options,Events, Chain], 						  

	options: {
		/* AnimationStage Class object */
		stage : '',
		/* CSS selector str */
		scene : '',
		/* length of anim in ms */
		animDuration : 300,
		/* length of pause between in an out (in ms) */
		animPause : 1000,
		/* length of delay at start of Anim (in ms) */
		animStartDelay : 1000,
		/* length of offset between Actor animations (in ms) */
		animOffset : 200,
		
	}, 
	
	log: function(){
		return false;
		//if('console' in window && 'log' in window.console) console.log.apply(console, arguments);
	},
	
	initialize: function(options){ 
		/* EVENTS:
			sceneComplete = when the last Actor has triggered event 'animComplete'
		 */
		
		this.setOptions(options);
		
		//this.log('this.options=',this.options); return 0;
		
		var r = false;
		/* list of all actors in this scene */
		this.Actors = [];
		/* base DOM element */
		this.SceneElement;
		/* track this */
		this.eventAdded = false;
		
		if(this.SceneElement = document.id(this.options.stage).getElement(this.options.scene)){
			/* add all actors */
			
			this.SceneElement.getElements('.actor').each(
				function(item, index, array){
					var actor;
					if(actor = new AnimationActor( Object.merge({'actor':item}, this.options) )){
						this.Actors.push(actor);
					}
				},this
			);
			
			//this.log('this.Actors=',this.Actors);
			
			/* hide scene */
			this.SceneElement.setStyle('display', 'none');

			
			r = this;
		}
		
		return r;
		
	},
	/*
	called when using document.id with this class as parameter
	*/
	toElement : function (){
		return this.SceneElement;
	},
	
	/*
	progresses the Scene Animation
	params['addEvent'] (bool) : whether to add the event handler
	*/
	stepAnimation : function (params){
		
		/* show scene */
		this.SceneElement.setStyle('display', 'block');
			
		
		this.Actors.each(
			
			/* trigger all Actor animation sequences */
			function(item, index, array){
				
				//this.log(document.id(this), ' stepAnimation params=',params);
				
				if(params.addEvent && (index+1) == this.Actors.length){
					/* last actor */
					/* add event handler */
					//var boundFunc = function(){this.log(document.id(item),'YO YO YO');}.bind(this);
					//var completeHandler = this.sceneComplete.bind(this);
					//this.log('this.eventAdded=',this.eventAdded,'params =',params, 'index=',index, 'item=', document.id(item));
					
	
					if(!this.eventAdded){
						item.addEvent('animComplete', this.sceneComplete.bind(this));
						
						this.log('event added params = ',params);
						
						this.eventAdded = true;
					}
				}else{
					this.log('params=',params);
					//item.removeEvent('animComplete', this.sceneComplete);
				}
				
				var f = function(){this.callChain()};
				var timeoutId = f.delay(this.options.animOffset * index, item);
				//this.log('timeoutId=',timeoutId);				
			},this
		);
		

	},
	
	/*
	event fire when first Actor has entered
	$params[''] () : unused
	*/
	sceneStarted: function (){
		//this.fireEvent('sceneStarted');
		//this.log('sceneStarted');
		
	},
	
	/*
	event when last Actor has left
	$params[''] () : unused
	*/
	sceneComplete: function (){
		/* hide scene */
		this.SceneElement.setStyle('display', 'none');

		this.fireEvent('sceneComplete');
		this.log('sceneComplete');
		
	},
	


});
