var followCursor = function() {

	var cursors = [];
	var options = {
		offsetX: 15,
		offsetY: 10,
		rate: 50,
		count: 4
	};
	
	var bounds;
	
	var setPos = function(e) {
		var xPos, yPos, oldX, oldY, len = cursors.length;
		e = getEvent(e);
		moveCursor(cursors.length - 1, getXpos(e) + 2, getYpos(e) + 2);
		cursors[cursors.length - 1].div.style.display = "block";
	}
	
	var updatePos = function() {
		var x, len = cursors.length;
		var coordX, coordY;
		for(x = 0; x < len - 1; x++) {
			moveCursor(x, cursors[x + 1].curPos.x + options.offsetX, cursors[x + 1].curPos.y + options.offsetX);
			if(cursors[x + 1].div.style.display == "block") {
				cursors[x].div.style.display = "block";
			}
		}
	}
	
	var moveCursor = function(index, xPos, yPos) {
		cursors[index].curPos.x = Math.min(xPos + cursors[index].div.style.width, bounds.width);
		cursors[index].curPos.y = Math.min(yPos + cursors[index].div.style.height, bounds.height);
		cursors[index].div.style.left = cursors[index].curPos.x + "px";
		cursors[index].div.style.top = cursors[index].curPos.y + "px";
	};
	
	var addEvent = function(elem, type, fnc) {
		if(elem.addEventListener) {
			elem.addEventListener(type, fnc, false);
		} else {
			elem.attachEvent("on" + type, fnc);
		}
	}
	
	var getXpos = function(e) {
		if(e.pageX) {
			return e.pageX
		} else {
			return e.clientX;
		}
	}
	
	var getYpos = function(e) {
		if(e.pageY) {
			return e.pageY;
		} else {
			return e.clientY;
		}
	}
	
	var getEvent = function(e) {
		if(!e) e = window.event;
		return e;
	}
	
	var setBounds = function(e) {
		bounds.width = document.body.scrollWidth;
		bounds.height = document.body.scrollHeight;
	}
	
	return {
		init: function() {
			var len = options.count;
			var cursorDiv;
			for(var x = 0; x < len; x++) {
				cursorDiv = document.createElement("div");
				cursorDiv.className = "cursorImage" + x;
				cursorDiv.style.display = "none";
				document.body.appendChild(cursorDiv);
				cursors.push(
					{
						curPos: {x: 0, y: 0},
						targetPos: {x:0, y:0},
						div: cursorDiv
					}
				);
			}
			bounds = {width: document.body.scrollWidth, height: document.body.scrollHeight};
			addEvent(document.body, "mousemove", setPos);
			addEvent(document.body, "resize", setBounds);
			setInterval(updatePos, options.rate);
		}
	}
}();



