<HTML>
<HEAD>
<TITLE>DirectAnimation SDK, JScript sample</TITLE>
<SCRIPT LANGUAGE="JScript">
<!--
if (window.top.frames.length!=0 && window.top.frames[0].ShowNoButtons!=null)
    window.top.frames[0].ShowNoButtons();
//-->
</SCRIPT>
</HEAD>
<BODY BGCOLOR=WHITE LINK=#0033CC TOPMARGIN=15 LEFTMARGIN=20>
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2> 
<CENTER>
<H1>Jump URL in Scripting</H1>
</CENTER>

<OBJECT ID="DAControl"
  STYLE="position:absolute; left:20; top:75; width:350; height:250;"
  CLASSID="CLSID:B6FFC24C-7E13-11D0-9B47-00C04FC2F51D">
</OBJECT>

<DIV STYLE="position:absolute; left:380; top:75;width:50%;" >
This template shows how DirectAnimation can be used along with native JScript.  
When you move the mouse over the picture of Seattle, a sound will start playing and a 
tip box will appear with instructions.  The pickable image and sound are 
imported by using DirectAnimation.  Linking to another webpage is done by
using DirectAnimation's Callback function and the href property of the Location object.
</DIV>

<SCRIPT LANGUAGE="JScript">
<!--
  // The DirectAnimation library
  m = DAControl.MeterLibrary;

  // Create bases for importing images and sounds.
  mediaBase = "../../../../Media/";
  imgBase = mediaBase + "image/";
  sndBase = mediaBase + "sound/";

  // Import seattle.jpg.
  seattleImg = m.ImportImage(imgBase + "seattle.jpg");

  // Import the sound that will be played when the mouse moves over 
  // seattleImg.
  pickSnd = m.ImportSound(sndBase + "etherial.mp2").Sound.Loop();

  // Make seattleImg pickable.
  pickPImg = seattleImg.PickableOccluded();

  // Create an event that will trigger when the mouse moves over detectImg.
  pickEv = pickPImg.PickEvent;

  // Get the image part of pickPImg.
  pickImg = pickPImg.Image;

  // Create the tip box (tipImg), which consists of a black 
  // backgroud (tipBackIm), and white text (tipTxtIm).
  font = m.Font("Arial",12,m.White).Bold();
  tipTxtImg = m.StringImage("Click the red dot to go to Seattle Sidewalk", font);

  txtBB = tipTxtImg.BoundingBox;

  tipBackImg = m.SolidColorImage(m.Black).Crop(txtBB.Min,txtBB.Max);
		
  tipImg = m.Overlay(tipTxtImg,tipBackImg);

  // Create a detectable image (jumpImg)and crop it to 6 by 6 mm.  
  // This image will be made pickable and used to jump to Seattle Sidewalk.
  jumpImg = m.SolidColorImage(m.Red).Crop(m.Point2(-0.003,-0.003),
    m.Point2(0.003,0.003));

  jumpImg = jumpImg.Transform(m.Translate2Anim(m.DANumber(0),
    m.Mul(m.DANumber(-50),m.Pixel)));

  // Make detectImg pickable.
  jumpPImg = jumpImg.PickableOccluded();

  // Create an event that will trigger when the mouse moves over jumpImg.
  jumpEv = jumpPImg.PickEvent;

  // Create an event that will trigger when both the mouse moves over 
  // jumpImg, and the left mouse button is clicked.
  jumpClickEv = m.AndEvent(m.LeftButtonDown, jumpEv);

  // Get the image part of jumpPImg.
  jumpPointImg = jumpPImg.Image;

  // Combine the pickable images with the tip box and pair them with sound.
  compTup1 = m.DATuple(new Array(pickPImg.Image,m.Silence));
  finalImg = m.Overlay(jumpPointImg,m.Overlay(tipImg,pickImg));
  compTup2 = m.DATuple(new Array(finalImg,pickSnd));

  // Create a behavior (pickTup) that start out as a detectable empty
  // image with no sound.  When the mouse moves over it, the sound
  // changes to pickSnd, and the tip box is displayed.  When the mouse is
  // no longer over it, it returns to the original behavior.
  pickedTup = m.UninitializedTuple(m.DATuple(new Array(m.EmptyImage,m.Silence)));
  pickedTup.Init(m.Until(compTup1,pickEv,m.Until(compTup2,
    m.NotEvent(pickEv),pickedTup)));

  // Create a behavior that starts out as pickedTup, and that jumps to the
  // Seattle Sidewalk site when the user clicks on pickPImg using the left
  // mouse button.
  finalTup = m.Until(pickedTup,
  jumpClickEv.ScriptCallback("SideWalkLink()","JScript"),pickedTup);

  // Display the final image.
  DAControl.Image = m.Overlay(finalTup.Nth(0),
    m.Overlay(seattleImg,m.SolidColorImage(m.Black)));

  // Start the sound.
  DAControl.Sound = m.Mix(finalTup.Nth(1),m.Silence);  

  // Set the background in case of a non-windowless browser (like IE3).
  DAControl.BackgroundImage = m.SolidColorImage(m.Blue)

  // Start the animation.
  DAControl.Start();
  function SideWalkLink()  {
    window.top.location.href = "http://seattle.sidewalk.com";
  }
-->
</SCRIPT>
</FONT>
</BODY>
</HTML>

