var WinWidth;
var WinHeight

function getWinSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    WinWidth = window.innerWidth;
    WinHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    WinWidth = document.documentElement.clientWidth;
    WinHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    WinWidth = document.body.clientWidth;
    WinHeight = document.body.clientHeight;
  }
}

var moving = false;
var newTop;

function moveDivs(){
  if (!moving) {
    getWinSize();
    moving = true;
  	frameHeight = (!document.all && document.getElementById) ? window.innerHeight : document.body.clientHeight;
  	if (WinHeight > 600) {
  	  $('bodyTag').style.overflow = 'hidden';
  	  newTop = (WinHeight - 560) / 2;
    } else {
      $('bodyTag').style.overflow = 'auto';
      newTop = 20;
    }
    var tween = new Fx.Tween('content', { onComplete: function(){ 
    	moving = false; 
    } });
    tween.start('margin-top', newTop);
    new Fx.Tween('mbCenter').start('top',(WinHeight-560)/2);
  }
}

function startHome(){
	getWinSize();
	frameHeight = (!document.all && document.getElementById) ? window.innerHeight : document.body.clientHeight;
  	if (WinHeight > 600) {
  	  $('bodyTag').style.overflow = 'hidden';
  	  newTop = (WinHeight - 560) / 2;
    } else {
      $('bodyTag').style.overflow = 'auto';
      newTop = 20;
    }
    
    // var tween = new Fx.Tween('content', { onComplete: function(){ 
    //  moving = false; 
    //  if(page=='home' || page=='home-en'){ 
    //        $('pellicola').fade('out');
    //      } else { 
    //        $('pellicola').fade('out');
    //      }
    // } });
    // tween.start('margin-top', newTop);
    
    $('content').style.marginTop = newTop + "px";
    
    window.onload = function(){
      if(page=='home' || page=='home-en'){ 
        $('pellicola').fade('out');
      } else {
        $('pellicola').style.display = "none";
        // $('pellicola').fade('out');
      }
    }
}

function setCookie(sNome, sValore, iGiorni) {
  var dtOggi = new Date()
  var dtExpires = new Date()
  dtExpires.setTime
    (dtOggi.getTime() + 24 * iGiorni * 3600000)
  document.cookie = sNome + "=" + escape(sValore) +
    "; expires=" + dtExpires.toGMTString();
}

// restituisce il valore del cookie sNome

function getCookie(sNome) {
  // genera un array di coppie "Nome = Valore"
  // NOTA: i cookies sono separati da ';'
  var asCookies = document.cookie.split("; ");
  // ciclo su tutti i cookies
  for (var iCnt = 0; iCnt < asCookies.length; iCnt++)
  {
    // leggo singolo cookie "Nome = Valore"
    var asCookie = asCookies[iCnt].split("=");
    if (sNome == asCookie[0]) { 
      return (unescape(asCookie[1]));
    }
  }

  // SE non esiste il cookie richiesto
  return("");
}

// rimuove un cookie
function delCookie(sNome) {
  setCookie(sNome, "");
}

// window.onload = startHome;
window.addEvent('resize', moveDivs);
