function setup_ratio(i) { var o = $(i).offset(); var xo = o.left; if (parseInt(navigator.appVersion) > 3) { if (navigator.appName=="Netscape") { winW = window.innerWidth; } else if (navigator.appName.indexOf("Microsoft") != -1) { winW = document.body.offsetWidth; } } var xroom = winW - (xo + 45); var ratio = 1.0; while( xroom < i.width*ratio ) ratio -= 0.01; return ratio; } $(document).ready(function() { var ol = function(){ var ratio = setup_ratio(this); var s = { orgw: this.width, orgh: this.height, neww: this.width*ratio, newh: this.height*ratio }; $(this).animate({width: s.neww, height: s.newh}, 500).attr(s).click(function(){ var t = $(this); if( Math.abs(t.attr("width") - t.attr("neww"))<=2 ) { t.animate({width: t.attr("orgw"), height: t.attr("orgh")}, 500); } else { t.animate({width: t.attr("neww"), height: t.attr("newh")}, 500); } }); }; $("img").each(function(){ $(this).load(ol); this.src = this.src; }); // workaround for a known bug });