var CMHTMLBLOCKcurrPag = new Array();
function RefreshBlocco(idblocco,npag,tout,EffettoFadeInOut,TempoEffettoFadeInOut) {
    if(CMHTMLBLOCKcurrPag[idblocco] == null)
        CMHTMLBLOCKcurrPag[idblocco] = 1;
    var myChain = null;
    if(EffettoFadeInOut)
        myChain = new Chain();
    var myEffectOut = null;
    var myEffectIn = null;
    var oPagOut = null;
    for(var i=0; i<npag; i++) {
        var oPag = document.getElementById(idblocco + i);
        if(EffettoFadeInOut) {
            if(oPag.style.display != "none") {
                // effetto fade-out
                oPagOut = oPag;
                myEffectOut = new Fx.Morph(idblocco + i, {onComplete: function() { myChain.callChain(); }, duration: parseInt(TempoEffettoFadeInOut,10), transition: Fx.Transitions.Sine.easeOut});
            } else {
                oPag.style.display = "none";
                var myFx = new Fx.Tween(oPag);
                myFx.set("opacity",0);   
            }                
        } else if(oPag.style.display != "none")
            oPag.style.display = "none";
    }
    
    var oPagShow = document.getElementById(idblocco + CMHTMLBLOCKcurrPag[idblocco]);
    
    if(EffettoFadeInOut) {
        // effetto fade-in
        myEffectIn = new Fx.Morph(idblocco + CMHTMLBLOCKcurrPag[idblocco], {onComplete: function() { myChain.callChain(); },duration: parseInt(TempoEffettoFadeInOut,10), transition: Fx.Transitions.Sine.easeIn});
        
        if(myEffectOut) {
            myChain.chain(
                function() { myEffectOut.start({ 'opacity': [1, 0] }); },
                function() { oPagOut.style.display = "none"; this.callChain(); },
                function() { oPagShow.style.display = "block"; this.callChain(); },
                function() { myEffectIn.start({ 'opacity': [0, 1] }); }
                );
        } else {
            myChain.chain(
                function() { oPagShow.style.display = "block"; this.callChain(); },
                function() { myEffectIn.start({ 'opacity': [0, 1] }); }
                );
        }
        myChain.callChain();
    } else
        oPagShow.style.display = "block";
    
    if(CMHTMLBLOCKcurrPag[idblocco] >= npag - 1)
        CMHTMLBLOCKcurrPag[idblocco] = 0;
    else
        CMHTMLBLOCKcurrPag[idblocco]++;
    setTimeout("RefreshBlocco('" + idblocco + "'," + npag + "," + tout + "," + EffettoFadeInOut + "," + TempoEffettoFadeInOut + ");",tout);
}
