public void StartSaveCall( ) // this call does the work, passed in when thread is created, executes on thread.start
    {
        ThreadRunning = true;
		ThreadComplete = false;
		try
        {

			// create a playback file
			InteractPlaybackList list = new InteractPlaybackList();
			list.Save(record);
			// now save this file
			list.SaveXML(filePath);
        }
		catch
		{
			error = "error";
		}
        ThreadRunning = false;
		ThreadComplete = true;
    }
	void OnGUI()
	{
		if ( ShowGUI == false )
			return;

		GUILayout.BeginArea(new Rect(0,40,600,300));

		if ( state != State.Playing )
		{
			GUILayout.Box ("INTERACT PLAYBACK");
			if ( GUILayout.Button ("Save") )
			{
				// create a logrecord
				LogRecord record = new LogRecord();
				record.Add(LogMgr.GetInstance().GetCurrent());
				record.SetDateTime();
				// create a playback file
				InteractPlaybackList list = new InteractPlaybackList();
				list.Save(record);
				// now save this file
				list.SaveXML(null);
			}
			if ( GUILayout.Button ("Load") )
			{
				debug = true;
				if ( state != State.Playing )
				{
					// now create a playback list
					InteractPlaybackList list = new InteractPlaybackList();
					list.LoadXML(null);
					// save start 
					RestartWithList(list);
					//StartList(list);
				}
				else
				{
					UnityEngine.Debug.LogError("InteractPlaybackMgr.Update() : can't start new playback while one is in progress!!");
				}				
			}
		}
		else if ( state == State.Playing )
		{
			GUILayout.Box ("INTERACT PLAYBACK : " + InteractPlaybackFileMgr.GetInstance().Filename);
			if ( GUILayout.Button ("Stop") )
			{
				state = State.Complete;
				Time.timeScale = 1.0f;
			}
			GUILayout.BeginHorizontal();
			if ( GUILayout.Button ("1x"))
				Time.timeScale = 1.0f;
			if ( GUILayout.Button ("2x"))
				Time.timeScale = 2.0f;
			if ( GUILayout.Button ("5x"))
				Time.timeScale = 5.0f;
			GUILayout.EndHorizontal();
		}

		if ( state != State.Playing || currentIdx == -1 || debug == false )
		{
			if ( restartTime != 0.0f && RestartOnDoneOrError == true)
				GUILayout.Button("Playback Complete, Restarting in " + ((int)(restartTime-elapsedTime)).ToString () + " seconds...");

			GUILayout.EndArea();
			return;
		}

		GUILayout.Space(10);
		if ( (currentIdx-1) >= 0 )
			GUILayout.Label(" PB.curr=" + List.Items[currentIdx-1].Debug ());//InteractName + "," + List.Items[currentIdx].Character);
		GUILayout.Label(" PB.wait=" + List.Items[currentIdx].Debug ());//InteractName + "," + List.Items[currentIdx].Character);
		if ( (currentIdx+1) < List.Items.Count )
			GUILayout.Label(" PB.next=" + List.Items[currentIdx+1].Debug ()); //InteractName + "," + List.Items[currentIdx+1].Character);
		GUILayout.EndArea();
	}		
	public void RestartWithList( InteractPlaybackList list )
	{
		// reset executed flag in list
		foreach( PlaybackItem item in list.Items )
			item.Executed = false;

		InteractPlaybackFileMgr.GetInstance().StartList = list;
		InteractPlaybackFileMgr.GetInstance().Filename = list.Filename;
		InteractPlaybackFileMgr.GetInstance().timeScale = Time.timeScale;
		Application.LoadLevel ("Trauma_05");
	}
	public void StartList( InteractPlaybackList list )
	{
		if ( list != null && list.Items != null && list.Items.Count > 0 )
		{
			// set new playback file
			List = list;
			// start playing, give some extra time
			elapsedTime = StartTime;
			currentIdx = 0;
			state = State.Playing;
			debug = true;
			restartTime = 0.0f;

			// calc index to start based on StartTime
			if ( StartTime != 0.0f )
			{
				foreach( PlaybackItem item in list.Items )
				{
					if ( item.RealTime >= StartTime )
						break;
					else
						currentIdx++;
				}
				UnityEngine.Debug.Log ("InteractPlaybackMgr.StartList() Advancing to index=" + currentIdx + " : item=" + list.Items[currentIdx].InteractName);
			}
		}
	}
	// create a playback list from a log file
	public void Load(LogRecord log)
	{
		List = new InteractPlaybackList();
		List.Save(log);
		currentIdx = 0;
		elapsedTime = StartTime;
		// init state
		state = State.Init;
	}
 public void Load()
 {
     List = new InteractPlaybackList();
     List.LoadXML("XML/playback");
     currentIdx = 0;
     elapsedTime = StartTime;
     // init state
     state = State.Init;
 }