Div on center screen isnt centred when webpage scrolled down
<p>How to centre the div on the website? ive such script:</p>

<pre><code>$(document).ready( function(){    

    $('.cod').click(function() {
    var div_name = $(this).attr('id');

    $('#overlay_window').load('/templates/' + div_name + '_template.php', function(){
    var div_width = $('#'+div_name+'-overlay').width();
    var div_height = $('#'+div_name+'-overlay').height();
    $('#overlay_window').css("width", ""+div_width+"px")
    $('#overlay_window').css("height", ""+div_height+"px")
    var div2_width = $('#overlay_window').width();
    var div2_height = $('#overlay_window').height();
    var window_width = $(window).width();
    var window_height = $(window).height();

    var widthoffset = (window_width - div2_width) / 2;  
    var heightoffset = (window_height - div2_height) / 2;   
    $('#overlay_window').css("left", "" + (widthoffset) + "px");
    $('#overlay_window').css("top", "" + (heightoffset + 750) + "px");
    $('#overlay_background').fadeIn(800);
    $('#overlay_window').fadeIn(800);
    });
    });




    });
</code></pre>

<p>but it centres the div from top of page and if its scrolled down it appears on top not there where ive scrolled, can someone help?</p>
