Position.includeScrollOffsets = true;
var lh = 0;
var url = '';
var timerID;
var isPlaying = 'false';

var Engine = {
  detect: function() {
    var UA = navigator.userAgent;
    this.isKHTML = /Konqueror|Safari|KHTML/.test(UA);
    this.isGecko = (/Gecko/.test(UA) && !this.isKHTML);
    this.isOpera = /Opera/.test(UA);
    this.isMSIE  = (/MSIE/.test(UA) && !this.isOpera);
    this.isMSIE7 = this.isMSIE && !(/MSIE 6\./.test(UA) && !this.isOpera);
    this.isMSIE6 = this.isMSIE && !this.isMSIE7;
  }
}
Engine.detect();

Position.getPageSize = function() {
  var xScroll, yScroll;

  if (window.scrollMaxX) {  
    xScroll = window.innerWidth  + window.scrollMaxX;
    yScroll = window.innerHeight + window.scrollMaxY;
  } else {
    xScroll = document.body.scrollWidth;
    yScroll = document.body.scrollHeight;
  } 
  
  var windowWidth, windowHeight;
  if (self.innerHeight) { // all except Explorer
    windowWidth = self.innerWidth;
    windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
    windowWidth = document.documentElement.clientWidth;
    windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
    windowWidth = document.body.clientWidth;
    windowHeight = document.body.clientHeight;
  }
  // for small pages with total height less then height of the viewport
  pageHeight = Math.max(windowHeight, yScroll);

  // for small pages with total width less then width of the viewport
  pageWidth = Math.max(windowWidth, xScroll);

  return { page: { width: pageWidth, height: pageHeight }, window: { width: windowWidth, height: windowHeight } };
}

function showBody() {
//    new Effect.Parallel( [
        new Effect.Appear('go2home', {duration: 2.0});
        new Effect.BlindDown('barra', {duration: 3.0});
        new Effect.SlideDown('corpo', {duration: 4.0, scaleX: true, afterFinish: 
          function(effect) { 
            $$('a.home_link').each(function(el){
              Effect.Appear(el.id);
            });
            $('loghetto2').show(); 
            new Effect.Pulsate('loghetto2'); 
            new Effect.Appear('ombra'); 
            new Effect.Appear('footer');
          }
        });
//        { duration: 4, afterFinish: function(effect) { $('loghetto2').show(); new Effect.Pulsate('loghetto2'); } }
//    );
}

function highlight(ann){
	if(lh==ann) return;
	lh = ann;
	new Effect.Opacity('img_corpo_'+ann,{duration:1.0,from:0.0});
}

function doRedirect() {
    window.clearInterval(timerID);
    document.location = url;
}

function loadPage(num) {
    var urls = ['presentazione.php','galleria.php','scatti.php','teatrale.php','album.php','referenze.php'];
    url = urls[num-1];
    /*
	$$('li').each(function(el){
        el.removeClassName('current');
    });
	*/
    $('menu_item_'+num).addClassName('current');
    $('pagina').update('<img src="images/loading.gif" alt="Caricamento in corso..." />');
    timerID = window.setTimeout("doRedirect()", 3000);
}

function goToPage(num) {
    $$('a.home_link').each(function(el){
        Effect.Squish(el.id);
    });
    
    $$('a.home_link_hover').each(function(el){
        Effect.Squish(el.id);
    });

    $$('div.div_img_corpo').each(function(el){
        Effect.Squish(el.id, {duration: 1.5});
    });

    $('menu').show();

    $('bottom_home').hide();

    $('corpo').setStyle({
      width: '781px',
      background: 'url(img/copertina/background_2.jpg) no-repeat',
      position: 'relative',
      top: '46px'
    });
   
    new Effect.Parallel( [
        new Effect.Morph('menu',{style:'width: 181px;'}),
        new Effect.Morph('corpo',{style:'width: 600px;'})
     
        ], { duration: 3.0, afterFinish: function(effect) { new Effect.BlindDown('navcontainer'); new Effect.Appear('go2home'); loadPage(num); }}
    );
}
