document.write("<div id='hyclip0' style='border-width:1px; border-style:none; width:11px; height:18px; position:absolute; left:50px; top:50px; z-index:1; visibility:hidden;'>")
document.write("<img src='http://www.angelfire.com/trek/xiaoxue/starz4.gif'>")
document.write("</div>")
document.write("<div id='hyclip1' style='border-width:1px; border-style:none; width:15px; height:22px; position:absolute; left:50px; top:50px; z-index:1;'>")
document.write("<img src='http://www.angelfire.com/trek/xiaoxue/starz4.gif'>")
document.write("</div>")
document.write("<div id='hyclip2' style='border-width:1px; border-style:none; width:15px; height:22px; position:absolute; left:50px; top:50px; z-index:1;'>")
document.write("<img src='http://www.angelfire.com/trek/xiaoxue/star3.gif'>")
document.write("</div>")
document.write("<div id='hyclip3' style='border-width:1px; border-style:none; width:15px; height:22px; position:absolute; left:50px; top:50px; z-index:1;'>")
document.write("<img src='http://www.angelfire.com/trek/xiaoxue/starz2.gif'>")
document.write("</div>")
document.write("<div id='hyclip4' style='border-width:1px; border-style:none; width:15px; height:22px; position:absolute; left:50px; top:50px; z-index:1;'>")
document.write("<img src='http://www.angelfire.com/trek/xiaoxue/starz1.gif'>")
document.write("</div>")


var nhyclips = 5;
if (document.all&&window.print)
document.body.style.cssText="overflow-x:hidden;overflow-y:scroll"
var Xpos = 0;
var Ypos = 0;
var DELTAT = .006;
var SEGLEN = 10;
var SPRINGK = 10;
var MASS = 1;
var GRAVITY = 50;
var RESISTANCE = 10;
var STOPVEL = 0.1;
var STOPACC = 0.1;
var hyclipSIZE = 11;
var BOUNCE = 0.75;
var isNetscape = navigator.appName=="Netscape";
var followmouse = true;

var hyclips = new Array();

init();

function init()
{
   var i = 0;
   for (i = 0; i < nhyclips; i++) {
       hyclips[i] = new hyclip(i);
   }

   if (!isNetscape) {
   }
   for (i = 0; i < nhyclips; i++) {
       hyclips[i].obj.left = hyclips[i].X;
       hyclips[i].obj.top = hyclips[i].Y;
   }
   
   if (isNetscape) {
       startanimate();
   } else {
       setTimeout("startanimate()", 2000);
   }
}


function hyclip(i) 
{
   this.X = Xpos;
   this.Y = Ypos;
   this.dx = 0;
   this.dy = 0;

   if (isNetscape) {   
        this.obj = eval("document.hyclip" + i);
   } else {
       this.obj = eval("hyclip" + i + ".style");
   }
}

 

function startanimate() {       
   setInterval("animate()", 20);
}
 
function setInitPositions(hyclips)
{
   var startloc = document.all.tags("LI");
   var i = 0;

   for (i = 0; i < startloc.length && i < (nhyunclips - 1); i++) {
       hyclips[i+1].X = startloc[i].offsetLeft
           startloc[i].offsetParent.offsetLeft - hyclipSIZE;
       hyclips[i+1].Y = startloc[i].offsetTop +
           startloc[i].offsetParent.offsetTop + 2*hyclipSIZE;
   }

   // put 0th hyunclip above 1st (it is hidden)
   hyclips[0].X = hyclips[1].X;
   hyclips[0].Y = hyclips[1].Y - SEGLEN;
}

// just save mouse position for animate() to use
function MoveHandler(e)
{
   Xpos = e.pageX;
   Ypos = e.pageY;       
   return true;
}

 
// just save mouse position for animate() to use
function MoveHandlerIE() {
   Xpos = window.event.x + document.body.scrollLeft;
   Ypos = window.event.y + document.body.scrollTop;      
}

if (isNetscape) {
   document.captureEvents(Event.MOUSEMOVE);
   document.onMouseMove = MoveHandler;
} else {
   document.onmousemove = MoveHandlerIE;
}

 

function vec(X, Y)
{
   this.X = X;
   this.Y = Y;
}


// adds force in X and Y to spring for hyclip[i] on hyclip[j]
function springForce(i, j, spring)
{
   var dx = (hyclips[i].X - hyclips[j].X);
   var dy = (hyclips[i].Y - hyclips[j].Y);
   var len = Math.sqrt(dx*dx + dy*dy);

   if (len > SEGLEN) {
       var springF = SPRINGK * (len - SEGLEN);
       spring.X += (dx / len) * springF;
       spring.Y += (dy / len) * springF;
   }
}

 
function animate() {    
   // hyclips[0] follows the mouse,
   // though no hyclip is drawn there
   var start = 0;

   if (followmouse) {
       hyclips[0].X = Xpos;
       hyclips[0].Y = Ypos;       
       start = 1;
   }
   
   for (i = start ; i < nhyclips; i++ ) {
       var spring = new vec(0, 0);
       if (i > 0) {
           springForce(i-1, i, spring);
       }
       if (i < (nhyclips - 1)) {
           springForce(i+1, i, spring);
       }

       // air resisitance/friction
       var resist = new vec(-hyclips[i].dx * RESISTANCE,
           -hyclips[i].dy * RESISTANCE);

       // compute new accel, including gravity
       var accel = new vec((spring.X + resist.X)/ MASS,
           (spring.Y + resist.Y)/ MASS + GRAVITY);

       // compute new velocity
       hyclips[i].dx += (DELTAT * accel.X);
       hyclips[i].dy += (DELTAT * accel.Y);

       // stop dead so it doesn't jitter when nearly still
       if (Math.abs(hyclips[i].dx) < STOPVEL &&
           Math.abs(hyclips[i].dy) < STOPVEL &&
           Math.abs(accel.X) < STOPACC &&
           Math.abs(accel.Y) < STOPACC) {
           hyclips[i].dx = 0;
           hyclips[i].dy = 0;
       }

       // move to new position
       hyclips[i].X += hyclips[i].dx;
       hyclips[i].Y += hyclips[i].dy;

       // get size of window
       var height, width;

       if (isNetscape) {
           height = window.innerHeight + document.scrollTop;
           width = window.innerWidth + document.scrollLeft;
       } else {        
           height = document.body.clientHeight + document.body.scrollTop;
           width = document.body.clientWidth + document.body.scrollLeft;
       }

       // bounce of 3 walls (leave ceiling open)
       if (hyclips[i].Y >=  height - hyclipSIZE - 1) {
           if (hyclips[i].dy > 0) {
               hyclips[i].dy = BOUNCE * -hyclips[i].dy;
           }
           hyclips[i].Y = height - hyclipSIZE - 1;
       }
       if (hyclips[i].X >= width - hyclipSIZE) {
           if (hyclips[i].dx > 0) {
               hyclips[i].dx = BOUNCE * -hyclips[i].dx;
           }
           hyclips[i].X = width - hyclipSIZE - 1;
       }
       if (hyclips[i].X < 0) {
           if (hyclips[i].dx < 0) {
               hyclips[i].dx = BOUNCE * -hyclips[i].dx;
           }
           hyclips[i].X = 0;
       }
        
       // move img to new position
       hyclips[i].obj.left = hyclips[i].X;                   
       hyclips[i].obj.top =  hyclips[i].Y;           
   }
}

