//$$Revision: 3 $
//$$Workfile: image-gallery.js $

// set the starting image.
var i = 0;			

// The number of images in the array.
var NumOfImages = $$('div.fade-box').length;

// The time to wait before moving to the next image. Set to 5 seconds by default.
var wait = 5000;

// The Fade Function
function SwapImage(x,y) {		
	$($$('div.fade-box')[x].id).appear({ duration: 1.5 });
	$($$('div.fade-box')[y].id).fade({duration: 1.5});
}

// the onload event handler that starts the fading.
function StartSlideShow() {
    NumOfImages = $$('div.fade-box').length;
    if (NumOfImages > 0)
    {
        play = setInterval('Play()',wait);
        //$('PlayButton').hide();
        //$('PauseButton').appear({ duration: 0});
		//updatecounter();
    }
}

function Play() {
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	try{
        if (imageShow == NumOfImages) {
            SwapImage(0,imageHide);	
            i = 0;					
        } else {
            SwapImage(imageShow,imageHide);			
            i++;
        }
        var textIn = i+1 + ' of ' + NumOfImages;
	}
	catch(err){}
	//updatecounter();
}

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++;
	}

	updatecounter();
}

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)
	}
	
	updatecounter();
}

function updatecounter() {
	var textIn = i+1 + ' of ' + NumOfImages;
	document.getElementById('Counter').innerHTML = textIn;
}
