/******************************************
 * @author Maria A. Zamora
 * @company Digitec Interactive Inc.
 * @version 0.1
 * @date 12/14/2010
 *
 * LessonsCEE class for lessonsFrame5 movie of the CEE application
 * CS5 version of com.digitec.cee.LessonsCEE
 *
 *******************************************/
package com.digitec.cee {
	//import flash.geom.Rectangle;
	import flash.printing.*;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.*;
	import flash.text.StyleSheet;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import fl.controls.UIScrollBar;
	import fl.controls.ScrollBarDirection;
	import flash.net.NetConnection;
	import flash.net.NetStream;
	import flash.media.Video;
	import flash.display.Loader;
	import flash.display.LoaderInfo;
	import flash.net.*;
	import flash.text.*;
	import flash.media.SoundMixer;
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import flash.text.Font;


	public class LessonsCEE extends BaseCEE {
		private static const OVERVIEW: String = "definition";
		private static const LESSONS: String = "lessons";
		private static const TIPS: String = "tips";
		private static const RESOURCES: String = "resources";
		private static const RELATED: String = "related";
		private var myFormat3: TextFormat;
		private var currentTab: String;
		private var contentItem: ConceptItem;
		private var conceptTxtField: TextField;
		private var glossTxtField: TextField;
		private var vScrollBar: UIScrollBar;
		private var vScrollBar2: UIScrollBar;
		private var flagGlossaOpen: Boolean; //Glossary Tab is closed				
		private var flagfGlossaOpen: Boolean; //Full Glossary Tab is closed
		private var glossary: Glossary;
		private var relatedItemsArr: Array;
		private var dw_quizgood;
		//private var dw_quizgood:contentItem.conceptTips;
		private var myFont2: Font = new Font1();
		private var versionField: TextField;
		private var videoHolder: VideoHolder;
		private var fl_Loader: Loader;
		private var dwactivevid = 0;
		private var fl_quizloader: Loader;
		private var fl_PICLoader: Loader;
		private var fl_PICLoader2: Loader;
		private var fl_ToLoad: Boolean = true; //This variable keeps track of whether you want to load or unload the SWF		
		private var vscrollglss: Boolean = false;
		private var vscrollconcept: Boolean = false;
		//private var myFont:Font = new Font1();
		private var isfullscreenset: Boolean;
		//private var ppLines:Number=70;		
		//private var ppLines:Number=48; <--on Hope's computer - font difference - count the # of lines on a full printed page to get this # - 54 for Dave's box
		private var ppLines: Number = 54
		private var videoObj: Object;
		private var cRelated_txt: TextField;
		private static const PAUSE_ME: String = "pauseMe";
		private var videoMC: MovieClip;
		private var dprintOver: Boolean = false;
		private var dprintLessons: Boolean = false;
		private var dprintTips: Boolean = false;
		private var dprintOnline: Boolean = false;
		private var dprintQuiz: Boolean = false;

		private var quiz: Quiz;
		private var arrayOfQuestions: Array;
		private var numberOfQuestions: int;
		private var correctQuestions: int;
		private var currQuestionNum: int;
		private var currCorrectAnswer: int;
		private var currCorrectAnswerText: String;
		private var currSelectedAnswer: int;
		private var emailAddress: String;
		private var xmlQuiz: String = MainConstants.XMLPATH + MainConstants.XMLQUIZ;
		private var emailButtonOn: Boolean;
		private var printButtonOn: Boolean;


		private var $nc: NetConnection;
		private var $ns: NetStream;
		private var $streampath: String;
		private var $streamurl: String = MainConstants.CEE_SERVER + MainConstants.XMLQUIZ;
		private var quizidSET;
		//private var quizidSET=3;
		//HEADER STRINGS
		private var conceptTitle_str: String;

		//MAX ANSWERS THAT FIX IN DISPLAY
		private var maxAnswers: int;

		//FOR FEEDBACK - SCREEN 3
		private var CORRECT_STR: String;
		private var INCORRECT_STR: String;
		private var correct_feedback: String;
		private var incorrect_feedback: String;
		private var dwthisispos: Number;
		//FOR QUIZCOMPLETED - SCREEN 4
		private var ANSW1_SCREEN4: String;
		private var ANSW2_SCREEN4: String;
		private var ANSW3_SCREEN4: String;
		private var COMPLETE_SCREEN4: String;
		private var questionField: TextField;
		private var lettersArr: Array = new Array("A", "B", "C", "D", "E");
		private var questionIdObj_arr: Array = new Array();
		private var questionAnsObj_arr: Array = new Array();
		private var currentQuestionId: String;
		private var currentQuestionTxt: String;
		private var currentCorrectTxt: String;
		private var btnAnswerId_arr: Array = new Array();
		private var btnAnswerTxt_arr: Array = new Array();
		private var vidpicpath: String;

		public function LessonsCEE() {
			super(MainConstants.XMLLESSONS);
			setup();

		}

		/*******************************************************************
		 * FUNCTION: SETUP FRAME TEXT_FIELDS  FROM XML
		 *******************************************************************/
		override public function setFramesText(_xml: XML): void {

			var passpath = Object(parent).getDpath();

			glossary = new Glossary();
			glossary.setpath(passpath);
			
			//SET CONCEPT TEXT AREA	
			var myFont: Font = new Font1();
			var myFormat: TextFormat = new TextFormat();
			myFormat.font = myFont.fontName;
			myFormat.size = 14;
			//myFormat.color = 0xFF00FF;
			
			conceptTxtField = new TextField();
			conceptTxtField.defaultTextFormat = myFormat;
			conceptTxtField.x = 51;
			conceptTxtField.y = 133;

			conceptTxtField.height = 340;
			conceptTxtField.width = 475;
			conceptTxtField.background = false;
			conceptTxtField.border = false;
			conceptTxtField.multiline = true;
			conceptTxtField.wordWrap = true;
			conceptTxtField.embedFonts = true;

			addChild(conceptTxtField);

			//LOAD CSS AND APPLY TO TEXT AREA
			var GETLISTXML = Object(parent).getDpath();
			var cssUrl: URLRequest = new URLRequest(GETLISTXML + "_VE50DATA/" + MainConstants.CSS_CONCEPT_COPY);
			
			trace("[LEssonsCEE.as:175]" + MainConstants.CSS_CONCEPT_COPY);
			//CSS_CONCEPT_COPY
			var cssLoader: URLLoader = new URLLoader();

			cssLoader.load(cssUrl);
			cssLoader.addEventListener(Event.COMPLETE, cssLoaded);
			function cssLoaded(event: Event): void {
				trace("[LessionsCEE.as:181] cssLoaded");
				var css: StyleSheet = new StyleSheet();
				css.parseCSS(URLLoader(event.target).data);
				conceptTxtField.styleSheet = css; //////////////////////////////////////////////////////////////////////////
				// conceptTxtField.textField.styleSheet = css;
			}

			//needs to pull from concept
			//this.title_tf.text = _xml.xtitle;			

			this.clickAbove_tf.text = _xml.xclickAbove;
			//this.logo1_tf.text =  _xml.xlogo1;
			//this.logo2_tf.text =  _xml.xlogo2;
			//this.version2_tf.text =  _xml.xversion2;			
			var myFormat2: TextFormat = new TextFormat();
			myFormat2.font = myFont2.fontName;
			myFormat2.size = 12;
			myFormat2.color = 0x8DC269;
			myFormat2.bold = true;
			versionField = new TextField();
			versionField.defaultTextFormat = myFormat2;
			versionField.height = 17;
			versionField.width = 50;
			versionField.background = false;
			versionField.border = false;
			versionField.multiline = true;
			versionField.wordWrap = true;
			versionField.x = 415;
			versionField.y = 581;
			versionField.embedFonts = true;
			versionField.text = _xml.xversion2;
			vtxtmc.addChild(versionField);
			this.register_tf.text = _xml.xregister;

			//SET THE CURRENT TAB TO DEFINITION= OVERVIEW
			currentTab = OVERVIEW;

			var myFont3: Font = new Font1();
			myFormat3 = new TextFormat();
			myFormat3.font = myFont.fontName;
			myFormat3.size = 12;


			conceptTxtField.embedFonts = true;
			//SET GLOSSARY TEXT FIELD						
			glossTxtField = new TextField();
			glossTxtField.defaultTextFormat = myFormat3;
			glossTxtField.x = 16;
			glossTxtField.y = 15;
			glossTxtField.height = 273;
			glossTxtField.width = 160;
			glossTxtField.background = false;
			glossTxtField.border = false;
			glossTxtField.multiline = true;
			glossTxtField.wordWrap = true;
			glossTxtField.scrollV = 1;
			glossTxtField.embedFonts = true;
			this.glossary_mc.addChild(glossTxtField);




			var myFont4: Font = new Font1();
			var myFormat4: TextFormat = new TextFormat();
			myFormat4.font = myFont4.fontName;
			myFormat4.size = 12;
			myFormat4.color = 0xFFFFFF;
			myFormat4.underline = true;
			myFormat4.bold = true;
			//CREATE TEXT FIELD FOR RELATED LINKS			
			cRelated_txt = new TextField();
			cRelated_txt.defaultTextFormat = myFormat4;
			cRelated_txt.height = 149;
			cRelated_txt.width = 168;
			cRelated_txt.background = false;
			cRelated_txt.border = false;
			cRelated_txt.multiline = true;
			cRelated_txt.wordWrap = true;
			cRelated_txt.x = 586;
			cRelated_txt.y = 353;
			cRelated_txt.embedFonts = true;
			addChild(cRelated_txt);

			//CREATE VIDEO HOLDER
			videoHolder = new VideoHolder();
			videoHolder.x = 0;
			videoHolder.y = 0;

			addEventListener(HCustomEvent.ADD_GLOSSARY, addGlossary, true);

		}

		/*************************************************************************************
		 * FUNCTIONS: SET THE CONTENT ITEM OBJECT FOR FIRST TIME
		 ************************************************************************************/
		private function glossaryScrollGo() {
			vscrollglss = true;
			vScrollBar = new UIScrollBar();
			vScrollBar.direction = ScrollBarDirection.VERTICAL;
			vScrollBar.width = glossTxtField.width;
			vScrollBar.move(glossTxtField.x + glossTxtField.width, glossTxtField.y);
			vScrollBar.height = glossTxtField.height;
			vScrollBar.scrollTarget = glossTxtField;

			this.glossary_mc.addChild(vScrollBar);
		}
		private function glossaryScrollConcept() {
			vscrollconcept = true;

			vScrollBar2 = new UIScrollBar();
			vScrollBar2.direction = ScrollBarDirection.VERTICAL;
			vScrollBar2.width = conceptTxtField.width;
			vScrollBar2.move(conceptTxtField.x + conceptTxtField.width, conceptTxtField.y);
			vScrollBar2.height = conceptTxtField.height;
			vScrollBar2.scrollTarget = conceptTxtField;

			addChild(vScrollBar2);
		}
		public function setConceptText(concept: ConceptItem) {

			contentItem = concept;
			this.title_tf.text = contentItem.conceptName
			conceptTxtField.addEventListener(TextEvent.LINK, linkEvent);
			setRelated();
			dw_quizgood = contentItem.conceptQuiz;
			//trace("dw_quizgood"+dw_quizgood);
			setTabContent(OVERVIEW);
		}

		/*************************************************************************************
		 * FUNCTIONS: SET RELATED CONCEPTS
		 ************************************************************************************/
		public function setRelated() {
			////////// var cssRelated:StyleSheet = new StyleSheet();
			///////////////cssRelated.setStyle("a:hover", {textDecoration:"underline"} );

			relatedItemsArr = new Array();
			var conItem: ConceptItem;

			var str: String = "";
			if (contentItem.relatedConceptsArr != null) {
				var arr: Array = contentItem.relatedConceptsArr;
				//EXTRACT RELATED CONCEPTS IDS FROM ARRAY
				//GET FROM MAIN THE CONCEPT ITEM
				//CREATE AN ARRAY OF RELATED CONCEPTS ITEMS ///////////////////////MAYBE WE DONT NEED THIS
				//CREATE A STRING WITH RELATED CONCEPT ITEMS NAMES				
				for (var r: int = 0; r < arr.length; r++) {
					conItem = Object(parent).getConceptItemPerId(arr[r]);
					//relatedItemsArr.push( conItem );
					relatedItemsArr[r] = conItem;
					//str += "<p>"+ conItem.conceptName+ "</p>\n";
					str += "<p><b><u><a href= 'event:viewRelated," + arr[r] + "'>" + conItem.conceptName + "</a></u><b></p>\n";
					//str += "<p><font face='Verdana, Geneva, sans-serif' size='12' color='#FFFFFF' ><bold><u><a href= 'event:viewRelated,"+arr[r]+"'>"+conItem.conceptName +"</a></u></bold></font></p><br>";																		
				}
			}
			cRelated_txt.addEventListener(TextEvent.LINK, linkEventRelated);
			cRelated_txt.htmlText = "" + str;
			//cRelated_txt.styleSheet = cssRelated;								

		}

		/*************************************************************************************
		 * FUNCTIONS: EVENT  HANDLER FOR TEXT LINKS IN RELATED CONCEPTS
		 ************************************************************************************/
		private function linkEventRelated(e: TextEvent): void {
			var linkContent: Array = e.text.split(",");
			var functionName: String = linkContent[0];
			var args: String = linkContent[1];

			switch (functionName) {
				case "viewRelated":
					var conceptitem: ConceptItem = Object(parent).getConceptItemPerId(args);
					//trace("args                                     "+args);
					Object(parent).setlessonpage(conceptitem);
					//Object(parent).setIDLessonpage(ConceptItem);
					setConceptText(conceptitem);
					break;
				default:
					trace("function not found");
			}
		}

		/*************************************************************************************
		 * FUNCTIONS: SHOW LINK DEFINITION IN THE GLOSSARY
		 ************************************************************************************/
		private function getTabContent(): String {
			/*
			dprintOver
			dprintLessons
			dprintTips
			dprintOnline
			dprintQuiz
			*/
			var tempString: String = "";
			var tempString1: String = "";
			var tempString2: String = "";
			var tempString3: String = "";
			var tempString4: String = "";
			var tempString5: String = "";
			if (dprintOver == true) {
				//trace("string 1 good");
				tempString1 = "<font size='14'><b>Overview</b><BR>" + contentItem.conceptDefinition + "<BR><BR>";
			}
			if (dprintLessons == true) {
				//trace("string 2 good");
				tempString2 = "<font size='14'><b>Lessons</b></font><BR>" + contentItem.conceptLessons + "<BR><BR>";
			}
			if (dprintTips == true) {
				//trace("string 3 good");
				tempString3 = "<font size='14'><b>Tips</b></font><BR>" + contentItem.conceptTips + "<BR><BR>";
			}
			if (dprintOnline == true) {
				//trace("string 4 good");
				tempString4 = "<font size='14'><b>Online Resources</b></font><BR>" + contentItem.conceptResources + "<BR><BR>";
			}
			if (dprintQuiz == true) {
				//trace("string 5 good");
				tempString5 = "<font size='14'><b>Quiz</b></font><BR>" + currentQuestionTxt;
				//tempString5 = contentItem.conceptResources+"<BR>";
			}
			//tempString=contentItem.conceptDefinition+"<BR>"+contentItem.conceptLessons+"<BR>"+contentItem.conceptTips+"<BR>"+contentItem.conceptResources;			
			tempString = "<font size='14'><b>" + contentItem.conceptName + "</b></font><BR><BR>" + tempString1 + tempString2 + tempString3 + tempString4 + tempString5 + "<br><br>Copyright © Council for Economic Education. http://www.councilforeconed.org";

			return tempString;
		}
		private function init2(): void {
			//removeEventListener(Event.ADDED_TO_STAGE, init);									
			//var streamtemp =$streamurl+ dwpasspub;

			vidpicpath = Object(parent).getDpath();
			loadQuizXML(vidpicpath + "_VE50DATA/" + xmlQuiz);
			trace("vidpicpath[LessonsCEE.as:411]: + _VE50DATA/+xmlQuiz  " + vidpicpath + "_VE50DATA/" + xmlQuiz);

			//2019-07-12 NOLOAD
			/*
			trace("vidpicpath+ _VE50DATA/+xmlQuiz  " + vidpicpath + "_VE50DATA/" + xmlQuiz)
			var myurlloadertemp: URLLoader = new URLLoader();
			var myurlreqtemp: URLRequest = new URLRequest($streamurl);
			myurlloadertemp.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandlerQUIZ);
			myurlloadertemp.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			myurlloadertemp.load(myurlreqtemp);
			*/

			// loadXML();			
		}
		private function httpStatusHandlerQUIZ(event: HTTPStatusEvent): void {
			//trace("httpStatusHandler: -----------------------------------" + event);
			//trace("status: " + event.status);
			if (event.status == 0) {

				loadQuizXML(vidpicpath + "_VE50DATA/" + xmlQuiz);
			} else {
				loadQuizXML($streamurl);
			}
			//loadLibraryFinal(MainConstants.XMLPATH + dwpasspub);
		}




		/*******************************************************************
		 * FUNCTION:  TO LOAD TEXT FROM A XML FILE
		 *******************************************************************/
		private function loadQuizXML(stream: String): void {
			//TRYI FIRST TO CONNECT TO CEE SERVER 
			//trace("here first");
			var myurlloader: URLLoader = new URLLoader();

			var myurlreq: URLRequest = new URLRequest(stream);
			//myurlreq.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			myurlloader.load(myurlreq);
			myurlloader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			myurlloader.addEventListener(Event.COMPLETE, loadData);
			//myurlloader.addEventListener(Event.CONNECT, connectServer);

			function loadData(evt: Event) {
				var _xml: XML = new XML(myurlloader.data);
				currQuestionNum = 0;
				maxAnswers = 5;
				//CREATE THE QUIZ OBJECT WITH 5 ANSWERS PER QUESTION														

				//SET HEADER STRINGS
				//myXML.IMAGE.(@TITLE=="school")
				//trace("_xml.quizconcept.quizid.length() "+_xml.quizconcept.quizid.length());
				for (var i: int = 0; i < _xml.quizconcept.quizid.length(); i++) {
					var dwquiztemp2 = _xml.quizconcept.quizid[i];
					//trace("dwquiztemp2    "+dwquiztemp2);
					//trace("contentItem.conceptID    "+contentItem.conceptID);
					if (dwquiztemp2 == contentItem.conceptID) {
						dwthisispos = i;
						i = _xml.quizconcept.quizid.length();
					}
				};
				//trace(dwthisispos);

				quiz = new Quiz(_xml, maxAnswers, dwthisispos);
				arrayOfQuestions = quiz.questionsArr;
				numberOfQuestions = quiz.numOfQuestions;
				currentQuestionTxt = "";
				//trace("numberOfQuestions "+numberOfQuestions);
				for (var i2: int = 1; i2 < numberOfQuestions + 1; i2++) {
					//trace("Clip here   "+i2);
					currQuestionNum = i2;
					setQuestion(currQuestionNum);
				};

			}
		}
		private function ioErrorHandler(event: IOErrorEvent): void {
			trace("ioErrorHandler: " + event);
		}
		private function setQuestion(questionNum: int): void {

			var _questionObj: Question = arrayOfQuestions[questionNum - 1]
			currentQuestionTxt = currentQuestionTxt + "Question: " + _questionObj.question.toString() + "<BR>";
			//trace("currentQuestionTxt  t"+currentQuestionTxt);
			//question_txt.text =  _questionObj.question.toString();						

			currentQuestionId = _questionObj.thequestionId.toString(); /////////////////////////////////////////////////////////////////////////////////
			//trace("currentQuestionId===="+currentQuestionId);



			var _answers: Array = _questionObj.answers;
			//trace("_questionObj.answers.length       "+_questionObj.answers.length);
			var btnNum: int = _answers.length;
			//trace("btnNum   "+btnNum);
			//if( btnNum > 5){ btnNum = 5; }  //max is 5 buttons
			for (var index: int = 0; index < btnNum; index++) {

				//trace("________________Here");				
				currentQuestionTxt = currentQuestionTxt + "Answer: " + _answers[index].Answer + "<BR>";
				//var questionField = _answers[index].Answer; //////////////////////////////////////////////////////////////////////////////////////////////
				//trace(questionField);//
				//questionField.htmlText = "<p><a href= 'event:answerSelected,"+_answers[index].AnswerId+"'>"+_answers[index].Answer+"</a></p>";
				//rowsArr[i].textHolder.htmlText = "<p><font size='12' color='#588527' ><bold><u><a href= 'event:viewLesson,"+item.id+"'>"+item.title +"</a></u></bold></font></p>"+"<p>"+ item.desc+"</p>";									
				//btnAnswerId_arr[index] =  _answers[index].AnswerId;////////////////////////////////////////////////////Id asssociated with the button (answer)
				//btnAnswerTxt_arr[index] =  _answers[index].Answer;
				//trace( "btnAnswerId_arr[index]=========="+ btnAnswerId_arr[index] );
				//trace( "btnAnswerId_arr[index]=========="+ btnAnswerTxt_arr[index] );

				//previousAnswerTextFields_arr.push(questionField);////////////////////////////////////////


				//this["textBckg_" + lettersArr[index] ].answer_txt.text = _answers[index];
			}
			currentQuestionTxt = currentQuestionTxt + "<BR>";
			//trace("currentQuestionTxt     "+currentQuestionTxt);
			//currCorrectAnswer = _questionObj.correctAnswerPosition;	
			//currCorrectAnswerText = _questionObj.correctAnswer;
		}
		private function setTabContent(tab: String) {

			currentTab = tab;
			conceptTxtField.htmlText = "";

			if (tab == OVERVIEW) {


				tabOverview_mc.gotoAndStop(2);
				tabLessons_mc.gotoAndStop(1);
				tabTips_mc.gotoAndStop(1);
				tabResources_mc.gotoAndStop(1);
				conceptTxtField.htmlText = contentItem.conceptDefinition;
				
				if (contentItem.conceptResources == "") {
					this.tabResources_mc.visible = false;
				} //NEW
			} else if (tab == LESSONS) {
				tabOverview_mc.gotoAndStop(1);
				tabLessons_mc.gotoAndStop(2);
				tabTips_mc.gotoAndStop(1);
				tabResources_mc.gotoAndStop(1);
				conceptTxtField.htmlText = contentItem.conceptLessons;
				//trace("CONCEPT LESSONS+"+contentItem.conceptLessons);

			} else if (tab == TIPS) {
				tabOverview_mc.gotoAndStop(1);
				tabLessons_mc.gotoAndStop(1);
				tabTips_mc.gotoAndStop(2);
				tabResources_mc.gotoAndStop(1);
				conceptTxtField.htmlText = contentItem.conceptTips;

			} else if (tab == RESOURCES) {
				//conceptTxtField.htmlText ="Resources!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";			
				//trace("contentItem.conceptResources"+contentItem.conceptResources); //NEW
				conceptTxtField.htmlText = contentItem.conceptResources; //NEW
				tabOverview_mc.gotoAndStop(1);
				tabLessons_mc.gotoAndStop(1);
				tabTips_mc.gotoAndStop(1);
				tabResources_mc.gotoAndStop(2);

			}

			if (vscrollconcept == false && conceptTxtField.numLines > 21) {
				glossaryScrollConcept();
				vScrollBar2.update();
			} else if (vscrollconcept == true && conceptTxtField.numLines > 21) {
				//glossaryScrollConcept();

				vScrollBar2.update();
			} else if (vscrollconcept == true && conceptTxtField.numLines < 22) {
				//glossaryScrollConcept();
				vscrollconcept = false;
				this.removeChild(vScrollBar2);
				//vScrollBar2.update();
			}
			fl_PICLoader = new Loader(); //NEW
			vidpicpath = Object(parent).getDpath();

			var picPath: String = "" + vidpicpath + "_VE50DATA/" + MainConstants.THUMBPIC_PATH + contentItem.conceptID + ".jpg"; //NEW
			fl_PICLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete);
			fl_PICLoader.load(new URLRequest(picPath));

			//thumb = Bitmap(fl_PICLoader.content);
			//thumb.smoothing = true;
			//this.videoButton.picholder_mc.addChild(thumb);
			//NEW
			init2();
		}
		private function loadProdComplete(e: Event): void {
			var bit: Bitmap = e.target.content;
			if (bit != null) {
				bit.smoothing = true;
				bit.width = 170;
				bit.height = 170;
			}

			this.videoButton.picholder_mc.addChild(e.target.content);
		}
		//tf.addEventListener(TextEvent.LINK, linkEvent);		

		/*************************************************************************************
		 * FUNCTIONS: EVENT  HANDLER FOR LINKS IN CONTENT TEXT AREA
		 ************************************************************************************/
		private function linkEvent(txtEvt: TextEvent): void {
			//trace("EVENT=============================="+txtEvt.text);
			var functionArr: Array = HelperFunctions.extractFunctionName(txtEvt.text);
			//var functionArr:Array = extractFunctionName( txtEvt.text );
			var functionName: String = functionArr[0];
			var args: String = functionArr[1];
			switch (functionName) {
				case "defineGlossaryTerm":
					//trace("trip 1");
					this.defineGlossaryTerm(args);
					break;

				case "viewLesson":
					this.viewLesson(args);
					break;

				case "viewPublication":
					this.viewPublication(args);
					break;

				case "gotoKeywordSearch":
					this.gotoKeywordSearch(args);
					break;
				case "gotoWebPage":
					this.gotoWebPage(args);
					break;
				default:
					trace("function not found");
			}
		}
		//fullGlossary_btn
		/*************************************************************************************
		 * FUNCTIONS: CLICK TABS OF TEXT AREA
		 ************************************************************************************/
		public function clickOverviewTab(event: MouseEvent): void {
			setTabContent(OVERVIEW);
		}
		public function clickLessonsTab(event: MouseEvent): void {
			setTabContent(LESSONS);
		}
		public function clickTipsTab(event: MouseEvent): void {
			setTabContent(TIPS);
		}
		public function clickResourcesTab(event: MouseEvent): void {
			setTabContent(RESOURCES);
		}
		private function gotoKeywordSearch(str: String): void {
			if (str != null) {}
		}

		/*************************************************************************************
		 * FUNCTIONS:VIEW LESSONS
		 ************************************************************************************/
		private function viewLesson(str: String): void {
			//trace(str);
			if (str != null) {
				//var lessonitem:LessonItem = getLessonPerId( id );
				//pdfFile = lessonitem.pdf_url;
				Object(parent).setPDFLesson(str, false); //isLessonBrowse type = false

				Object(parent).setLastPDFlessonId(str, false); //remember last pdf
			}
		}

		private function gotoWebPage(str: String): void {
			//trace(str);
			if (str != null) {
				//var lessonitem:LessonItem = getLessonPerId( id );
				//pdfFile = lessonitem.pdf_url;
				var request: URLRequest = new URLRequest(str);
				navigateToURL(request, '_blank');
			}
		}
		/*************************************************************************************
		 * FUNCTIONS:VIEW PUBLICATIONS
		 ************************************************************************************/
		private function viewPublication(str: String): void {
			if (str != null) {
				//cRelated_txt.text = "View Publications: "+ str;												
				//trace("In Lessons, Publication Id = "+ str);
				Object(parent).setPublicationLesson(str, false); //isLessonBrowse type = false
				Object(parent).setLastPubId(str, false);
			}
		}

		/*************************************************************************************
		 * FUNCTIONS:DEFINE A GLOSSARY TERM
		 ************************************************************************************/
		private function defineGlossaryTerm(str: String): void {
			//glossTxtField.textField.styleSheet  = glossary.getStyleSheet();
			//glossTxtField.styleSheet  = glossary.getStyleSheet();
			/*
			glossTxtField.htmlText= glossary.defineGlossaryTerm(str);															
			glossTxtField.styleSheet  = glossary.getStyleSheet();			
			 vScrollBar.update();
			 */
			var tempText = glossTxtField.htmlText;
			trace("glossary go");
			//glossTxtField.styleSheet  = glossary.getStyleSheet();
			//glossTxtField.defaultTextFormat = myFormat3;
			//glossTxtField.embedFonts=true;
			glossTxtField.htmlText = glossary.defineGlossaryTerm(str) + "<BR>" + tempText;
			trace("vscrollglss  " + vscrollglss);
			trace("scroll lines  " + glossTxtField.numLines);
			if (vscrollglss == false && glossTxtField.numLines > 19) {
				glossaryScrollGo();
			}

			if (glossTxtField.numLines > 19) {
				vScrollBar.update();
			}
			// if (glossTxtField.numLines>19){
			// glossaryScrollGo();
			// 	vScrollBar.update();
			// }

			if (!flagGlossaOpen) {
				openGlossary();
			}
		}

		private function openGlossary() { //this.glossary_mc.x =577; 
			var dwx = this.glossary_mc.x;
			var myTween: Tween = new Tween(this.glossary_mc, "x", Regular.easeOut, dwx, 577, .5, true);
			this.glossary_mc.expand_txt.text = "click to hide";
			flagGlossaOpen = true;
			cRelated_txt.visible = false;

		}
		private function closeGlossary() {
			//this.glossary_mc.x =779;  
			//this.glossary_mc.fullGlossBack.x =223;  
			var dwx = this.glossary_mc.x;
			var dwx2 = this.glossary_mc.fullGlossBack.x;
			var myTween: Tween = new Tween(this.glossary_mc, "x", Regular.easeOut, dwx, 779, .5, true);
			var myTween2: Tween = new Tween(this.glossary_mc.fullGlossBack, "x", Regular.easeOut, dwx2, 223, .4, true);
			this.glossary_mc.expand_txt.text = "click to expand";
			this.glossary_mc.fullGlossarybtn_txt.text = "BROWSE FULL GLOSSARY";
			flagGlossaOpen = false;
			flagfGlossaOpen = false;
			conceptTxtField.visible = true;
			if (vscrollconcept == true) {
				vScrollBar2.visible = true;
			}
			cRelated_txt.visible = true;
		}
		private function openFGlossary() {
			//this.glossary_mc.fullGlossBack.x =-555;
			this.glossary_mc.fullGlossarybtn_txt.text = "CLOSE FULL GLOSSARY";
			var dwx2 = this.glossary_mc.fullGlossBack.x;
			var myTween2: Tween = new Tween(this.glossary_mc.fullGlossBack, "x", Regular.easeOut, dwx2, -555, .5, true);
			conceptTxtField.visible = false;
			if (vscrollconcept == true) {
				vScrollBar2.visible = false;
			}
			flagfGlossaOpen = true;
		}
		private function closeFGlossary() {
			//this.glossary_mc.fullGlossBack.x =223;  
			//this.glossary_mc.x =779; 
			var dwx = this.glossary_mc.x;
			var dwx2 = this.glossary_mc.fullGlossBack.x;
			var myTween: Tween = new Tween(this.glossary_mc, "x", Regular.easeOut, dwx, 779, .4, true);
			var myTween2: Tween = new Tween(this.glossary_mc.fullGlossBack, "x", Regular.easeOut, dwx2, 223, .4, true);
			this.glossary_mc.fullGlossarybtn_txt.text = "BROWSE FULL GLOSSARY";
			this.glossary_mc.expand_txt.text = "click to expand";
			conceptTxtField.visible = true;
			cRelated_txt.visible = true;
			if (vscrollconcept == true) {
				vScrollBar2.visible = true;
			}
			flagGlossaOpen = false;
			flagfGlossaOpen = false;
		}
		/*************************************************************************************
		 * FUNCTION: EXPAND AND HIDE THE GLOSSARY PANEL
		 ************************************************************************************/
		private function expandHideGlossary(ev: MouseEvent): void {
			if (flagGlossaOpen) {
				closeGlossary();
			} else {
				openGlossary();
			}
		}

		/*************************************************************************************
		 * FUNCTION: PRINT GLOSSARY TERMS
		 ************************************************************************************/
		private function printGlossary(ev: MouseEvent): void {
			this.myPJ.printText.htmlText = ""
			//trace("PrintGlossary");			 
			this.myPJ.printText.htmlText = "Virtual Economics V.4 : Glossary<br>" + glossTxtField.htmlText + "<br>Copyright © Council for Economic Education. http://www.councilforeconed.org";


			////////////HMD TEST HERE
			var stripf: String = this.myPJ.printText.text
			this.myPJ.printText.htmlText = stripf
			this.myPJ.printText.defaultTextFormat = myFormat3

			var numPages = cleanupText();
			var printJob: PrintJob = new PrintJob();
			//HMD Removed for test
			//var numPages:int = 0;

			if (printJob.start()) {
				//numPages = Math.ceil(myPJ.printText.numLines/ ppLines);
				//numPages = Math.ceil(myPJ.printText.numLines/ ppLines);

				for (var i: int = 0; i < numPages; i++) {
					printJob.addPage(myPJ);
					nextPage();
				}
			}
		}

		/*************************************************************************************
		 * FUNCTION: CLEAR GLOSSARY TERMS
		 ************************************************************************************/
		private function clearGlossary(ev: MouseEvent): void {
			if (vscrollglss == true) {
				//this.glossary_mc.removeChild(vScrollBar);
				this.glossary_mc.removeChild(vScrollBar);
				vscrollglss = false;
			}
			glossTxtField.htmlText = "";
		}
		/*************************************************************************************
		 * FUNCTION: ADD A TERM TO THE GLOSSARY
		 ************************************************************************************/
		private function addGlossary(e: HCustomEvent): void {

			var tempText = glossTxtField.htmlText;

			//glossTxtField.styleSheet  = glossary.getStyleSheet();
			trace("add glossary");
			glossTxtField.htmlText = "<p class='term'>" + e.data.titleText + "</p><p class='def'>" + e.data.contentText + "</p><BR>" + tempText;
			trace("vscrollglss  " + vscrollglss);
			trace("scroll lines  " + glossTxtField.numLines);
			if (vscrollglss == false && glossTxtField.numLines > 19) {
				glossaryScrollGo();
			}

			if (glossTxtField.numLines > 19) {
				vScrollBar.update();
			}

		}
		/*************************************************************************************
		 * FUNCTION: FULL GLOSSARY TERMS
		 ************************************************************************************/
		private function fullGlossary(ev: MouseEvent): void {
			//glossTxtField.htmlText="";				
			//glossTxtField.styleSheet  = glossary.getStyleSheet();
			var fGlos = glossary.getFullGlossary();
			this.glossary_mc.fullGlossBack.init(!flagfGlossaOpen);
			//open Glossary tab
			if (flagfGlossaOpen) {
				closeFGlossary();
			} else {
				openFGlossary();
			}
		}
		/*************************************************************************************
		 * FUNCTION: PRINT TABS - WITH TASKS INVOLVED
		 ************************************************************************************/
		private function nextPage(): void {
			this.myPJ.printText.scrollV = this.myPJ.printText.scrollV + ppLines;
			trace("this.myPJ.printText.scrollV      " + this.myPJ.printText.scrollV);
			trace("ppLines      " + ppLines);
		}

		private function cleanupText(): Number {
			//used to add lines to the bottom of the print area so the last page won't overlap from the previous page.
			var numPages: int = 0;
			numPages = Math.ceil(myPJ.printText.numLines / ppLines);
			trace("Cleanup Text");
			trace("Number of Lines in PJ:" + myPJ.printText.numLines);
			trace("Number of Pages:" + numPages)
			var linestoadd = (numPages * ppLines) - myPJ.printText.numLines;

			for (var ct: int = 0; ct < linestoadd; ct++) {
				trace("Lines added:" + (ct + 1));
				myPJ.printText.htmlText += "<BR>"
			}
			myPJ.printText.scrollV = 0;
			myPJ.myScrollBar.visible = false;
			return numPages
		}

		public function printTabs(ev: MouseEvent): void {
			//add stuff
			cover_mc.visible = true;
			setChildIndex(cover_mc, numChildren - 1);
			printpopup.visible = true;
			setChildIndex(printpopup, numChildren - 1);
			printpopup.select_all.addEventListener(MouseEvent.CLICK, selectAll);
			printpopup.deselect_all.addEventListener(MouseEvent.CLICK, deselectAll);
			printpopup.print_close.addEventListener(MouseEvent.CLICK, closePrint);
			printpopup.print_overview.addEventListener(MouseEvent.CLICK, overviewPrint);
			printpopup.print_lessons.addEventListener(MouseEvent.CLICK, lessonsPrint);
			printpopup.print_tips.addEventListener(MouseEvent.CLICK, tipsPrint);
			printpopup.print_online.addEventListener(MouseEvent.CLICK, onlinePrint);
			printpopup.print_quiz.addEventListener(MouseEvent.CLICK, quizPrint);
			printpopup.print_btn.addEventListener(MouseEvent.CLICK, PrintButton);
			/*
				this.myPJ.printText.htmlText=getTabContent();				
				////////////
				cleanupText();
				
				var printJob:PrintJob = new PrintJob();
				var numPages:int = 0;
			
				if (printJob.start())
				{
					numPages = Math.ceil(myPJ.printText.numLines/ ppLines);
					
					for (var i:int = 0; i < numPages; i++)
					{
						printJob.addPage(myPJ);
						nextPage();
					}
				}*/
		}
		private function selectAll(ev: MouseEvent): void {


			printpopup.print_checkbox1.gotoAndStop(2);
			printpopup.print_checkbox2.gotoAndStop(2);
			printpopup.print_checkbox3.gotoAndStop(2);
			printpopup.print_checkbox4.gotoAndStop(2);
			printpopup.print_checkbox5.gotoAndStop(2);
			dprintOver = true;
			dprintLessons = true;
			dprintTips = true;
			dprintOnline = true;
			dprintQuiz = true;
		}
		private function deselectAll(ev: MouseEvent): void {


			printpopup.print_checkbox1.gotoAndStop(1);
			printpopup.print_checkbox2.gotoAndStop(1);
			printpopup.print_checkbox3.gotoAndStop(1);
			printpopup.print_checkbox4.gotoAndStop(1);
			printpopup.print_checkbox5.gotoAndStop(1);
			dprintOver = false;
			dprintLessons = false;
			dprintTips = false;
			dprintOnline = false;
			dprintQuiz = false;
		}
		private function closePrint(ev: MouseEvent): void {

			printpopup.print_close.removeEventListener(MouseEvent.CLICK, closePrint);
			printpopup.select_all.removeEventListener(MouseEvent.CLICK, selectAll);
			printpopup.deselect_all.removeEventListener(MouseEvent.CLICK, deselectAll);
			printpopup.print_overview.removeEventListener(MouseEvent.CLICK, overviewPrint);
			printpopup.print_lessons.removeEventListener(MouseEvent.CLICK, lessonsPrint);
			printpopup.print_tips.removeEventListener(MouseEvent.CLICK, tipsPrint);
			printpopup.print_online.removeEventListener(MouseEvent.CLICK, onlinePrint);
			printpopup.print_quiz.removeEventListener(MouseEvent.CLICK, quizPrint);
			printpopup.print_btn.removeEventListener(MouseEvent.CLICK, PrintButton);
			printpopup.print_checkbox1.gotoAndStop(1);
			printpopup.print_checkbox2.gotoAndStop(1);
			printpopup.print_checkbox3.gotoAndStop(1);
			printpopup.print_checkbox4.gotoAndStop(1);
			printpopup.print_checkbox5.gotoAndStop(1);
			dprintOver = false;
			dprintLessons = false;
			dprintTips = false;
			dprintOnline = false;
			dprintQuiz = false;
			cover_mc.visible = false;
			printpopup.visible = false;
		}
		private function overviewPrint(ev: MouseEvent): void {
			if (dprintOver == false) {
				printpopup.print_checkbox1.gotoAndStop(2);
				dprintOver = true;
			} else {
				dprintOver = false;
				printpopup.print_checkbox1.gotoAndStop(1);
			}
		}
		private function lessonsPrint(ev: MouseEvent): void {
			if (dprintLessons == false) {
				printpopup.print_checkbox2.gotoAndStop(2);
				dprintLessons = true;
			} else {
				dprintLessons = false;
				printpopup.print_checkbox2.gotoAndStop(1);
			}
		}
		private function tipsPrint(ev: MouseEvent): void {
			if (dprintTips == false) {
				printpopup.print_checkbox3.gotoAndStop(2);
				dprintTips = true;
			} else {
				dprintTips = false;
				printpopup.print_checkbox3.gotoAndStop(1);
			}
		}
		private function onlinePrint(ev: MouseEvent): void {
			if (dprintOnline == false) {
				printpopup.print_checkbox4.gotoAndStop(2);
				dprintOnline = true;
			} else {
				dprintOnline = false;
				printpopup.print_checkbox4.gotoAndStop(1);
			}
		}
		private function quizPrint(ev: MouseEvent): void {
			if (dprintQuiz == false) {
				printpopup.print_checkbox5.gotoAndStop(2);
				dprintQuiz = true;
			} else {
				dprintQuiz = false;
				printpopup.print_checkbox5.gotoAndStop(1);
			}
		}
		private function PrintButton(ev: MouseEvent): void {
			this.myPJ.printText.htmlText = ""
			this.myPJ.printText.htmlText = getTabContent();
			////////////strip formatting
			var stripf: String = this.myPJ.printText.text
			this.myPJ.printText.htmlText = stripf
			this.myPJ.printText.defaultTextFormat = myFormat3

			trace("SEND CLEANUP TEXT")
			var numPages = cleanupText();

			//HMD Try this
			//numPages = Math.ceil(myPJ.printText.numLines/ppLines);
			//trace("this.myPJ.printText.htmlText      "+this.myPJ.printText.text);
			var printJob: PrintJob = new PrintJob();
			//var numPages:int = 0;

			if (printJob.start()) {
				trace("myPJ.printText.numLines-----------------------------------------------   " + myPJ.printText.numLines);
				trace("ppLines-----------------------------------------------   " + ppLines);
				//numPages = Math.ceil(myPJ.printText.numLines/ppLines);
				trace("numPages-----------------------------------------------   " + numPages);
				for (var i: int = 0; i < numPages; i++) {
					printJob.addPage(myPJ);
					nextPage();
				}
			}
			printpopup.print_close.removeEventListener(MouseEvent.CLICK, closePrint);
			printpopup.print_overview.removeEventListener(MouseEvent.CLICK, overviewPrint);
			printpopup.print_lessons.removeEventListener(MouseEvent.CLICK, lessonsPrint);
			printpopup.print_tips.removeEventListener(MouseEvent.CLICK, tipsPrint);
			printpopup.print_online.removeEventListener(MouseEvent.CLICK, onlinePrint);
			printpopup.print_quiz.removeEventListener(MouseEvent.CLICK, quizPrint);
			printpopup.print_btn.removeEventListener(MouseEvent.CLICK, PrintButton);
			printpopup.select_all.removeEventListener(MouseEvent.CLICK, selectAll);
			printpopup.deselect_all.removeEventListener(MouseEvent.CLICK, deselectAll);
			printpopup.print_checkbox1.gotoAndStop(1);
			printpopup.print_checkbox2.gotoAndStop(1);
			printpopup.print_checkbox3.gotoAndStop(1);
			printpopup.print_checkbox4.gotoAndStop(1);
			printpopup.print_checkbox5.gotoAndStop(1);
			dprintOver = false;
			dprintLessons = false;
			dprintTips = false;
			dprintOnline = false;
			dprintQuiz = false;
			cover_mc.visible = false;
			printpopup.visible = false;
		}

		//closeVideo
		/*************************************************************************************
		 * FUNCTION: CLOSE VIDEO
		 ************************************************************************************/
		private function closeVideo(ev: MouseEvent): void {

			if (dwactivevid != 0) {
				SoundMixer.stopAll();
				//videoObj.pauseMe(PAUSE_ME);
				//videoObj.resetScreen();
				if (isfullscreenset == true) {
					stage.removeEventListener(KeyboardEvent.KEY_DOWN, pressESCKey);
					videoHolder.prompttext.text = "";
					isfullscreenset = false;
				}

				videoObj = null;
				videoMC = MovieClip(null);
				videoHolder.holder.stop();
				fl_Loader.unloadAndStop();
				videoHolder.holder.removeChild(fl_Loader);

				videoHolder.holder.visible = false;
				videoHolder.vid_background.gotoAndStop(1);
				videoHolder.picholder_mc.visible = true;
				videoHolder.beginplay_mc.visible = true;
				dwactivevid = 0;

			} else {
				this.cover_mc.visible = false;
				isfullscreenset = false;
				videoHolder.beginplay_mc.removeEventListener(MouseEvent.CLICK, launchVideo);
				videoHolder.x = 0;
				videoHolder.y = 0;
				videoHolder.width = 593;
				videoHolder.height = 466.30;
				conceptTxtField.visible = true;
				//Object(parent).setfullscreen(isfullscreenset);
				removeChild(videoHolder);
				SoundMixer.stopAll();
			}
			//

		}


		/*************************************************************************************
		 * FUNCTION: LAUNCH VIDEO
		 ************************************************************************************/
		private function launchVideoQuiz(event: MouseEvent): void {
			addChild(videoHolder);
			SoundMixer.stopAll();
			this.cover_mc.visible = true;
			conceptTxtField.visible = false;
			videoHolder.beginplay_mc.visible = true;
			if (dw_quizgood == "1") {
				videoHolder.takequiz_mc.visible = true;
				videoHolder.takequiz_mc.addEventListener(MouseEvent.CLICK, launchQuiz);
			}
			videoHolder.picholder_mc.visible = false;
			fl_PICLoader2 = new Loader(); //NEW
			vidpicpath = Object(parent).getDpath();
			var picPath: String = "" + vidpicpath + "_VE50DATA/" + MainConstants.THUMBPIC_PATH + contentItem.conceptID + ".jpg"; //NEW
			//trace("picPath "+picPath);
			videoHolder.presentation_text.htmlText = "<b>" + contentItem.conceptName + "</b>";
			fl_PICLoader2.contentLoaderInfo.addEventListener(Event.COMPLETE, loadProdComplete2);
			fl_PICLoader2.load(new URLRequest(picPath));
			videoHolder.picholder_mc.visible = true;
			//videoHolder.picholder_mc.addChild(e.target.content);
			videoHolder.vid_background.gotoAndStop(1);
			videoHolder.holder.visible = false;
			videoHolder.quizclosebtn.visible = false;
			videoHolder.quizholder.visible = false;
			videoHolder.prompttext.text = "";
			videoHolder.closebtn.addEventListener(MouseEvent.CLICK, closeVideo);
			videoHolder.maxgobutton.addEventListener(MouseEvent.CLICK, TrytoMaximize);
			videoHolder.beginplay_mc.addEventListener(MouseEvent.CLICK, launchVideo);

			//trace("-------------------LAUNCH VIDEO QUIZ---------------------------");
		}

		private function TrytoMaximize(event: MouseEvent): void

		{

			if (isfullscreenset == false) {
				videoHolder.x = -152.6;
				videoHolder.y = -123.25;
				videoHolder.width = 798.5;
				videoHolder.height = 637.35;
				isfullscreenset = true;
				videoHolder.prompttext.text = "Press Esc to exit full screen mode.";
				videoHolder.maxgobutton.visible = false;
				stage.addEventListener(KeyboardEvent.KEY_DOWN, pressESCKey);
			} else if (isfullscreenset == true) {
				videoHolder.prompttext.text = "  ";
				videoHolder.x = 0;
				videoHolder.y = 0;
				videoHolder.width = 593;
				videoHolder.height = 466.30;
				videoHolder.maxgobutton.visible = true;
				stage.removeEventListener(KeyboardEvent.KEY_DOWN, pressESCKey);
				videoHolder.prompttext.text = "  ";
				isfullscreenset = false;
			}

			//Object(parent).setfullscreen(isfullscreenset);
		}
		private function TryMinimize(): void

		{
			if (isfullscreenset == true) {
				videoHolder.x = 0;
				videoHolder.y = 0;
				videoHolder.width = 593;
				videoHolder.height = 466.30;
				videoHolder.prompttext.text = "  ";
				videoHolder.maxgobutton.visible = true;
				stage.removeEventListener(KeyboardEvent.KEY_DOWN, pressESCKey);
				isfullscreenset = false;
			}

			//Object(parent).setfullscreen(isfullscreenset);
		}
		private function pressESCKey(evt: KeyboardEvent): void {
			trace("key select here");
			if (evt.keyCode == 27) {
				trace("key select");
				TryMinimize();
			}
		} //KeyCode = 13 is ENTER key		 

		private function loadProdComplete2(e: Event): void {
			var bit: Bitmap = e.target.content;
			if (bit != null) {
				bit.width = 170;
				bit.height = 170;
				bit.smoothing = true;
			}
			videoHolder.picholder_mc.addChild(e.target.content);
		}

		/*************************************************************************************
		 * FUNCTION: LAUNCH VIDEO
		 ************************************************************************************/
		private function launchVideo(event: MouseEvent): void {
			//videoHolder.beginplay_mc.visible = false;
			//videoHolder.takequiz_mc.visible = false;
			dwactivevid = 1;
			videoHolder.vid_background.gotoAndStop(2);
			videoHolder.holder.visible = true;
			videoHolder.picholder_mc.visible = false;
			videoHolder.beginplay_mc.visible = false;
			//if(fl_ToLoad)
			//{
			var vidfullpath = Object(parent).getDpath();
			//trace("vidfullpath        "+vidfullpath);
			fl_Loader = new Loader();
			fl_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, movieLoaded);
			//if ((contentItem.conceptID != 14) && (contentItem.conceptID != 46)){
			//var videoPath:String = "" +vidfullpath+ "_VE4DATA/"+MainConstants.VIDEOMOVIEPATH + contentItem.conceptID + ".swf";
			//} else {
			var videoPath: String = "" + MainConstants.VIDEOMOVIEPATH + contentItem.conceptID + ".swf";
			//}
			//trace("videoPath"+videoPath);
			//var videoPath:String = "" + MainConstants.VIDEOMOVIEPATH + "13" + ".swf";
			fl_Loader.load(new URLRequest(videoPath));
			videoHolder.holder.addChild(fl_Loader);
			/*
				}else	{
					fl_Loader.unload();
					removeChild(fl_Loader);
					fl_Loader = null;
				}
				// Toggle whether you want to load or unload the SWF
				fl_ToLoad = !fl_ToLoad;				*/
		}
		public function movieLoaded(myevent: Event): void {
			//var videoObj:Object = videoHolder.holder.getChildAt(1); //ACCESS CODE IN LESSON MC
			//var videoObj:Object = myevent.target.content; //ACCESS CODE IN LESSON MC
			videoObj = myevent.target.content; //ACCESS CODE IN LESSON MC

			myevent.target.content.beginplayMe();
			//var videoMC:MovieClip = MovieClip(myevent.target.content);
			videoMC = MovieClip(myevent.target.content);
			videoObj.beginplayMe();
			videoObj.addEventListener("goEnd", videoEnd, true);
			var str: String = videoObj.toString(); //return "mainControl"				

			//trace("myevent.target.content = " +str);			
			//videoObj.nav_controller.beginplayMe();			
		}
		/*************************************************************************************
		 * FUNCTION: LAUNCH VIDEO
		 ************************************************************************************/
		public function videoEnd(e: Event): void {
			//addChild(videoHolder);					
			videoHolder.beginplay_mc.visible = true;
			//videoHolder.takequiz_mc.visible = true;
			if (dw_quizgood == "1") {
				videoHolder.takequiz_mc.visible = true;
				videoHolder.takequiz_mc.addEventListener(MouseEvent.CLICK, launchQuiz);
			}
			//videoHolder.holder.SoundMixer.stopAll(); 
			videoHolder.holder.stop();
			SoundMixer.stopAll();
			dwactivevid = 0;
			videoHolder.vid_background.gotoAndStop(1);
			if (fl_Loader != null) {
				videoHolder.holder.removeChild(fl_Loader);
			}

			videoHolder.holder.visible = false;
			videoHolder.picholder_mc.visible = true;
			videoHolder.beginplay_mc.visible = true;
			SoundMixer.stopAll();
			//videoHolder.closebtn.addEventListener(MouseEvent.CLICK,closeVideo); 
			//videoHolder.beginplay_mc.addEventListener(MouseEvent.CLICK, launchVideo); 
			//videoHolder.takequiz_mc.addEventListener(MouseEvent.CLICK, launchQuiz); 				
			//trace("-------------------LAUNCH VIDEO QUIZ---------------------------");
		}
		/*************************************************************************************
		 * FUNCTION: LAUNCH QUIZ
		 ************************************************************************************/
		private function launchQuiz(event: MouseEvent): void {
			//trace("did this trip");
			fl_Loader = new Loader();
			SoundMixer.stopAll();
			fl_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, quizmovieLoaded);
			//var videoPath:String = "" + MainConstants.VIDEOMOVIEPATH + contentItem.conceptID + ".swf";
			var videoPath: String = "" + "quiz.swf";
			//var videoPath:String = "" + MainConstants.VIDEOMOVIEPATH + "13" + ".swf";
			fl_Loader.load(new URLRequest(videoPath));
			videoHolder.quizholder.addChild(fl_Loader);

		}
		public function getDQpath() {
			return vidpicpath;
		}
		public function quizmovieLoaded(myevent: Event): void {
			var quizObj: Object = myevent.target.content; //ACCESS CODE IN LESSON MC
			myevent.target.content.PassID(contentItem.conceptID, vidpicpath);
			var videoMC: MovieClip = MovieClip(myevent.target.content);
			quizObj.PassID(contentItem.conceptID, vidpicpath);
			var qstr: String = quizObj.toString();
			videoHolder.vid_background.gotoAndStop(2);
			videoHolder.quizholder.visible = true;
			videoHolder.beginplay_mc.visible = false;
			videoHolder.quizclosebtn.visible = true;
			videoHolder.picholder_mc.visible = false;
			videoHolder.quizclosebtn.addEventListener(MouseEvent.CLICK, quizclosequiz);
		}
		private function quizclosequiz(ev: MouseEvent): void {
			SoundMixer.stopAll();
			videoHolder.quizholder.removeChild(fl_Loader);
			videoHolder.quizholder.visible = false;
			videoHolder.quizclosebtn.visible = false;
			videoHolder.picholder_mc.visible = true;
			videoHolder.beginplay_mc.visible = true;
			videoHolder.vid_background.gotoAndStop(1);
			//removeChild(videoHolder);
			//SoundMixer.stopAll();  
		}

		public function getConceptId(): String {
			return "" + contentItem.conceptID;
		}

		/*******************************************************************
		 * FUNCTIONS:  SET UP ALL BUTTONS AND TEXTFIELDS
		 *******************************************************************/
		private function setup(): void {
			//this.myPJ.printText.autoSize = TextFieldAutoSize.LEFT;
			//this.close_button2.buttonMode = true; 
			//this.close_button2.mouseChildren = false; 
			//this.close_button2.useHandCursor = true; 
			this.cover_mc.visible = false;
			printpopup.visible = false;
			/*this.about_button.buttonMode = true;
			this.about_button.mouseChildren = false; 
			this.about_button.useHandCursor = true; 			
			if(contentItem.conceptResources==null){
				this.tabResources_mc.visible=false;
			}*/
			this.print_button.buttonMode = true;
			this.print_button.mouseChildren = false;
			this.print_button.useHandCursor = true;

			//VIDEOS AND QUIZ
			this.videoButton.addEventListener(MouseEvent.CLICK, launchVideoQuiz);
			this.videoButton.buttonMode = true;

			//GLOSSARY PANEL BUTTONS			
			this.glossary_mc.glossaryPrint_btn.addEventListener(MouseEvent.CLICK, printGlossary);
			this.glossary_mc.glossaryClear_btn.addEventListener(MouseEvent.CLICK, clearGlossary);
			this.glossary_mc.fullGlossary_btn.addEventListener(MouseEvent.CLICK, fullGlossary);
			this.glossary_mc.fullGlossBack.closeGlossary_btn.addEventListener(MouseEvent.CLICK, fullGlossary);
			this.glossary_mc.expand_btn.addEventListener(MouseEvent.CLICK, expandHideGlossary);


			this.close_button2.addEventListener(MouseEvent.MOUSE_OVER, onCloseOver);
			this.close_button2.addEventListener(MouseEvent.MOUSE_OUT, onCloseOut);
			this.close_button2.addEventListener(MouseEvent.CLICK, onCloseClick);

			//this.about_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoAboutFrm); 			
			this.about2_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoAboutFrm);
			this.print_button.addEventListener(MouseEvent.MOUSE_DOWN, printTabs);

			this.nav_back_button.addEventListener(MouseEvent.MOUSE_OVER, onNavBackOver);
			this.nav_back_button.addEventListener(MouseEvent.MOUSE_OUT, onNavBackOut);
			this.nav_back_button.addEventListener(MouseEvent.CLICK, gotoLastFrm);

			this.nav_home_button.addEventListener(MouseEvent.MOUSE_OVER, onNavHomeOver);
			this.nav_home_button.addEventListener(MouseEvent.MOUSE_OUT, onNavHomeOut);
			this.nav_home_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoHomeFrm);

			this.nav_concepts_button.addEventListener(MouseEvent.MOUSE_OVER, onNavConceptsOver);
			this.nav_concepts_button.addEventListener(MouseEvent.MOUSE_OUT, onNavConceptsOut);
			this.nav_concepts_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoConceptsFrm);

			this.nav_lessons_button.addEventListener(MouseEvent.MOUSE_OVER, onNavLessonsOver);
			this.nav_lessons_button.addEventListener(MouseEvent.MOUSE_OUT, onNavLessonsOut);
			this.nav_lessons_button.addEventListener(MouseEvent.MOUSE_DOWN, gotoSearchFrm);


			this.tabOverview_mc.tab_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOverTab);
			this.tabLessons_mc.tab_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOverTab);
			this.tabTips_mc.tab_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOverTab);
			this.tabResources_mc.tab_btn.addEventListener(MouseEvent.MOUSE_OVER, mouseOverTab);

			this.tabOverview_mc.tab_btn.addEventListener(MouseEvent.MOUSE_OUT, mouseOutTab);
			this.tabLessons_mc.tab_btn.addEventListener(MouseEvent.MOUSE_OUT, mouseOutTab);
			this.tabTips_mc.tab_btn.addEventListener(MouseEvent.MOUSE_OUT, mouseOutTab);
			this.tabResources_mc.tab_btn.addEventListener(MouseEvent.MOUSE_OUT, mouseOutTab);

			this.tabOverview_mc.tab_btn.addEventListener(MouseEvent.CLICK, clickOverviewTab);
			this.tabLessons_mc.tab_btn.addEventListener(MouseEvent.CLICK, clickLessonsTab);
			this.tabTips_mc.tab_btn.addEventListener(MouseEvent.CLICK, clickTipsTab);
			this.tabResources_mc.tab_btn.addEventListener(MouseEvent.CLICK, clickResourcesTab);
		}

		/*******************************************************************
		 * FUNCTIONS:  BUTTONS ROLL OVER & OUT
		 *******************************************************************/
		private function mouseOverTab(evt: MouseEvent): void {
			evt.target.parent.textTab.alpha = .75;
			//trace("evt.target. = "+evt.target..toString() );
		}
		private function mouseOutTab(evt: MouseEvent): void {
			evt.target.parent.textTab.alpha = 1;
		}
		private function onCloseOver(evt: MouseEvent): void {
			this.close_button.gotoAndStop(2);
		}
		private function onCloseOut(evt: MouseEvent): void {
			this.close_button.gotoAndStop(1);
		}
		private function onNavBackOver(evt: MouseEvent): void {
			this.back_icon_roll.gotoAndStop(2);
		}
		private function onNavBackOut(evt: MouseEvent): void {
			this.back_icon_roll.gotoAndStop(1);
		}
		private function onNavHomeOver(evt: MouseEvent): void {
			this.house_mc.gotoAndStop(2);
		}
		private function onNavHomeOut(evt: MouseEvent): void {
			this.house_mc.gotoAndStop(1);
		}
		private function onNavConceptsOver(evt: MouseEvent): void {
			this.nav_concepts_roll.gotoAndStop(2);
		}
		private function onNavConceptsOut(evt: MouseEvent): void {
			this.nav_concepts_roll.gotoAndStop(1);
		}
		private function onNavLessonsOver(evt: MouseEvent): void {
			this.nav_lessons_roll.gotoAndStop(2);
		}
		private function onNavLessonsOut(evt: MouseEvent): void {
			this.nav_lessons_roll.gotoAndStop(1);
		}

	} // Main class

} //end package