var trailLength = 10 // The length of trail (8 by default; put more for longer "tail")
var range = "layers.",style = "",topPix = ".top",leftPix = ".left",il,d = 0,images,storage
var cursor = false

function initTrail() { // prepares the script
	images = new Array() // prepare the image array
	for (il = 0; il < parseInt(trailLength); il++) {
		images[il] = new Image()
		images[il].src = "../../gif/redball.gif"
	}
	storage = new Array() // prepare the storage for the coordinates
	for (il = 0; il < images.length*3; il++) {
		storage[il] = -10;
	}
	for (il = 0; il < images.length; il++) { 
		document.write('<layer name="obj' + il + '" width="0" height="0" z-index="100"><img src="' + images[il].src + '"></layer>')
	}
	trail()
}
function trail() { // trailing function
	for (il = 0; il < images.length; il++) { // for every div/layer
		eval("document.layers.obj" + il + ".top=" + storage[d]) // the Y-coordinate
		eval("document.layers.obj" + il + ".left=" + storage[d+1]) // the X-coordinate
		d = d+2
	}
	for (il = storage.length; il >= 2; il--) { // save the coordinate for the div/layer that's behind
		storage[il] = storage[il-2]
	}
	d = 0 // reset for future use
        if (cursor) {  
	     setTimeout("trail()",5) // call recursively 
        }
}
function processEvent(e) { // catches and processes the mousemove event 
	storage[0] = e.pageY +1
	storage[1] = e.pageX +1
}

function mouseDown(e) {
  clickType=e.which;
  if (clickType!=1)  TrialSwitch();
  return true;
}

function TrialStore() {
     for (il = 0; il < images.length; il++) { // for every div/layer
        eval("document.layers.obj" + il + ".top=" + -10) // the Y-coordinate
        eval("document.layers.obj" + il + ".left=" + -10) // the X-coordinate
     }
}

function TrialSwitch(){
     if (cursor) {  
        cursor = false;
	trail();
	setTimeout("TrialStore()",50) 
     } else {
         cursor = true;
         trail();
     }
}        

document.captureEvents(Event.MOUSEMOVE);
document.captureEvents(Event.MOUSEDOWN);
initTrail() 
document.onmousemove = processEvent;
document.onmousedown = mouseDown;



