var totnews;
var counter;

function homenewsfade() {
   id1 = "mum"+counter;
   k = counter + 1;
   id2 = "mum"+k;
   if (counter < totnews){
     mostra($(id1),$(id2));
     counter = counter+2;
   }
   else{
     counter = 0;
   }
}
function homenewsfade2() {
	   id1 = "mum"+counter;
	   if (counter < totnews){
	     mostra2($(id1));
	     counter = counter+1;
	   }
	   else{
	     counter = 0;
	   }
	}

function MTFadeOpen (div) {
  div.setStyle('display','block');
  div.setStyle('opacity','0');
  new Fx.Style(div, 'opacity', {duration: 1500} ).start(1);
}
function MTFadeClose (div) {
    div.setStyle('display','none');
  }


function chiudituttiglialtri(n1,n2) {
  /* NASCONDI lentamente */
    $$('div[class=newshome]').each(function(el){
       if ((el != n1) || (el!=n2)){
         MTFadeClose(el);
       }
    })
  }
function chiudituttiglialtri2(n1) {
	  /* NASCONDI lentamente */
	    $$('div[class=newshome2]').each(function(el){
	       if (el != n1){
	         MTFadeClose(el);
	       }
	    })
	  }
function mostra(news1,news2) {
     /* nascondi gli altri */
     chiudituttiglialtri(news1,news2);
     /* MOSTRA lentamente */
     MTFadeOpen(news1);
     MTFadeOpen(news2);
 }
function mostra2(news1) {
    /* nascondi gli altri */
    chiudituttiglialtri2(news1);
    /* MOSTRA lentamente */
    MTFadeOpen(news1);
}
function contalenews(){
   totale = 0;
   $$('div[class^=newshome]').each(function(el){
      totale = totale + 1;
   });

  return totale;
}

window.addEvent('load', function() {
  totnews = contalenews();
  mill= totnews * 1500;
  counter = 0;
    if ( $$('.newshome')!='')   {
      homenewsfade();
      homenewsfade.periodical(mill);
    }
    if( $$('.newshome2')!=''){
        homenewsfade2();
        homenewsfade2.periodical(mill);
      }
});
