JavaScript: Resolution independent click event location

I need a way to normalize mouse clicks across different resolution sizes for placement of an image. Currently I’m converting the x/y coordinates to percentages and then convert that percentage to the proper x/y value based on their resolution.

http://pastie.org/235472

This works very poorly, sometimes the images will be 100-150px off. Although the margin of error gets smaller as the resolutions get closer. I don’t know what I’m doing wrong or how to fix it.

Your rating: None