function ModalDiv(modalDiv) {
  this.modalDiv = $(modalDiv);
  this.__modality = $('__modality');
  this.index = 0;
  return this.initialize();
};

ModalDiv.prototype = {
  initialize: function() {
    this.modalDiv.style.position = 'absolute';
    this.modalDiv.style.zIndex = 900 + this.index * 150;
  },
  reindex: function(){
    if(this.index){
      if(!$('__modality'+this.index)){
        var tmp = document.createElement('div');
        tmp.setAttribute('id', '__modality'+this.index);
        tmp.className="div_modality";
        tmp.style.zIndex = 900 + this.index * 100;
        document.body.appendChild(tmp);
      }
      this.__modality = $('__modality'+this.index);
      this.modalDiv.style.zIndex = 900 + this.index * 150;
    }
  },
  show: function() {
    this.hidden = false;
    //this.__modality.style.width = '100%'; // FIXME later!
    this.__modality.style.width = getDocWidth() + 'px';
    //this.__modality.style.height = (ScreenUtils.getClientHeight()) + 'px'; // FIXME later!
    //this.__modality.style.height = '100%';
    this.__modality.style.height = getDocHeight() + 'px';
    

    //this.__modality.style.height = (ScreenUtils.getHeight() + ScreenUtils.getScrollTop()) + 'px';
    //alert(Math.round(ScreenUtils.getHeight() / 2 + ScreenUtils.getScrollTop()) + 'px');
    this.modalDiv.style.top = Math.round(ScreenUtils.getHeight() / 2 + ScreenUtils.getScrollTop()) + 'px';
    this.modalDiv.style.display = 'block';
    //this.modalDiv.style.top = Math.round(ScreenUtils.getHeight() / 2 + ScreenUtils.getScrollTop() - this.modalDiv.scrollHeight/4) + 'px';
    //alert(this.modalDiv.scrollHeight);
    return this;
  },
  showADV: function(t,l) {
    this.hidden = false;
    //this.__modality.style.width = '100%'; // FIXME later!
    this.__modality.style.width = getDocWidth() + 'px';
    //this.__modality.style.height = (ScreenUtils.getClientHeight()) + 'px'; // FIXME later!
    //this.__modality.style.height = '100%';
    this.__modality.style.height = getDocHeight() + 'px';
    

    //this.__modality.style.height = (ScreenUtils.getHeight() + ScreenUtils.getScrollTop()) + 'px';
    //alert(Math.round(ScreenUtils.getHeight() / 2 + ScreenUtils.getScrollTop()) + 'px');
    this.modalDiv.style.top = t + 'px';
    this.modalDiv.style.left = l + 'px';
    this.modalDiv.style.display = 'block';
    //this.modalDiv.style.top = Math.round(ScreenUtils.getHeight() / 2 + ScreenUtils.getScrollTop() - this.modalDiv.scrollHeight/4) + 'px';
    //alert(this.modalDiv.scrollHeight);
    return this;
  },
  hide: function() {
    this.hidden = true;
    this.__modality.style.width = '0px';
    this.__modality.style.height = '0px';
    this.modalDiv.style.display = 'none';
    return this;
  },
  setHidden: function(hidden) {
    return hidden ? this.hide() : this.show();
  },
  isHidden: function() {
    return this.hidden || false
  }
};

//Размер документа по вертикали
function getDocHeight()
{
	return (document.documentElement.scrollHeight > document.documentElement.offsetHeight)?document.documentElement.scrollHeight:document.documentElement.offsetHeight;
}

//Размер документа по горизонтали
function getDocWidth()
{
	return (document.documentElement.scrollWidth > document.documentElement.offsetWidth)?document.documentElement.scrollWidth:document.documentElement.offsetWidth;
}


