jQuery.noConflict();
jQuery(document).ready(function($){
    $('div.new_loadarea').each(function(){
/*  Come this way for every div with a class of new_loadarea  */
    var $div_id = $(this).attr("id");
    $return_html = "<div class='loadarea_thumbs'><p>To enlarge smaller images, please hover over with mouse.</p>\n";
/*  First decide if we are dealing with hyperlinks or just images */
    var $link_count = $("div#"+$div_id+" a").length;
    if ($link_count > 0)
    {
/*  At least one link - so away we go */
        $("div#"+$div_id+" a").each(function() {
/* Now build a thumbnail link for image */
/* Start by grabbing the underlying link 'cos we're going to overwrite that */
            var $link = $(this).attr("href");
            var $img = $(this).children("img:first");
            var $img_src = $img.attr("src");
            var $img_caption = $img.attr("title");
            var $thumb = "<a href='"+$img_src+"' rel='enlargeimage' rev='targetdiv:loadarea_"+$div_id+",link:"+$link+"'><img src='"+$img_src+"' title='"+$img_caption+"' alt='' /></a>\n";
            $return_html = $return_html + $thumb;
        })
    }
    else {
/*  No links - so how many images are we dealing with?  */
        var $img_count = $("div#"+$div_id+" img").length;
/*  If more than one, build a thumbnail division */
        if ($img_count > 1)
        {
            $("div#"+$div_id+" img").each(function() {
/*  Build a thumbnail link for image image */
            var $thumb = "<a href='"+$(this).attr("src")+"' rel='enlargeimage' rev='targetdiv:loadarea_"+$div_id+"'><img src='"+$(this).attr("src")+"' alt='' /></a>\n";
            $return_html = $return_html + $thumb;
        });
        }
    }
    var $return_html = $return_html + "</div>\n";

/*  First image in the division is the main man regardless of anything else */
    var $main_image_src = $("div#"+$div_id+" img:first").attr("src");
    var $main_image = "<img class='main_pic' title='' src='"+$main_image_src+"' alt='' />";
    $return_html = $return_html + "<div id='loadarea_"+$div_id+"'>\n";
    $return_html = $return_html + $main_image;
    $return_html = $return_html + "</div></div>";
    $(this).html($return_html);
    })
});

