
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation. Please see the index.html
// for more details.

function Face(faceId, faceX, faceY, width, height, eyeLeft, eyeRight)
{
	var thiz = this;

	var face = document.getElementById(faceId);
	if (face == null)
	{
		throw new Exception("Face: There is no element with the faceId == " + faceId + ".");
	}

	// var width = face.getAttribute("width");
	// var height = face.getAttribute("height");

	this.offsetX = faceX - (width / 2);
	this.offsetY = faceY - (height / 2);

	face.style.left = this.offsetX + "px";
	face.style.top = this.offsetY + "px";

	function onMouseMove(event)
	{
		draw(event);
	}

	function draw(event)
	{
		eyeLeft.draw(thiz, event);
		eyeRight.draw(thiz, event);
	}

	if (typeof document.addEventListener == 'undefined')
	{
		document.attachEvent("onmousemove", onMouseMove);
	}
	else
	{
		document.addEventListener("mousemove", onMouseMove, true);
	}

	face.style.display = "block";

	draw();
}


