/*
*  public class
*  audio code class controls the audio playback in the course
*/

package {
	import flash.display.MovieClip;
		import flash.events.*;
		import flash.media.SoundMixer;
	public class Audio_Code extends MovieClip {

		public var contentLevel:MovieClip;

		
		public var audioStepOn:Boolean;
		public var audioNmbr:int;
		public var num:int;
		public var checkNum:int;
		public var audioCount:int;
		public var tlNum:int;
		public var animCounterArray:Array;
		public var checkerArray:Array;
		public var arrayIncorrResult:int;

		
		private var islAppRoot:Object=new Object  ;
		
		/*
		*  @public
		*  class constructor, defines the main arguments and loads current movie
		*  to the main container
		*/
		public function Audio_Code() {
			audioStepOn=false;
			audioNmbr=0;

			animCounterArray=new Array  ;
			checkerArray=new Array  ;

			contentLevel=new MovieClip  ;
			contentLevel=CGlobal.content_mc ;
			
			

			CGlobal.CurrentPage=CGlobal.content_mc ;
		}
			var scrTxtArray:Array=new Array() ;
		/*
		*  @public
		*  sets the main audio arguments, checks if the audio is on, and initiates the 
		*  audio playback
		*/
		public function initAudio(audioTotal:int=0) {
			contentLevel.byPassCheckPoint=false;

			if (! islAppRoot.islMainPlayerRunning) {
				contentLevel=CGlobal.content_mc; 
				
			} else {
				contentLevel=CGlobal.content_mc;
			}// end else if
			num=1;
			audioCount=1;
			tlNum=audioTotal;
			if (contentLevel.audioStep == "on") {
				
				scrTxtArray=new Array() ;
				for (var _loc1=1; _loc1 < tlNum; ++_loc1) {
					if (contentLevel["body_text_" + _loc1] != "") {
						scrTxtArray.push(contentLevel["body_text_" + _loc1]);
						contentLevel["body_text_" + _loc1 + "_COMP"].visible=false;
					}// end if
				}// end of for
			}// end if
			arrayIncorrResult=0;
			checkNum=0;
			
			if (contentLevel.backgroundAudio == "on")
			{
				contentLevel.audio_holder.bkgSndMC_1.gotoAndPlay("start");
			}// end if
			if (contentLevel.audio_startPoint == "beginning") {
				playAudio(num);
				
				
			} else {
							
				addEventListener(Event.ENTER_FRAME,LoadplayAudio);
			}// end else if
		}// End of the function

		/*
		*  @public
		*  receives an Enter Frame event and calls the playAudio function
		*/
		public  function LoadplayAudio(e:Event) {
			
			if (contentLevel.currentFrame == contentLevel.audio_startPoint) {
							
				playAudio(num);
				removeEventListener(Event.ENTER_FRAME,LoadplayAudio);
			}// end if
		}
		
		/*
		*  @public
		*  receives the required audio track number and plays the corresponding
		*  audio track from the audio movie
		*/
		public  function playAudio(audioNum) {
			audioNmbr=audioNum;
			var _loc2=tlNum;
						
			new SoundPH(contentLevel.audio_holder,"snd_" + audioNmbr,"sndMC_" + audioNmbr,"start",true)
			
			if (CGlobal.checkLabel(contentLevel.audio_holder,"snd_" + audioNmbr))
				contentLevel.audio_holder.gotoAndStop("snd_" + audioNmbr);
						
			contentLevel.currentAudioSegment=contentLevel.audio_holder["sndMC_" + audioNmbr];
			
			contentLevel.currentMainScreenAudioSegment = contentLevel.audio_holder["sndMC_" + audioNmbr];
			if (contentLevel.audio_holder["sndMC_" + audioNmbr] == undefined) {
				if (CGlobal.CurrentPage.type != "question") {
					
				}// end if
			}// end if
			if (contentLevel.audioStep == "on") {
				contentLevel["body_text_" + audioNmbr + "_COMP"].visible=true;
			} else if (contentLevel.audioStep == "off" && CGlobal.showAllTxt == 0) {
				++CGlobal.showAllTxt;
				for (var _loc1=audioNmbr; _loc1 <= _loc2; ++_loc1) {
					contentLevel.txtBox=contentLevel.txtBox + scrTxtArray[_loc1];
				}// end of for
			  }// end else if 
		}// End of the function
		
		
		/*
		*  @public
		*  plays the next audio by incrementing the audio count and calling
		*  the playAudio function with the next audio number
		*/
		public function nextAudio() {
			++audioCount;
			playAudio(audioCount);
		}// End of the function
		
		/*
		*  @public
		*  generates the audio track name to be used in loading the right audio track
		*/
		public function audioAnim(stepNum) {
			if (contentLevel.audio_cuePoints == "on") {
				if (CGlobal.checkLabel(contentLevel,"audio_cue_" + stepNum))
				{
					contentLevel.gotoAndPlay("audio_cue_" + stepNum);
				}
		
			}// end if
			
		}// End of the function


		/*
		*  @public
		*  plays the extra audio
		*/
		function extraAudioPlay(frName) {
			
			contentLevel.byPassCheckPoint=true;
			contentLevel.currentMainScreenAudioSegment=undefined;
			
			
				new SoundPH(contentLevel.audio_holder,frName,frName + "_sndMC","start",true);
				
			
			
			if (CGlobal.CurrentPage.type == "basic") {
				labelCheckPoint();
			}// end if
		}// End of the function
		
		/*
		*  @public
		*  stops the extra audio
		*/
		function extraAudioStop(frName) {
			if(contentLevel.audio_holder[frName + "_sndMC"])
			contentLevel.audio_holder[frName + "_sndMC"].gotoAndStop(1);
		}// End of the function
		
		/*
		*  @public
		*  checks if the audio is set to off or ended and stops the audio playback 
		*/
		public function labelCheckPoint() {
			if (contentLevel.byPassCheckPoint == true && contentLevel.currentFrame < contentLevel.totalFrames) {
				contentLevel.play();
				
			} else if (contentLevel.screenAudio == "off" || contentLevel.audio_cuePoints == "off") {
				
				contentLevel.play();
			} else {
				
				contentLevel.stop();
			}// end else if
		}// End of the function



	} // close of class
} // closed of package