var ratio;
$(document).ready(function()
{
    $(".back").load(function()
    {
        var width = $(this).width();
        var height = $(this).height();
        ratio = width / height;
        setSizeAndShow(this);
    }).each(function()
    {
        if (this.complete || (jQuery.browser.msie && parseInt(jQuery.browser.version) == 6))
            $(this).trigger("load");
    });
    $(window).bind('resize', function()
    {
        setSizeAndShow($('.back'));
    });
});
function setSizeAndShow(image)
{
    var windowHeight = $('#wrapper').height();
    var windowWidth = $('#wrapper').width();
    var thisRatio = Math.max(ratio, (windowWidth / windowHeight));
    if (thisRatio > ratio)
    {
        $(image).width(windowWidth);
        $(image).height(windowWidth / ratio);
    }
    else
    {
        $(image).width(windowHeight * ratio);
        $(image).height(windowHeight);
    }
    $(image).css('top', ((windowHeight - $(image).height()) / 2) + 'px');
    $(image).css('left', ((windowWidth - $(image).width()) / 2) + 'px');
    $(image).css('display', '');
}
