(function(e){e.fn.extend({scale:function(f,g,h){return this.each(function(){function k(){if(a.data("jquery_scale_orig-height")){a.height(a.data("jquery_scale_orig-height"));a.width(a.data("jquery_scale_orig-width"));b("jquery.scale: has been run before. Reset the object to its original dimensions of "+a.width()+"x"+a.height())}else{a.data("jquery_scale_orig-height",a.height());a.data("jquery_scale_orig-width",a.width());b("jquery.scale: is starting for the first time. Captured the original dimensions of "+ a.width()+"x"+a.height())}b("jquery.scale: BEFORE scaling, object's outer size = "+a.outerWidth()+"x"+a.outerHeight()+", object's parent's inner size = "+a.parent().width()+"x"+a.parent().height());if(a.outerHeight()>a.parent().height()&&a.outerWidth()<=a.parent().width()){b("jquery.scale: object is too tall, but width is OK");i()}else if(a.outerWidth()>a.parent().width()&&a.outerHeight()<=a.parent().height()){b("jquery.scale: object is too wide, but height is OK");j()}else if(a.outerWidth()a.parent().width()&&a.outerHeight()>a.parent().height()){b("jquery.scale: object is too tall and wide");if(a.parent().height()/ a.outerHeight()>a.parent().width()/a.outerWidth()){b("jquery.scale: width is closer to being correct");j()}else{b("jquery.scale: height is closer to being correct, or height and width are equally close to being correct");i()}}if(m){b("jquery.scale: centering option enabled");a.css("position","relative");a.css("margin-top",a.parent().height()/2-a.outerHeight()/2);a.css("margin-left",a.parent().width()/2-a.outerWidth()/2)}this.onload=null;b("jquery.scale: AFTER scaling, object's size = "+a.outerWidth()+ "x"+a.outerHeight()+", object's parent's size = "+a.parent().width()+"x"+a.parent().height()+".'")}function i(){b("jquery.scale: matching height");a.width(a.outerWidth()*a.parent().height()/a.outerHeight()-(a.outerWidth()-a.width()));a.height(a.parent().height()-(a.outerHeight()-a.height()))}function j(){b("jquery.scale: matching width");a.height(a.outerHeight()*a.parent().width()/a.outerWidth()-(a.outerHeight()-a.height()));a.width(a.parent().width()-(a.outerWidth()-a.width()))}function b(o){window.console&& n&&console.log(o)}b("jquery.scale is starting...");b('jquery.scale: Using browser "'+navigator.appName+'" version "'+navigator.appVersion+'"');var m=false,l=false,n=false;if(f=="center"||g=="center"||h=="center")m=true;if(f=="stretch"||g=="stretch"||h=="stretch")l=true;if(f=="debug"||g=="debug"||h=="debug")n=true;var a=e(this);if(a.attr("src")&&!a.data("jquery_scale_orig-height")){b("jquery.scale: object is an image");var p=new Date,c=a.attr("src"),d=c;if(c.indexOf("?")!=-1)d=c.substring(0,c.indexOf("?")); d=d+"?"+p.getTime();a.attr("src",d);b("jquery.scale: img src changed to "+d+" to force a reload");e.support.leadingWhitespace&&a.attr("src",c);this.onload=k}else{b("jquery.scale: object is NOT an image");k()}})}})})(jQuery);