I created this code to resize photos/images to fit the screen, considering the space available for the nav bar.
The script fires on image load and on navigation clic
I know this question is well old, but here's a solution (although I'm sure the OP's works fine too):
This jQuery plugin seems to do exactly what you need: http://code.google.com/p/jquery-imagefit-plugin/
if you perform it on a 100% height, 100% width element: http://www.tutwow.com/htmlcss/quick-tip-css-100-height/
(demo: http://jsfiddle.net/nottrobin/9Pbdz/)