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

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

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

function showImagesInGallery() {
   $(".gallery-icon").click(function() {
        var title = $(this).find("img").attr('title');
        var src = $(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$3');
        var id = $(this).parent().parent().attr('id');
        var re = /\w+\-(\d+)/;
        var m = re.exec(id);
        //alert(new_url);
        if (m!=null) {
            num = m[Math.max(m.length - 1, 0)];
            $("#gallery-viewer_" + num).find("img").attr('title',title);
            $("#gallery-viewer_" + num).find("img").attr('src',new_url);
            $("#gallery-viewer_" + num).attr('href', new_url);
        }

        return false;
   });
}
