$(document).ready(function(){
    $('#image_gallery div.thumbs a').click(function(){
        var elLoad = $('#loading_wrapper');
        elLoad.css({ opacity: 0, display: 'block', visibility: 'visible', width: $(this).parent().width() + 'px', height: $(this).parent().height() + 'px' });
        elLoad.stop().animate({ opacity: 0.8});
        var newImg = $(this).attr('href');
        var newAlt = $(this).find('img').attr('alt');
        var newTitle = $(this).find('img').attr('title');
        $('#main_image_wrapper').animate({ opacity: 0 }, 500, function(){
            $('#main_image').find('img').attr({ src: newImg, title: newTitle, alt: newAlt });  
            $('#image_title').html(newTitle);
            $('#main_image').stop().animate({ opacity: 1 },500,function(){
              elLoad.stop().animate({ opacity: 0 },500);
              
              var newHeight = $(this).height();
              if(newTitle!=''){ newHeight = newHeight + 17; }
              $('#main_image_wrapper').stop().animate({ opacity: 1, height: newHeight+'px' }, 500);  
            })
        })
        return false;
    });    
});