
// set the starting image.
var play;

// The array of div names which will hold the images.

var image_slide = new Array();
var image_slide2 = new Array();
var image_slide3 = new Array();

var j = 0;

$$('div.fade-box').each(function(s) {
    image_slide.push('image-' + j);
    j++;
    //alert($(s.id));
    });

j = 0;

$$('div.fade-box2').each(function(s) {
    image_slide2.push('image2-' + j);
        j++;
	    //alert($(s.id));
});

j = 0;

$$('div.fade-box3').each(function(s) {
    image_slide3.push('image3-' + j);
        j++;
	    //alert($(s.id));
});



// The number of images in the array.
var NumOfImages = image_slide.length;

// The time to wait before moving to the next image. Set to 3 seconds by default.
var wait = 2000;

// The Fade Function
function SwapImage(x,y) {	
        $(image_slide[x]).appear({ duration: 1.5 });
	$(image_slide[y]).fade({duration: 1.5});
	$(image_slide2[x]).appear({ duration: 1.5 });
	$(image_slide2[y]).fade({duration: 1.5});
	$(image_slide3[x]).appear({ duration: 1.5 });
	$(image_slide3[y]).fade({duration: 1.5});


}

function SwapImage2(x) {
        clearInterval(play);
        //$('PlayButton').appear({ duration: 0});
	//$('PauseButton').hide();
        	
        $(image_slide[x]).appear({ duration: 1.5 });
	$(image_slide[i]).fade({duration: 1.5});
	$(image_slide2[x]).appear({ duration: 1.5 });
	$(image_slide2[i]).fade({duration: 1.5});
	$(image_slide3[x]).appear({ duration: 1.5 });
	$(image_slide3[i]).fade({duration: 1.5});
        i = x;
}

// the onload event handler that starts the fading.
function StartSlideShow() {
	play = setInterval('Play()',wait);
	//$('PlayButton').hide();
	//$('PauseButton').appear({ duration: 0});
}        
        

var i = 0;

function Play() {
	var imageShow, imageHide;

        imageShow = i+1;
	imageHide = i;
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
}

function Stop () {
	clearInterval(play);				
	//$('PlayButton').appear({ duration: 0});
	//$('PauseButton').hide();
}

function GoNext() {
        clearInterval(play);
        //$('PlayButton').appear({ duration: 0});
	//$('PauseButton').hide();
        var imageShow, imageHide;
        imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
        	SwapImage(0,imageHide);	
		i = 0;					
	} else {
        	SwapImage(imageShow,imageHide);			
		i++;
	}
}

function GoPrevious() {
	clearInterval(play);
        //$('PlayButton').appear({ duration: 0});
	//$('PauseButton').hide();
        var imageShow, imageHide;
				
	imageShow = i-1;
	imageHide = i;
	
	if (i == 0) {
		SwapImage(NumOfImages-1,imageHide);	
		i = NumOfImages-1;		
		//alert(NumOfImages-1 + ' and ' + imageHide + ' i=' + i)
	} else {
		SwapImage(imageShow,imageHide);			
		i--;
		//alert(imageShow + ' and ' + imageHide)
	}
}

