
document.write "<OBJECT classid=""clsid:D45FD31B-5C6E-11D1-9EC1-00C04FD7081F"" id=""Agent"" CODEBASE=""http://activex.microsoft.com/activex/controls/agent2/MSagent.exe#VERSION=2,0,0,0""></OBJECT>"
document.write "<OBJECT classid=""clsid:B8F2846E-CE36-11D0-AC83-00C04FD97575"" id=""TruVoice"" CODEBASE=""http://activex.microsoft.com/activex/controls/agent2/tv_enua.exe#VERSION=6,0,0,0""></OBJECT>"


Dim Peedy
Dim LoadRequestUNC
Dim LoadRequestURL
Dim GetShowAnimation
Dim currText
Dim selText

Sub Window_OnLoad
  ' Load the character
  LoadCharacter
End Sub

Sub LoadCharacter
  On Error Resume Next
  ' Attempt to load the character from the local Microsoft Agent Chars directory (windows\msagent\chars)
  Set LoadRequestUNC = Agent.Characters.Load ("Peedy", "ladybug.acs")  
  ' If it fails...
  If LoadRequestUNC.Status <> 0 Then
  '  GIVE USER THE OPTION TO DOWNLOAD AND INSTALL
	Promptx = "The text assistant, Ms Lady Bug, is not installed on your computer." & Chr(13)
	Promptx = Promptx & "Click OK if you would like to see instructions on downloading and installing the assistant." & Chr(13)  
	Promptx = Promptx & "If you click CANCEL you may temporarily install the assistant by answering YES to the next security question."
	req = MsgBox (Promptx, vbOkCancel+vbDefaultButton1+vbQuestion, "Do you want to install the text reader character?")
	if req = vbOK then window.location = "http://kids-learn.org/ladybugs/instructions.htm"
  ' Attempt to load the character from the Project Website
    Set LoadRequestURL = Agent.Characters.Load ("Peedy", "http://kids-learn.org/ladybugs/ladybug.acf")
  Else 	' It loaded locally, so assign Peedy to loaded character file
    ' Assign Peedy to the loaded character
    Set Peedy = Agent.Characters("Peedy")
    DoIntro
  End If
End Sub

Sub DoIntro
  InitCommands
  ' Set the character's language ID
  Peedy.LanguageID = &H0409
  ' Make the character appear
  On Error Resume Next
  Peedy.MoveTo window.screenLeft+10, window.screenTop+70
  Peedy.Show
  Peedy.Speak "Hello, my name is Ms. Lady Bug.  I am your friendly text reader."
  Peedy.Speak "Highlight any words you would like me to read, and click on me."
  Peedy.Play "Explain"
  Peedy.Speak "If you want me to stop talking, click on me again."
  Peedy.Play "Explain"
  Peedy.Speak "I will go away if you right mouse click on me and select hide."
End Sub


Sub InitCommands
  ' Give user access to the Advanced Character Options dialog
  Peedy.Commands.RemoveAll
  'Peedy.Commands.Add "ACO", "Advanced Character Options"
End Sub


Sub Agent_RequestComplete(ByVal Request)
  ' The Request to load the ACF character fails 
  If Request = LoadRequestURL Then
    ' If it failed
    If Request.Status = 1 Then
      Msgbox "Ms Lady Bug could not be loaded. You did not allow the character to be installed."
      Exit Sub

    ' If it succeeded
    ElseIf Request.Status = 0 Then
      ' Assign Peedy to the loaded character
      Set Peedy = Agent.Characters("Peedy")
      ' Get the preliminary animations necessary to show Peedy
      Set GetShowAnimation = Peedy.Get ("state", "showing, speaking, hiding")
      Peedy.Get "animation", "Eat,Blink, Greet, Pleased, Explain, Think, GestureRight,Idle1_1,Idle2_2, Announce, Uncertain", False
    End If

  ' The request to get the animation 
  ElseIf Request = GetShowAnimation Then
    ' If it failed 
    If Request.Status = 1 Then
		Msgbox "Request to load the Show animation failed. The server may be busy."
		Exit Sub
	' If it succeeded
    ElseIf Request.Status = 0 Then
      DoIntro
    End If
  End If
End Sub

Sub Agent_Click (ByVal CharacterID, ByVal Button, ByVal Shift, ByVal X, ByVal Y)
  ' Start the monologue
	selText = document.selection.createRange().text
	if selText <> currText then
		currText = selText
		Peedy.Speak currText
		Peedy.Play "Eat"
	else
		Peedy.Stop
	end if
End Sub

Sub Agent_DragComplete (ByVal CharacterID, ByVal Button, ByVal Shift, ByVal X, ByVal Y)
  Peedy.Stop
  'Peedy.Play "Blink"
  Peedy.Speak "Well, \emp\this area of the garden might have yummy aphids!|I hope there is no praying mantis over here!|I like it much better over here. I hope there are no pesticides that will poison me!|Now why did you move me? I liked it over there!|Hey, be gentle!"
	Peedy.Play "Eat"
End Sub


Sub Agent_Command (ByVal UserInput)
  If UserInput.Name = "ACO" Then
    Agent.PropertySheet.Visible = True
  End If
End Sub
