/*
Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com
Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html
*/
function so_connect(fid)
{
    window.addEventListener?window.addEventListener('load',function(){so_init(fid)},false):window.attachEvent('onload',function(){so_init(fid)});
}
var d=document, imgs = new Array(), zInterval = null, current=0, pause=false;
function so_init(fid)
{
    if(!d.getElementById || !d.createElement)return;
    css = d.createElement('link');
    css.setAttribute('href','js/slideshow.css');
    css.setAttribute('rel','stylesheet');
    css.setAttribute('type','text/css');
    d.getElementsByTagName('head')[0].appendChild(css);
    imgs[fid] = d.getElementById('themeSlideshow'+fid.toString()).getElementsByTagName('img');
    for(i=1;i<imgs[fid].length;i++) imgs[fid][i].xOpacity = 0;
    imgs[fid][0].style.display = 'block';
    imgs[fid][0].xOpacity = .99;
    setTimeout(function(){so_xfade(fid)},3000);
}
function so_xfade(fid)
{
    cOpacity = imgs[fid][current].xOpacity;
    nIndex = imgs[fid][current+1]?current+1:0;
    nOpacity = imgs[fid][nIndex].xOpacity;
    cOpacity-=.05;
    nOpacity+=.05;
    imgs[fid][nIndex].style.display = 'block';
    imgs[fid][current].xOpacity = cOpacity;
    imgs[fid][nIndex].xOpacity = nOpacity;
    setOpacity(imgs[fid][current]);
    setOpacity(imgs[fid][nIndex]);
    if(cOpacity<=0)
    {
        imgs[fid][current].style.display = 'none';
        current = nIndex;
        setTimeout(function(){so_xfade(fid)},9000); <!-- velocità di rotazione più il valore è alto e più lenta è la rotazione -->
    }
    else
    {
        setTimeout(function(){so_xfade(fid)},50);
    }
    function setOpacity(obj)
    {
        if(obj.xOpacity>.99)
        {
            obj.xOpacity = .99;
            return;
        }
        obj.style.opacity = obj.xOpacity;
        obj.style.MozOpacity = obj.xOpacity;
        obj.style.filter = 'alpha(opacity=' + (obj.xOpacity*100) + ')';
    }
}