/*
	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
*/

window.addEventListener?window.addEventListener('load',so_init,false):window.attachEvent('onload',so_init);


function so_init()
{
    prepareSlideShow('rotator',5000);
}

var slideshow_imgs = new Array(), playing, timeToView;

function prepareSlideShow(sDivToUse,ViewTime)
{

	if(!document.getElementById || !document.createElement)return;

	css = document.createElement('link');
	css.setAttribute('href','slideshow.css');
	css.setAttribute('rel','stylesheet');
	css.setAttribute('type','text/css');
	document.getElementsByTagName('head')[0].appendChild(css);

    // Retrieve graphics pictures
	slideshow_imgs = document.getElementById(sDivToUse).getElementsByTagName('img');

    // See if we have something to do
    if (slideshow_imgs.length == 0) return;
    
    // Setup timer
    timeToView = ViewTime;   // Time in miliseconds for showing the image
    
    // Prepare state machine
    playing = 0;    // Current image on play

    // Make all images invisible
	for(i=1;i<slideshow_imgs.length;i++) slideshow_imgs[i].style.display = 'none';

   
    setTimeout(runSlideShow,timeToView);
}

function runSlideShow()
{
    Effect.Fade  (slideshow_imgs[playing],{ queue: {position: 'end', scope: 'masterpage'} });
    playing++;
    if (playing == slideshow_imgs.length) playing = 0;
    Effect.Appear(slideshow_imgs[playing],{ queue: {position: 'end', scope: 'masterpage'} });
    setTimeout(runSlideShow,timeToView);        
}


