Convert preview script to jQuery