var FileName = "";
var HTMLText = "";
var trailLength = 8 // The length of trail (8 by default; put more for longer "tail")
var path = "http://www.lcars.org.uk/images/trail1.gif" // URL of your image
var isIE = false, isNav = false, isOther=false, range = "all.", style = ".style", i, d = 0
var topPix = ".pixelTop", leftPix = ".pixelLeft", images, storage
var ns4 = (document.layers) ? 1 : 0;
var ie4 = (document.all) ? 1 : 0;
var ns6 = (document.getElementById && !document.all) ? 1 : 0;

function OpenPage()
{
	TrailCursor();
	dynAnimation();
}

function FP_playSound(path) {//v1.0
 var b,d=document,e,es,i,se="<EMBED SRC='"+path+"' HIDDEN=TRUE LOOP=FALSE AUTOSTART=TRUE>";			
 if(d.body)b=d.body;	if(d.getElementsByTagName) { es=d.getElementsByTagName('embed')		
 for(i=0;i<es.length;i++) { e=es(i); if( e.src==path ) { if(e.removeNode) e.removeNode();
 break; } } if(b&&b.insertAdjacentHTML) b.insertAdjacentHTML("beforeend",se); }
}

function TrailCursor() {

	if (document.layers) { // browser sniffer
		isNav = true,range = "layers.",style = "",topPix = ".top",leftPix = ".left"
	} else if (document.all) {
		isIE = true;
	}
	else {
		isOther = true;
	}

	initTrail() 
	if (isNav) {
		document.captureEvents(Event.MOUSEMOVE) // Defines what events to capture for Navigator
		document.onmousemove = processEvent // start capturing
	}
	if ( isOther ) {
		document.addEventListener("mousemove", processEvent, true);
	}
	if ( isIE ) {
		document.onmousemove = processEvent // start capturing
	}
}

function initTrail() { // prepares the script

	images = new Array(); // prepare the image array
	for (i = 0; i < parseInt(trailLength); i++) {
		images[i] = new Image()
		images[i].src = path
	}
	storage = new Array() // prepare the storage for the coordinates
	for (i = 0; i < images.length*3; i++) {
		storage[i] = 0
	}
	for (i = 0; i < images.length; i++) { // make divs for IE and layers for Navigator
		(isIE || isOther) ? HTMLText = HTMLText + '<div id="trail' + i + '" style="position: absolute; z-Index: 100; height: 0; width: 0;"><img src="' + images[i].src + '"></div>' : HTMLText = HTMLText + '<layer name="trail' + i + '" width="0" height="0" z-index="100"><img src="' + images[i].src + '"></layer>';
	}
	document.getElementById('Cursor').innerHTML = HTMLText;	
	CheckTrail();
	trail()
}

function trail() { // trailing function
	for (i = 0; i < images.length; i++) { // for every div/layer
		document.getElementById('trail'+i).style.top = storage[d];
		document.getElementById('trail'+i).style.left = storage[d+1];

		d = d+2
	}
	for (i = storage.length; i >= 2; i--) { // save the coordinate for the div/layer that's behind
		storage[i] = storage[i-2]
	}
	d = 0 // reset for future use
	var timer = setTimeout("trail()",10) // call recursively 
}

function processEvent(e) { // catches and processes the mousemove event 
	var width = (ns4||ns6) ? window.innerWidth : document.body.clientWidth;
	var height = (ns4||ns6) ? window.innerHeight : document.body.clientHeight;
	//window.status = width + ": " + height + " - " + (window.event.clientY+document.body.scrollTop+10) + " : " + (window.event.clientX+document.body.scrollLeft+10);
	if (isIE ) { // for IE
		storage[0] = window.event.clientY+document.body.scrollTop+10
		storage[1] = window.event.clientX+document.body.scrollLeft+10
	} else { // for Navigator
		storage[0] = e.pageY+12
		storage[1] = e.pageX+12
	}
}


function CheckTrail() {
	if (parent.document.getElementById('MouseFlag').value == 'HIDE') {
		if ( isIE ) {
			document.getElementById("Cursor").style.display = "none";
		}
		else {
			for ( i = 0; i<8; i++) document.getElementById("trail"+i).style.display = "none";
		}
	} 
	else {
		if ( isIE ) {
			document.getElementById("Cursor").style.display = "block";
		}
		else {
			for ( i = 0; i<8; i++) document.getElementById("trail"+i).style.display = "block";
		}
	}
}

