var variation=15;
var timer;

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function Img(imgname,width,height) {
 this.named=imgname;
 this.stepX=variation*Math.random();
 this.stepY=variation*Math.random();
 this.w=width;
 this.h=height;
 this.posLeft=0;
 this.posTop=0;
 this.timer1=null;
}

function moveImg(obj) {
	if (document.getElementById){
	eval("img="+obj);

    if (window.innerWidth || window.opera){
		 PageOffsetX=window.pageXOffset; // 0
		 pageMarginRight=window.innerWidth-40;
		 PageOffsetY=window.pageYOffset; //0
		 pageMarginBottom=window.innerHeight-40;
    }
   else if (document.body){
		 PageOffsetX=iecompattest().scrollLeft; //0
		 pageMarginRight=iecompattest().offsetWidth-40;
		 PageOffsetY=iecompattest().scrollTop; //0
		 pageMarginBottom=iecompattest().offsetHeight-40;
		 
    } 

   img.posLeft=img.posLeft+img.stepX;
   img.posTop=img.posTop+img.stepY;
   img.stepX+=5*(Math.random()-0.5); 
   img.stepY+=5*(Math.random()-0.5); 

   
   if(img.stepX > (variation))  
	   img.stepX=(variation)*2 - img.stepX;
   if(img.stepX < (-variation)) 
	   img.stepX=(-variation)*2 - img.stepX;
   if(img.stepY > (variation))  
	   img.stepY=(variation)*2 - img.stepY;
   if(img.stepY < (-variation)) 
	   img.stepY=(-variation)*2 - img.stepY;

 // if image has reached to the left most side
   if(img.posLeft<=PageOffsetX){
		img.posLeft=PageOffsetX; // set the left position to 0
		img.stepX=variation*Math.random(); // set the step to move towards RHS 
     }
 //  if image has reached to the right most side
   if(img.posLeft>=pageMarginRight-img.w-40){
		img.posLeft=pageMarginRight-img.w-40; // set the left position to max page width
		img.stepX=-variation*Math.random(); // set the step to move towards LHS
     }
// if image has reached the top most side
   if(img.posTop<=PageOffsetY) {  
		  img.posTop=PageOffsetY; // set the top position i.e. height to 0
		  img.stepY=variation*Math.random(); // set the step to move downwards
     }
// if images has reached teh bottom of the page
   if(img.posTop>=PageOffsetY+pageMarginBottom-img.h)   {
		  img.posTop=PageOffsetY+pageMarginBottom-img.h; // set the height to max page height
		  img.stepY=-variation*Math.random(); // set the step to move upwards
     }

	document.getElementById(img.named).style.left=img.posLeft+"px";
	document.getElementById(img.named).style.top=img.posTop+"px";

  img.timer=setTimeout("moveImg('"+obj+"')",100);
  }
}

  function stopFloatingImg(obj) {
	if (document.getElementById){
		eval("img="+obj);
		clearTimeout(img.timer);
	}
}
