var larghezza = 0;
var t = 1.1;
var width = 400;
var height = 520;
var delay = 12000;
var x = 0;
var y = 0;
var w = 0;
var h = 0;
var cntx = 0;
var cnty = 0;

function popUp() {

  if (document.all) {
    x = window.screenLeft;
    y = window.screenTop;
    w = window.document.body.offsetWidth;
    h = window.document.body.offsetHeight;
  }
  else {
    x = window.screenX;
    y = window.screenY;
    w = window.outerWidth;
    h = window.outerHeight;
  }
  cntx = x + Math.round((w - width) / 2);
  cnty = y + Math.round((h - height) / 2)-100;
  document.getElementById('popup').style.height=height+'px';
  document.getElementById('popup').style.top=cnty+'px';
  //document.getElementById('popup').style.left=cntx+'px';
  document.getElementById('popup').style.visibility='visible';
  //window.setTimeout("cambiaPopUp()", 4000);
  //window.setTimeout("chiudiPopUp()", delay);
  for(i=0;i<10;i++)
  {
  mydelay=i*100;
  window.setTimeout("allarga("+i+")", mydelay);
  }
}

function allarga(ciclo) {
  t*=1.35;
  larghezza = t * t;
  
  document.getElementById('popup').style.width=larghezza+'px';
  if(larghezza>400) {
    document.getElementById('popup').style.width=400+'px';
  }
  mystring=document.getElementById('popup').style.width;
  leftstring=mystring.substr(0,3);
  
  if(larghezza>400) {
    cntx = x + Math.round((w - 400) / 2);
    document.getElementById('popup').style.left=cntx+'px';
  }
  else
  {
    cntx = x + Math.round((w - larghezza) / 2);
    document.getElementById('popup').style.left=cntx+'px';
  }
  if(ciclo==9)
  {
    document.getElementById('chiudi_popup').style.visibility='visible';
    document.getElementById('corpo_popup').style.visibility='visible';
  }
  
}
function cambiaPopUp() {
  document.getElementById('img_popup').src='promosv.jpg';
  //alert(document.getElementById('img_popup').src);
}
function chiudiPopUp() {
  document.getElementById('popup').style.visibility='hidden';
  document.getElementById('chiudi_popup').style.visibility='hidden';
  document.getElementById('corpo_popup').style.visibility='hidden';
  document.getElementById('bg').style.visibility='hidden';
}