﻿var lastMousePos = {x: 0, y: 0};
var timer,i,d = 0;
var trailElement = 8;
var path = "/common/images/css/mouseTrail.png";

function initTrail() {
    images = new Array();
    for (i=0; i<parseInt(trailElement); i++) {
	    images[i] = new Image();
	    images[i].src = path;
    }
    storage = new Array();
    for (i=0; i<images.length*3; i++) {
	    storage[i] = 0;
    }
    for (i=0; i<images.length; i++) {
	    document.write('<div id="oMouseTrail' + i + '" class="cssMouseTrail"><img src="' + images[i].src + '" width="28" height="24" alt="" /></div>\r\n');
    }
    trail();
}
function trail() {
    for (i=0; i<images.length; i++) {
	    thisEl = document.getElementById("oMouseTrail" + i);
	    thisEl.style.top = storage[d]+'px';
	    thisEl.style.left = + storage[d+1]+'px';

	    if (storage[d+1] == lastMousePos.x && storage[d] == lastMousePos.y && i>0)
		    thisEl.style.display = "none";
	    else
		    thisEl.style.display = "block";

	    d = d+2;
    }
    for (i=storage.length; i>=2; i--) {
	    storage[i] = storage[i-2];
    }
    d = 0;
    timer = setTimeout("trail()",25);
}
initTrail();

$(document).ready(function(){
    $(this).mousemove(function(e){
		storage[0] = e.pageY + 10;
		storage[1] = e.pageX + 20;
	    lastMousePos.y = storage[0];
	    lastMousePos.x = storage[1];
    });
});
