function get_scroll_xy() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function resize_modal(custom_width) {
    custom_width = custom_width || 450;
    $("#modal_window").width(custom_width);
    window_height = $(window).height();
    window_width = $(window).width();
    blanket_height = Math.max(window_height, $('body').height(), $('html').height());

    var blanket = document.getElementById('blanket');
    var modal_div = document.getElementById('modal_window');

    modal_height = $('#modal_window').height();   //150 is half popup's height
    blanket.style.height = blanket_height + 'px';
    scroll_top = get_scroll_xy()[1];
    var top_px = scroll_top + window_height/10 - modal_height/10;
    if (top_px < 100){
        top_px = 100;
    }
    modal_div.style.top = top_px + 'px';
    modal_div.style.left = window_width/2-custom_width/2 + 'px';
}
function modal_window(custom_width) {
    $("#blanket").toggle();
    $("#modal_window").toggle();
    resize_modal(custom_width);
}
$(document).ready(function(){
    $("#blanket").click(function(){
        modal_window();
    });
})
