// Global variables
var numslides=0;
var currentslide=0,oldslide=2;
var x = 0;
var slides = new Array();
var currentRotation = 0;
var checkSum = 1;
var timer = 4000;
function MakeSlideShow() {
   // find all images with the class "slide"
   imgs=dojo.query(".slide"); //document.getElementsByTagName("div");
   for (i=0; i<imgs.length; i++) {
      if (imgs[i].className != "slide") continue;
      slides[numslides]=imgs[i];
      // stack images with first slide on top
      if (numslides==0) {
         imgs[i].style.zIndex=10;
      } else {
         imgs[i].style.zIndex=0;
      }
	  //dojo.connect(imgs[i], "onclick", null, NextSlide); 
      //imgs[i].onclick=NextSlide(numslides);
      numslides++;
   } // end for loop
   //alert("currentslide=" + currentslide + ":oldslide=" + oldslide);
   currentRotation = 1;
   window.setTimeout("RotateSlide();",timer);
} // end MakeSlideShow()

function NextSlide() {
   //alert("in--currentslide=" + currentslide + ":oldslide=" + oldslide);
   // Set current slide to be under the new top slide
   slides[currentslide].style.zIndex=9;
   // Move older slide to the bottom of the stack
   slides[oldslide].style.zIndex=0;
   oldslide = currentslide;
   currentslide = oldslide+1;
   if (currentslide >= numslides) currentslide = 0;
   // start at the right edge
   //slides[currentslide].style.left=400;
   x=400;
   // Move the new slide to the top
   slides[currentslide].style.zIndex=10;
   //alert("out--currentslide=" + currentslide + ":oldslide=" + oldslide);
   AnimateSlide();
   window.setTimeout("RotateSlide();",timer);
}
function AnimateSlide() {
		//dojo.style(slides[oldslide], "opacity", "0");
		var fadeArgs = {
          node: slides[oldslide]
        };
        dojo.fadeOut(fadeArgs).play();
        dojo.style(slides[currentslide], "opacity", "0");
        fadeArgs = {
          node: slides[currentslide]
        };
        dojo.fadeIn(fadeArgs).play();
}


function ContinueRotate(){
	currentRotation = 1;
	RotateSlide();
}
function RotateSlide(){
	if(currentRotation == 1){
	    //checkSum = 0;
		NextSlide();
	}
}
// create the slideshow when the page loads
dojo.addOnLoad(MakeSlideShow);

