var t;
var x_pos=-250;
var y_pos=150;
var directions=[[1,0,-100,0],[0,1,0,-100],[-1,0,100,0],[0,-1,0,100],[1,1,-100,-100],[1,-1,-100,100],[-1,-1,100,100],[-1,1,100,-100]];
var direction_index=5;
var nu_img,image_index=0;
var img_urls=[
  "images/cat_thumb.jpg",
  "images/avril_thumb.jpg",
  "images/gregor_thumb.jpg",
  "images/james_thumb.jpg",
"images/child2_thumb.jpg",
"images/child6_thumb.jpg",
"images/dragon%20rider_thumb.jpg",
"images/jonny_thumb.jpg",
"images/trudi_thumb.jpg"];

function timedAnimator()
{
var my_img;
my_img=document.getElementById('sample_img');
my_img.style.left = x_pos+"px";
my_img.style.top = y_pos+"px";

if (x_pos!=0) x_pos +=directions[direction_index][0];
if (y_pos!=0) y_pos+=directions[direction_index][1];
x_pos=Math.round(x_pos*.92);
y_pos=Math.round(y_pos*.92);

if((x_pos==0)&&(y_pos==0))
{

   if (Math.random()>.4)
      direction_index=Math.floor(directions.length*Math.random());
   if (direction_index>=directions.length) direction_index=0; //Catch any uncommon rounding errors
   
   x_pos=directions[direction_index][2];
   y_pos=directions[direction_index][3];
  
  my_img=document.getElementById("sample_div");
  my_img.style.backgroundImage="url("+img_urls[image_index]+")";

 do{
    nu_img=Math.floor(Math.random()*img_urls.length);
 }while(nu_img==image_index);
  image_index=nu_img;
  
   my_img=document.getElementById('sample_img');
  
   my_img.style.left = x_pos+"px";
   my_img.style.top = y_pos+"px";
   my_img.src=img_urls[image_index];
}

t=setTimeout("timedAnimator()",40);
}

function imagePreloader()
{
var n,t_img,t;
	for(n=0;n<img_urls.length;n++)
	{
	 	t_img = new Image();
		t_img.src=img_urls[n];
	}
	
	t=setTimeout("timedAnimator()",40);
}
