The context sensitive Language Versions link

Most bilingual sites only have a fixed link to the other language version. Wherever you are on one language version of a site, clicking on the Language Version link always takes you to the home page of the other version of the site. But I want my visitors get the exact page they are viewing written in the other language. I used the javascript replace method to make it work.