function embiggen_image_cb() {
    $(this).attr('src', $(this).attr('src_big'));
}

function ensmallen_image_cb() {
    $(this).attr('src', $(this).attr('src_small'));
    $(this).parents('.zoomable-image-container').css('zIndex', '400');
}

$(document).ready(function() {
    $('.zoomable-image').each( function() {
        $(this).attr('src_small', $(this).attr('src'));
        $(this).attr('src_big', $(this).parents('div.property-element, div.property').find('.big-image').attr('src'));
        $(this).attr('orig_width', ($(this).css('width')));
        $(this).parents('.zoomable-image-container').css('zIndex', '100');
    });

    $(".zoomable-image").hover(
        function() {
            if ($(this).attr('src').match('missing-image')) return;
            $(this).parents('.zoomable-image-container').css('zIndex', '500');
            $(this).animate({
                width:"450px"
            }, 500, 'swing', embiggen_image_cb);
        },
        function() {
            if ($(this).attr('src').match('missing-image')) return;
            $(this).animate({ 
                width: $(this).attr('orig_width')
            }, 200, 'swing', ensmallen_image_cb );
        }
    );
});
