( function( $ ) {
    var $img = $( 'img' ),
        $win = $( window );

    setImageSizes();
    
    $win.resize( function() {
        setImageSizes();
    } );
    
    function setImageSizes() {
            
        $img.removeAttr( 'style' );
        
        var imgHeight = $img.height(),
            winHeight = $win.height();

        if( imgHeight > winHeight ) {
            $img.height( winHeight );
        } else if( imgHeight < winHeight ) {
            $img.css({
                'margin-top': ( winHeight - imgHeight ) / 2
            });
        }

        var imgWidth = $img.width(),
            winWidth = $win.width();

        if( imgWidth > winWidth ) {
            $img.width( winWidth );
        } else if( imgWidth < winWidth ) {
            $img.css({
                'margin-left': ( winWidth - imgWidth ) / 2
            });
        }
    }
} ( jQuery ) )
