Perfecting canvas mouse coordinates
===

I'm working on a function that I can use to get canvas coordinates.
Works kind of well, until part of the canvas is invisible on the screen.

When i make the window small, and scroll to bottom right corner it seems to start from the visible part of the canvas. How can I fix this to get the right coordinates?

Here's my code:

    function getMousePosition(event) {
	var MX = new Number();
	var MY = new Number();

	if (event.x != undefined && event.y != undefined) {
		MX = event.x;
		MY = event.y;
	}
	else { // Firefox method to get the position
		MX = event.clientX + document.body.scrollLeft +
		document.documentElement.scrollLeft;
		MY = event.clientY + document.body.scrollTop +
		document.documentElement.scrollTop;
	}
	MX -= canvas.offsetLeft;
	MY -= canvas.offsetTop;
	alert("x: " + MX + "  y: " + MY);
}