$(function () { $('.gallery-container > li').hoverIntent({ over: showPreview, timeout: 500, out: hidePreview, sensitivity: 4 }); function showPreview () { $(this).find ('.preview').fadeIn (); } function hidePreview () { $(this).find ('.preview').fadeOut (); } setTimeout (function () { $('.gallery-container > li').each (function () { var preview, img, width, height; preview = $(this).find ('.preview'); img = $(this).find ('img'); width = img.width (); height = img.height (); preview.css ({ width: width }); preview.css ({ height: height }); preview.addClass ('ui-lightbox'); }); }, 500); });