var OverBox = {
  url:'',
  pointer:null,
  over:null,
  supr:null,
  object:null,
  width:400,
  height:300,
  off:25,
  enabled:false,
  init:function() {
    this.pointer = $P(this,true);
    this.over = $$('div').set('id','overlay').appendAsFirst(document.body);
    this.supr = $$('div').set('id','superlayer').appendTo(document.body).addClass('round');
    this.object = $$('div').set('id','container').appendTo(document.body).addClass('round');
    this.over.onclick = OverBox.close;
    return this;
  },
  show:function(data) {
    this.enabled = true;
    if(!this.over) this.init();
    var sz = Screen.pageSize(), sh = sz.h;
    var ps = Screen.pageScroll().y;
    if(/[%]/.test(data.width)) data.width = Math.ceil(parseInt(data.width.replace('%','')) * sz.w) / 100 ;
    if(/[%]/.test(data.height)) data.height = Math.ceil(parseInt(data.height.replace('%','')) * sz.h) / 100;
    $extend(this,data);
    this.over.css({height:(ps + sh - 2)+'px'}).show();
    this.supr.css({height:this.height+'px',width:this.width+'px'}).show();
    this.object.css({height:(this.height-this.off)+'px',width:(this.width-this.off)+'px'}).show();
    this.supr.center();
    this.object.center();
    if(this.url!='') new Ajax.Request({url:this.url,target:'container'});
    return this;
  },
  hide:function(){
    if(!this.enabled) return this;
    this.enabled = false;
    this.over.destroy();
    this.supr.destroy();
    this.object.destroy();
    this.over = null;
    this.supr = null;
    this.object = null;
    return this;
  },
  close:function(){
    OverBox.hide();
  }
};

window.onscroll = function() {
  if(!OverBox.enabled) return;
  var s = Screen.pageScroll().y;
  var e=$E('superlayer'),p=e.getCenter();
  e.setPosition(p.x,p.y);
  var e=$E('container'),p=e.getCenter();
  e.setPosition(p.x,p.y);
  var h = s + Screen.pageSize().h-2;
  $E('overlay').css({height:h+'px'});
}

function vendas_form(id) {
  OverBox.show({url:'/vendas-form.php?id='+id,width:500,height:300});
}

function contato_form() {
  OverBox.show({url:'/contato-form.php',width:500,height:400});
}

function receita_mais(id) {
  OverBox.show({url:'/receitas-zoom.php?id='+id,width:'80%',height:400});
  return false;
}

function receita_imprimir(id) {
  window.open('/receitas-imprimir.php?id='+id,'_blank');
}

function receita_outra(id) {
  Ajax.Request({url:'/receitas-zoom.php?id='+id,target:'container'});
}

function forgot() {
  OverBox.show({url:'/passwd-reset.php',width:500,height:300});
  return false;
}
