var speed = 35;

var dx, xp, yp;
var am, stx, sty;
var i, doc_width = 800, doc_height = 600; 
var strInitPoint = 650;

dx = 0; // set coordinate variables 
xp = Math.random()*(doc_width-50); // set position variables 
yp = Math.random()*doc_height; 
am = Math.random()*20; // set amplitude variables 
stx = 0.02 + Math.random()/10; // set step variables 
sty = 0.7 + Math.random(); // set step variables 

function moveObject() {
   yp += sty; 
   if (yp > doc_height-50) { 
     xp = Math.random()*(doc_width-am-30); 
     yp = 0; 
     stx = 0.02 + Math.random()/10; 
     sty = 0.7 + Math.random(); 
   } 
   dx += stx; 
   movingobj.style.pixelTop = yp; 
   movingobj.style.pixelLeft = strInitPoint + am*Math.sin(dx); 
   setTimeout("moveObject()", speed); 
} 

function moveButterfly(){
   var bleft = butterfly.style.pixelLeft;
   var btop = butterfly.style.pixelTop;
   if (bleft<700)
     butterfly.style.pixelLeft = bleft + 2;
   else if (bleft==700)
     butterfly.style.pixelLeft = 20;
   else
     butterfly.style.pixelLeft = bleft - 2;
   setTimeout("moveButterfly()",100);
}

