var windowid = 1;
function NewWindow(param){
  var page_size = getPageSize();
  var shadow = $('<div id="pop-shadow"></div>');
  var close  = $('<div id="pop-close"><img src="/skin/images/zoomer/close.png" alt="закрыть"></div>');
  
  $(close).click(function(){
    $(shadow).remove();
    $(close).remove();
    $(param['object']).hide();
    return false;
  });
  
  $(shadow).show(); 
  $(shadow).css({'position':'absolute','background':'#000','opacity':'0.5','top':'0px','left':'0px','width': '100%','height': page_size[1]+'px','position': 'absolute','z-index':'999'});
  $('body').append(shadow);
  
  var win_width = $(param['object']).width();
  var win_height = $(param['object']).height();
  var marginLeft = Math.max(40, parseInt($(window).width()/2 - win_width/2)) + 'px';
  var marginTop  = Math.max(40, parseInt(($(window).height()/2 - win_height/2)+$(document).scrollTop())) + 'px';
  $(param['object']).append(close);
  $(param['object']).css('position','absolute');
  $(param['object']).css('left',marginLeft); 
  $(param['object']).css('top',marginTop);
  $(param['object']).css('z-index','1000');
  $(param['object']).css('display','block');
  
  return false;
}

function  getPageSize(){
       var xScroll, yScroll;

       if (window.innerHeight && window.scrollMaxY) {
                  xScroll = document.body.scrollWidth;
                  yScroll = window.innerHeight + window.scrollMaxY;
       } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
                  xScroll = document.body.scrollWidth;
                  yScroll = document.body.scrollHeight;
       } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
                  xScroll = document.documentElement.scrollWidth;
                  yScroll = document.documentElement.scrollHeight;
       } else { // Explorer Mac...would also work in Mozilla and Safari
                  xScroll = document.body.offsetWidth;
                  yScroll = document.body.offsetHeight;
       }

       var windowWidth, windowHeight;
       if (self.innerHeight) { // all except Explorer
                 windowWidth = self.innerWidth;
                 windowHeight = self.innerHeight;
       } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
                 windowWidth = document.documentElement.clientWidth;
                 windowHeight = document.documentElement.clientHeight;
       } else if (document.body) { // other Explorers
                 windowWidth = document.body.clientWidth;
                 windowHeight = document.body.clientHeight;
       }
  
  
       // for small pages with total height less then height of the viewport
       if(yScroll < windowHeight){
          pageHeight = windowHeight;
       } else {
          pageHeight = yScroll;
       }

       // for small pages with total width less then width of the viewport
       if(xScroll < windowWidth){
                 pageWidth = windowWidth;
       } else {
                 pageWidth = xScroll;
       }

       return [pageWidth,pageHeight,windowWidth,windowHeight];
}
