/*************************************************
Class:            animStepTime.class.js
Created On:       Aug 5, 2004
Last Modified On: Aug 19, 2004
Author:           Ricardo Cook
Copyright:        Magnifi Group, Inc. (c) 2004.

List of Modifications:

 Aug 06, 2004: * Removed argument 'nsteps' from object
 Aug 09, 2004: * Added functionality to handle multiple animations
 Aug 11, 2004: * Fixed bug in 'playStep()' function
 Aug 12, 2004: * Updated 'animationStopped()' function to handle multiple animations
               * Added 'animLength' parameter to 'addAnimation()'
               * Added 'stepIniTime' parameter to 'stepTime()'
               * Removed 'addAnimTime()', 'addStepTime()', 'setAnimations()', 'setSteps()', 'getAnimIndex()'
               * Modified 'playStep()' to consider the 'animLength' values. Added 'autoRunStatus' parameter              
 Aug 19, 2004: * Added functionality to handle sound (functions are being called through Flash)
 Oct 20, 2004: * Added command to reset camera: 'resetCamera()'      
 							 * Added functionality to scroll animation: scrollAnimation()
 Feb 08, 2005: * Removed animation length as it is not required.
               
*************************************************/

function animStepTime(vmpObj) {
	this.vmp = vmpObj;

	this.playingAutoRun =  false;
	this.currStep = -1;
	
	this.animationArray = new Array;
	this.stepArray = new Array;
	this.stepTimeArray = new Array;	
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.addAnimation = function(aName) {
	this.animationArray.push(aName);
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.addStep = function(sName, sTime) {
	this.stepArray.push(sName);
	this.stepTimeArray.push(sTime);
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.isPlayingAutoRun = function() {
	return this.playingAutoRun;
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.setPlayingAutoRun = function(autoRunStatus) {
	this.playingAutoRun = autoRunStatus;
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.animationStopped = function(stepNum) {
	if (!this.isPlayingAutoRun() && stepNum == this.currStep) 
		for (i=0; i<this.animationArray.length; i++)
			this.vmp.StopAnim('MTSTimeElem.' + this.animationArray[i]);	
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.playStep = function(stepNum, autoRunStatus) {
	var currTime = 0;	
	
	this.setPlayingAutoRun(autoRunStatus);
	this.currStep = stepNum;
	currTime = this.stepTimeArray[stepNum-1];
	
	for (i=0; i<this.animationArray.length; i++) {
			this.playAnimFrom(this.animationArray[i],currTime);
	}
}

/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.scrollAnimation = function(time) {
//	var currTime = 0;	
	
//	this.setPlayingAutoRun(autoRunStatus);
//	this.currStep = stepNum;
//	currTime = this.stepTimeArray[stepNum-1];
	
	for (i=0; i<this.animationArray.length; i++) {
			this.playAnimFrom(this.animationArray[i],time);
	}
}

/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.playAnimFrom = function(aName,time) {
	this.vmp.StopAnim('MTSTimeElem.' + aName);
	this.vmp.SetProperty('MTSTimeElem.' + aName, 'rwnd', 1, 'mts_int');
	this.vmp.ResetAnim('MTSTimeElem.' + aName);
	this.vmp.SetProperty('MTSTimeElem.' + aName, 'tinc', time, 'mts_real');
	this.vmp.StartAnim('MTSTimeElem.' + aName);
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.playAnimation = function() {
	this.playStep(1,true);
}

/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.resetAnimation = function() {
	var aname = '';
	
	this.playingAutoRun =  false;
	this.currStep = -1;

	for (i=0; i<this.animationArray.length; i++) {		
		aname = this.animationArray[i];
		this.vmp.StopAnim('MTSTimeElem.' + aname);
		this.vmp.ResetAnim('MTSTimeElem.' + aname);
		this.vmp.SetProperty('MTSTimeElem.' + aname, 'tinc', 0.01, 'mts_real');
	}
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.pauseAnimation = function() {
	
	for (i=0; i<this.animationArray.length; i++) {
		this.vmp.StopAnim('MTSTimeElem.' + this.animationArray[i]);
	}
}


/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.resumeAnimation = function(time) {
	
	for (i=0; i<this.animationArray.length; i++) {
			this.playAnimFrom(this.animationArray[i],time);
	}	
}

/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.resetCamera = function() {
	this.vmp.SetProperty('MTSScene', 'rstc', '1', 'mts_int');
}

/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.handleFSCommand = function(command, args) {
	if (command == "play") {
		this.playAnimation();
	}
	else if (command == "pause") {
		this.pauseAnimation();
	}
	else if (command == "resume") {
		this.resumeAnimation(args);
	}
	else if (command == "reset") {
		this.resetAnimation();
	}
	else if (command == "step") {
		this.playStep(args,false);		
	}
	else if (command == "resetCamera") {
		this.resetCamera();		
	}	
	else if (command == "scroll") {
		this.scrollAnimation(args);
	}
}

/*************************************************
FUNCTION:
VERSION: 2.0
*************************************************/

animStepTime.prototype.toString = function() {
  	var str = '';

	str = 'ANIMATIONS\n';
	for (i=0; i<this.animationArray.length; i++)	{
		str += this.animationArray[i] + '\n';
	}
	
	str += '\nSTEPS\n';
	for (i=0; i<this.stepArray.length; i++) {
		str += this.stepArray[i] + ' ' + this.stepTimeArray[i] + '\n';
	}

	return str;
}