i like to use urls which are relative to the root of the website for this very reason.
for example,
if the browser is at
example.org/index.php/path/info/
and you link to an image like so
<img src="images/foo.gif">
the browser will look here
example.org/index.php/path/info/images/foo.gif
and if the browser was here(notice no trailing / this time)
example.org/index.php/path/info
it would look here for the image
example.org/index.php/path/images/foo.gif
to make your urls relative to the root of your site, use a leading / like so
<img src="/images/foo.gif">
now the browser will look here
example.org/images/foo.gif
im not sure, but if your javascript is in an externale file, this may be affecting how your relative urls are calculated. using urls relative to the root would eliminate this possibility.
have a read
http://webtips.dan.info/url.html
you may also want to google up on the html <base> tag.