$.extend({ autoimagesize: function (item, bool) { if (item[0]) { item = item[0]; } var imgwidth = item.width; var imgheight = item.height; if (!item[0]) { item = $(item); } var parent = item.parent(); var boxh = parent.height(); var boxw = parent.width(); if (imgwidth > boxw) { imgheight = imgheight * (boxw / imgwidth); imgwidth = boxw; } if (imgheight > boxh) { imgwidth = imgwidth * (boxh / imgheight); imgheight = boxh; } if (typeof bool === 'undefined') { item.attr("style", ""); } if (!parent.is(":hidden")) { item.css({'width': imgwidth + 'px', 'height': imgheight + 'px', 'left': (boxw - imgwidth) / 2 + "px", 'top': (boxh - imgheight) / 2 + "px"}); $(window).resize(function () { $.autoimagesize(item); }); } else { var seti = setinterval(function () { if (!parent.is(":hidden")) { clearinterval(seti); $.autoimagesize(item); } $(window).resize(function () { clearinterval(seti); }); }, 100); } }, autoproductimgsize: function (item) { var imgwidth = item.width(); var imgheight = item.height(); var parent = item.parent(); var boxh = parent.height(); var boxw = parent.width(); if ((imgwidth / imgheight) < (boxw / boxh)) { item.css({'height': (boxw / boxh) * ((imgheight * 1.00) / imgwidth) * boxh, 'max-height': (boxw / boxh) * ((imgheight * 1.00) / imgwidth) * boxh, 'top': -((boxw / boxh) * ((imgheight * 1.00) / imgwidth) - 1) / 2 * boxh}) } else { item.css({'width': (boxh / boxw) * ((imgwidth * 1.00) / imgheight) * boxw, 'max-width': (boxh / boxw) * ((imgwidth * 1.00) / imgheight) * boxw, 'left': -((boxh / boxw) * ((imgwidth * 1.00) / imgheight) - 1) / 2 * boxw}) } } });