/******************************************
 * @author Maria A. Zamora
 * @company Digitec Interactive Inc.
 * @version 0.1
 * @date 12/14/2010
 * 
 * Glossary class for lessonsFrame5 movie of the CEE application
 * CS5 version of com.digitec.cee.Glossary
 *  
*******************************************/
package com.digitec.cee
{
	import flash.display.MovieClip;	
	import flash.events.*;	
	
	import fl.controls.ScrollPolicy;
	import fl.controls.TextArea;	
	import flash.text.StyleSheet;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.text.TextField;
	
	 import flash.display.Sprite;  
    import flash.text.TextFieldAutoSize;  
	
	public class Glossary
	{								
		private var XML_PATH:String ="data/glossary.xml";  //MainConstants.XML_GLOSSARY_FULLPATH; // 
		private var CSS_PATH:String ="data/glossary.css";// MainConstants.CSS_GLOSSARY_FULLPATH;		// 
		public var fullpath:String;
		public var glosspath:String;
		private  var cssGlossary:StyleSheet  = new StyleSheet();																
		private var glossXmlList:XMLList;				
			 
		 public function Glossary()
		 {					
			//fullpath = passpath+ "_VE4DATA/"+XML_PATH;
			fullpath = XML_PATH;
			trace("fullpath       "+fullpath);
			loadGlossary();			
			loadCSS();
		}						
			
		/*******************************************************************
		 * FUNCTION: GET FULL GLOSSARY ITEMS ARRAY
		 *******************************************************************/
		 public function getXMLGlossary():XMLList//Array
		{						
			return glossXmlList;
		}
		
		/*******************************************************************
		 * FUNCTION: GET FULL GLOSSARY ITEMS ARRAY
		 *******************************************************************/
		 public function getStyleSheet():StyleSheet
		{						
			return cssGlossary;
		}
		
		/*******************************************************************
		 * FUNCTION: GET FULL GLOSSARY ITEMS ARRAY
		 *******************************************************************/
		 public function getGlossaryItem():String //GlossaryItem
		{						
			return "item";
		}
		 
		
		/*******************************************************************
		 * FUNCTION: SETUP FRAME TEXT_FIELDS  FROM XML
		 *******************************************************************/
		private function loadGlossary():void
		{						
			//LOADGLOSSARY XML
			trace("glosspath[Glassary.as:75]: "+ glosspath);
			trace("glosspath[Glassary.as:76]: "+ fullpath);
			var glossUrl:URLRequest = new URLRequest(fullpath); //new URLRequest("data/glossary.xml");//
			var glossLoader:URLLoader = new URLLoader();
			glossLoader.load(glossUrl);
			glossLoader.addEventListener(Event.COMPLETE,glossLoaded);
			function glossLoaded(event:Event):void {
				var _xml:XML = new XML(glossLoader.data);
   				glossXmlList = new XMLList(_xml.term);								
			}										
		}																
		public function setpath(glosspathtemp){
			
			glosspath = glosspathtemp;
			trace("glosspath                                  jjjjjjjjjjjj2       "+glosspath);
			
		}
		/*******************************************************************
		 * FUNCTION: SETUP FRAME TEXT_FIELDS  FROM XML
		 *******************************************************************/
		private function loadCSS():void
		{								
			//LOAD GLOSSARY CSS AND APPLY TO TERMS TEXT
			//var csspath = Object(parent).getDpath();
			//var gUrl:URLRequest =  new URLRequest(csspath+ "_VE4DATA/"+CSS_PATH);   // new URLRequest("data/glossary.css");//
			var gUrl:URLRequest =  new URLRequest(CSS_PATH);   // new URLRequest("data/glossary.css");//
			var gLoader:URLLoader = new URLLoader();
			gLoader.load(gUrl);
			gLoader.addEventListener(Event.COMPLETE,gLoaded);
			function gLoaded(event:Event):void {				   				
				//cssGlossary.parseCSS(URLLoader(event.target).data);							
				 cssGlossary.parseCSS(gLoader.data);
			}							
		}																
		
		/*************************************************************************************
		 * FUNCTIONS: GET AND DEFINE GLOSSARY TERMS
		  ************************************************************************************/				
		public function defineGlossaryTerm( str:String ):String	
		{							
			var item_str:String;			
			if(str!=null)
			{				
           		 var item:XML;
				for each(item in glossXmlList)
				{
					if( item.@name == str )
					{						
						var definition:String =  item.def;						
						item_str= "<p class='term'>"+ item.@name+"</p>" + "<p class='def'>"+definition+"</p>" ;												
					}
				}	
			}							
			return item_str;
		}						
		
		/*************************************************************************************
		 * FUNCTIONS:GET FULL GLOSSARY TERMS
		  ************************************************************************************/				
		public function getFullGlossary(  ):XMLList	
		{										
			 var item:XML;
			 var full_str:String = "";			
			for each(item in glossXmlList)
			{										
					var definition:String =  item.def;										
					full_str += "<p class='term'>"+ item.@name+"</p>" + "<p class='def'>"+definition+"</p>" ;											
			}				
			//return full_str; //<--Original - Test HMD 2/1/11 Now send full list back
			return glossXmlList;
		}						
		 
		  /*************************************************************************************
		 * FUNCTION: PRINT GLOSSARY TERMS
		  ************************************************************************************/
		  private function printGlossary(ev:MouseEvent):void
		  {
			/////////////////////////////// // this.glossary_mc.terms_txt.htmlText= "";
		  }			
		  
		 
	} // Main class
 
} //end package



/*
//////////////////////////BACKUP//////////////////////////////////
public function defineGlossaryTerm( str:String ):String{							
	var item_str:String;			
	if(str!=null)	{				
		 var item:XML;
		for each(item in glossXmlList)	{
			if( item.@name == str ){ 
				//this.glossary_mc.terms_txt.htmlText= item; //WORK
				//this.glossary_mc.terms_txt.htmlText= item.toXMLString(); //ALSO WORK
				var definition:String =  item.def;
				//definition = definition.replace("<def>", ""); //eliminate any <def>
				//definition = definition.replace("</def>", ""); //eliminate any </def>						
				//this.glossary_mc.terms_txt.text=  item.@name + ": "+ definition ; //"Glossary: " + str;						
				item_str= "<p class='term'>"+ item.@name+"</p>" + "<p class='def'>"+definition+"</p>" ;										
			}
		}	
	}	return item_str;
}								
*/







