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 > 690) {
  	  $('bodyTag').style.overflow = 'hidden';
  	  newTop = (WinHeight - 690) / 2;
    } else {
      $('bodyTag').style.overflow = 'auto';
      newTop = 20;
    }
    
    var tween = new Fx.Tween('content', { onComplete: function(){ 
    	moving = false; 
    } });
    
    tween.start('margin-top', newTop);
    
    
   // if ($('mbCenter')!=null) new Fx.Tween('mbCenter').start('top',(WinHeight-690)/2);
	
  }
}

function startHome(){
	getWinSize();
	frameHeight = (!document.all && document.getElementById) ? window.innerHeight : document.body.clientHeight;
  	if (WinHeight > 690) {
  	  $('bodyTag').style.overflow = 'hidden';
  	  newTop = (WinHeight - 690) / 2;
    } else {
      $('bodyTag').style.overflow = 'auto';
      newTop = 20;
    }
    
     $('wrapper').style.display = 'block';
    
  	moveDivs();
	
	
	
	if (page=="contatti")
	document.SCHEDA.AZIENDA.focus();
	
	if (page=='home')
	{
		var myGallery = new gallery($('gallery'), {
			timed: true
		});
	$$('li.Tips1').each(function(element,index) { 
	var content = element.get('title').split('#'); 
	element.store('tip:title', content[0]); 
	element.store('tip:text', content[1]);  
	}); 
	var Tips1 = new Tips($$('.Tips1'),{className : 'tipztop'});
	
	}
	
	if (page == "news" && aprilink) {
		setTimeout("mostralight()", 100);
	}

}

function mostralight()
{
	Mediabox.open(linkURL, 'news', '');
}

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.addEvent('domready', startHome);
//window.onload = startHome;
window.addEvent('resize', moveDivs);

