/* This script and many more are available free online at
The JavaScript Source!! http://javascript.internet.com
Created by: Fang | http://www.webdeveloper.com/forum/showthread.php?t=191419Licensed under: Public Domain
 */

function postNews(nome) {
  aLI=document.getElementById(nome).getElementsByTagName('li');
  for(var i=0; i<aLI.length; i++)  {
    aLI[i].style.display="none";
    aLI[i].getElementsByTagName('p')[0];
  }    
  rotate(aLI.length-1);
};

function postNews2(nome) {
  aLI2=document.getElementById(nome).getElementsByTagName('li');  
  for(var j=0; j<aLI2.length; j++)  {
    aLI2[j].style.display="none";
    aLI2[j].getElementsByTagName('p')[0];
  }  
  rotate2(aLI2.length-1);
};

function postNews3(nome) {
  aLI3=document.getElementById(nome).getElementsByTagName('li');  
  for(var k=0; k<aLI3.length; k++)  {
    aLI3[k].style.display="none";
    aLI3[k].getElementsByTagName('p')[0];
  }  
  FadeOpacity(nome, 100, 0, 1000, 8);
  rotate2(aLI2.length-1);
  FadeOpacity(nome, 0, 100, 1000, 8);
};



var aLI=[];
var aLI2=[];
var aLI3=[];
var timerRUN=null;
var timerRUN2=null;
var timerRUN3=null;
var Speed=3000; // change as required
var Speed2=2000; // change as required
var Speed3=3000; // change as required

function rotate(idx) {
  aLI[idx].style.display="none";
  idx=(idx<aLI.length-1)? ++idx : 0;
  aLI[idx].style.display="block";
  timerRUN=setTimeout('rotate('+idx+')', Speed);
  FadeOpacity('news', 1, 100, 1000, 8);
}
function rotate2(idx2) {
  aLI2[idx2].style.display="none";
  idx2=(idx2<aLI2.length-1)? ++idx2 : 0;
  aLI2[idx2].style.display="block";
  timerRUN2=setTimeout('rotate2('+idx2+')', Speed2);
}
function rotate3(idx3) {
  aLI2[idx3].style.display="none";
  idx3=(idx3<aLI3.length-1)? ++idx3 : 0;
  aLI3[idx3].style.display="block";
  timerRUN3=setTimeout('rotate3('+idx3+')', Speed3);
}

function SetOpacity(elem, opacityAsInt)
{
	var opacityAsDecimal = opacityAsInt;
	
	if (opacityAsInt > 100)
		opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
		opacityAsInt = opacityAsDecimal = 0; 
	
	opacityAsDecimal /= 100;
	if (opacityAsInt < 1)
		opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
		
	elem.style.filter='progid:DXImageTransform.Microsoft.Alpha(Opacity=' + opacityAsDecimal + ')';	
	elem.style.opacity = opacityAsDecimal;
	elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";

}
function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
	var steps = Math.ceil(fps * (time / 1000));
	var delta = (toOpacity - fromOpacity) / steps;
	FadeOpacityStep(elemId, 0, steps, fromOpacity, delta, (time / steps));
}
function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
    SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));
    if (stepNum < steps)
        setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}

function inView() {
  var newsItem=0;
  for(var i=0; i<aLI.length; i++) {
    if(aLI[i].style.display=="block") {newsItem= i;}
  }
  return newsItem;
}

// Multiple onload function created by: Simon Willison
// http://simonwillison.net/2004/May/26/addLoadEvent/
function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  postNews('news');
  postNews2('referenze');
});


