// Declare required variables var fadeTimer = false; var fadeSpeed = 75; var fadeImgInterval = 2000; var fadeImgArray = new Array(); var fadeImgCounter = 1; var prevImgCounter = 0; /** * Unfade the current image and fade the next image in the global array fadeImgArray. * * @param int transparentValue defines the css alpha transparency value for the current image */ function fadeImage(transparencyValue) { // Stop the current fade timer stopFader(); var prevObj = DHTMLObj(fadeImgArray[prevImgCounter]); var obj = DHTMLObj(fadeImgArray[fadeImgCounter]); if (obj && prevObj) { obj.className = 'updateImgTransparency_' + transparencyValue; prevObj.className = 'updateImgTransparency_' + (100-transparencyValue); } // Increase the transparency value transparencyValue += 20; if (transparencyValue <= 100) { fadeTimer = setTimeout("fadeImage(" + transparencyValue + ")",fadeSpeed); } else { // Increase the counter prevImgCounter = fadeImgCounter; fadeImgCounter = (fadeImgCounter >= fadeImgArray.length -1) ? 0 : fadeImgCounter + 1; // Start a timer for the next fade fadeTimer = setTimeout("fadeImage(0)",fadeImgInterval); } } /** * Load the image array with images to use in the fade */ function loadImageArray() { for (i=0; i<8; i++) { fadeImgArray[i] = 'img_fader_' + i; } } /** * Start the fader that will loop through all images given in the global array fadeImgArray. */ function startFader() { loadImageArray(); fadeTimer = setTimeout("fadeImage(0)",fadeImgInterval); } /** * Stop the fader by clearing the fader timeout */ function stopFader() { // Clear the old timeout to avoid multiple fades if (fadeTimer) { clearTimeout(fadeTimer); } }