
function resize_images() {
    
    var $window = $(window),
        window_height = $window.height(),
        window_width = $window.width(),
        third_window_width = window_width / 3,
        $image_left = $('#left img.bg'),
        $image_middle = $('#middle img.bg'),
        $image_right = $('#right img.bg'),
        $images = $('.container img.bg');
    
    if (third_window_width > window_height) {
        $images.css('width', third_window_width);
        $images.css('height', null);
    } else {
        $images.css('width', null);
        $images.css('height', window_height);
    }
    
    if (third_window_width < $image_left.width() ) {
        var offset_horizontal = (third_window_width - $image_left.width() ) / 2;
        $image_left.css('left', offset_horizontal);
        $image_left.css('top', 0);
    } else {
        var offset_vertical = (window_height - $image_left.height() ) / 2;
        $image_left.css('left', 0);
        $image_left.css('top', offset_vertical);
    }
    
    if (third_window_width < $image_middle.width() ) {
        var offset_horizontal = (third_window_width - $image_middle.width() ) / 2;
        $image_middle.css('left', offset_horizontal);
        $image_middle.css('top', 0);
    } else {
        var offset_vertical = (window_height - $image_middle.height() ) / 2;
        $image_middle.css('left', 0);
        $image_middle.css('top', offset_vertical);
    }
    
    if (third_window_width < $image_right.width() ) {
        var offset_horizontal = (third_window_width - $image_right.width() ) / 2;
        $image_right.css('left', offset_horizontal);
        $image_right.css('top', 0);
    } else {
        var offset_vertical = (window_height - $image_right.height() ) / 2;
        $image_right.css('left', 0);
        $image_right.css('top', offset_vertical);
    }
    
}

$(document).ready(function() {
    $('.container').css('opacity',0);
});

$(window).load(function() {
    
    resize_images()
    
    $('.container').animate({
        opacity: 1
    }, 300);
    
});

$(window).resize(function() {
    resize_images();
});

