/***********************************************
* Floating image script- 
* Original by Virtual_Max (http://www.geocities.com/siliconvalley/lakes/8620)
* Improved by Dynamic Drive (Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code)
* Modified by the HKMC to suit various requirements of its public website (http://www.hkmc.com.hk)
***********************************************/


var vmin=2;
var vmax=5;
var vr=2;
var timer1;

// check ie properties (document.body and/or document.documentElement)
function iecompattest() {
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

// retrieve initial properties
function Chip(chipname,width,height){
 this.named=chipname;
 this.vx=vmin+vmax*Math.random();
 this.vy=vmin+vmax*Math.random();
 this.w=width+20;
 this.h=height;
 this.xx=490;				    // Window Left offset (make sure image does not go over/ under the left menu bar)
 this.yy=77;
 this.timer1=null;
}


function movechip(chipname){

if (document.getElementById){


eval("chip="+chipname);	// Move floating image one at a time

   
   if (window.innerWidth || window.opera){
     pageX=window.pageXOffset + 150;		// Window Left offset (make sure image does not go over/ under the left menu bar)
     pageW=window.innerWidth-40;
     pageY=window.pageYOffset;
     pageH=window.innerHeight-20;

    }
   else if (document.body){
     pageX=iecompattest().scrollLeft + 150;	// Window Left offset (make sure image does not go over/ under the left menu bar)
     pageW=iecompattest().offsetWidth-40;
     pageY=iecompattest().scrollTop;
     pageH=iecompattest().offsetHeight-20;
    } 

   chip.xx=chip.xx+chip.vx;
   chip.yy=chip.yy+chip.vy;
   
   chip.vx+=vr*(Math.random()-0.5);
   chip.vy+=vr*(Math.random()-0.5);
   if(chip.vx>(vmax+vmin))  chip.vx=(vmax+vmin)*2-chip.vx;
   if(chip.vx<(-vmax-vmin)) chip.vx=(-vmax-vmin)*2-chip.vx;
   if(chip.vy>(vmax+vmin))  chip.vy=(vmax+vmin)*2-chip.vy;
   if(chip.vy<(-vmax-vmin)) chip.vy=(-vmax-vmin)*2-chip.vy;

   if(chip.xx<=pageX){
			chip.xx=pageX;
      chip.vx=vmin+vmax*Math.random();
     }
   if(chip.xx>=pageX+pageW-chip.w){
			chip.xx=pageX+pageW-chip.w;
      chip.vx=-vmin-vmax*Math.random();
     }
   if(chip.yy<=pageY)
     {chip.yy=pageY;
      chip.vy=vmin+vmax*Math.random();
     }
   if(chip.yy>=pageY+pageH-chip.h)
     {chip.yy=pageY+pageH-chip.h;
      chip.vy=-vmin-vmax*Math.random();
     }

   // image starting point
   document.getElementById(chip.named).style.left=chip.xx+"px";
   document.getElementById(chip.named).style.top=chip.yy+"px";

   // move image
   //if (is_moving != "false") {
   	//chip.timer1=setTimeout("movechip('"+chip.named+"')",100);
   //}
  }

}


