jQuery(document).ready(function() {
    //collapsibleComments();
    showImagesInGallery();
    }
);

function collapsibleComments() {
    jQuery('.commentlink').click(function() {
        $(this).parent().next().slideToggle(400); 
        //alert($(this).parent().next().attr('id'));
        return false;
    }
    );
}

function hideImagesInGallery(){
     jQuery(".gallery").each(function(index, obj){
        var len = jQuery(obj).find("a").length;
        if (len > 0) {
            temp = jQuery(this).next();
            for(i=0; i < len; i++){
                jQuery(temp).hide();
                temp =jQuery(temp).next();                         
            }
        }
    });
}

function showImagesInGallery()  {
   jQuery(".gallery-icon").click(function() {
        var title = jQuery(this).find("img").attr('title');
        var src = jQuery(this).find("img").attr('src');
        var size_re =  /(.*)(-thumb)(.*$)/;
        var new_url = src.replace(size_re, '$1-medium$3');
        var big_url = src.replace(size_re, '$1-large$3');
        var id = jQuery(this).parent().parent().attr('id');
        var re = /\w+\-(\d+)/;
        var m = re.exec(id);
        if (m!=null) {
            num = m[Math.max(m.length - 1, 0)];
            jQuery("#gallery-viewer_" + num).find("img").attr('title',title);
            jQuery("#gallery-viewer_" + num).find("img").attr('src',new_url);
            jQuery("#gallery-viewer_" + num).attr('href', new_url);
        }

        return false;
   });
}

