var slides; var slideImg, slideCap, slideContainer1, slideContainer2, currSlide, otherSlide, slideNum, debugDiv, preImage; var animInt; var speed = 50; var opInt = 0.05; var topSlide = 1; var opacity = 1; var animInt; var pauseCounter = 0; var slidePause = 10000; function load(slidesArr) { slides = slidesArr; slideContainer1 = document.getElementById("image1"); slideContainer2 = document.getElementById("image2"); //debugDiv = document.getElementById("debug"); slideContainer1.style.opacity = 1; currSlide = slideContainer1; otherSlide = slideContainer2; //alert(slideContainer.style.opacity); animInt = setInterval(fade, speed); slideNum = 0; //alert(slideNum); } function fade() { //alert("fading"); nextSlide = slideNum + 1; if (nextSlide >= slides.length) { nextSlide = 0; } if ((pauseCounter >= slidePause) && (slides[nextSlide][2])) { newOpacity = opacity - opInt; if (newOpacity > 0) { currSlide.style.opacity = newOpacity; opacity = newOpacity; } else { currSlide.style.opacity = 0; if (topSlide == 1) { slideContainer2.style.zIndex = 2; slideContainer1.style.zIndex = 1; slideContainer1.style.opacity = 1; currSlide = slideContainer2; otherSlide = slideContainer1; topSlide = 2; } else { slideContainer1.style.zIndex = 2; slideContainer2.style.zIndex = 1; slideContainer2.style.opacity = 1; currSlide = slideContainer1; otherSlide = slideContainer2; topSlide = 1; } otherSlide.innerHTML = "\"\"
" + slides[nextSlide][1] + "
"; slideNum += 1; if (slideNum >= slides.length) { slideNum = 0; } //debugDiv.innerHTML = "

currSlide: " + slideNum + "

" + "

nextSlide: " + nextSlide + "

"; pauseCounter = 0; opacity = 1; //clearInterval(animInt); } } else { if (!slides[nextSlide][2]) { //debugDiv.innerHTML = "

LOADING " + slides[nextSlide][0] + "
SlideNum:" + nextSlide + "

"; if (!slides[nextSlide][3]) { preImage = new Image(); preImage.src = slides[nextSlide][0]; slides[nextSlide][3] = true; } else { if (isImageOk(preImage)) { slides[nextSlide][2] = true; otherSlide.innerHTML = "\"\"
" + slides[nextSlide][1] + "
"; } else { slides[nextSlide][2] = false; } } } pauseCounter += speed; } } function isImageOk(img) { if (!img.complete) { return false; } if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) { return false; } return true; }