
// set the starting image.
var i = 0;			

// The array of div names which will hold the images.
//var image_slide = new Array('image-1', 'image-2');
var image_slide;
// The number of images in the array.
var NumOfImages;

/*function initSlides(arrayElements, numElements) {
	alert(numElements);
	image_slide = arrayElements;
	NumOfImages = numElements;
}*/
	
// The time to wait before moving to the next image. Set to 4 seconds by default.
var wait = 16000;

// The Fade Function
function SwapImage(x,y) {
	var imageSlideX = $(image_slide[x]);
	var imageSlideY = $(image_slide[y]);	
	$(imageSlideX).appear({ duration: 0.5 });
	$(imageSlideY).fade({duration: 0.5});
	if($('notification-wrap').getHeight() >= $(image_slide[x]).getHeight()) {
		setTimeout("$('notification-wrap').style.height =  $(image_slide[" + x + "]).getHeight() + 'px'",500);	
	} else {
		$('notification-wrap').style.height =  $(image_slide[x]).getHeight() + 'px';		
	}
}

function updateDivHeight(imageSlide) {
	$('notification-wrap').style.height =  $(imageSlide).getHeight() + "px";
}

// the onload event handler that starts the fading.
function StartSlideShow(arrayElements, numElements) {
	image_slide = arrayElements;
	NumOfImages = numElements;
	
	play = setInterval('Play()',wait);
	//$('PlayButton').hide();
	//$('PauseButton').hide();
	
	updatecounter();
	
	$('notification-wrap').style.height =  $(image_slide[0]).getHeight() + 'px';
								
}

function Play() {
	var imageShow, imageHide;

	imageShow = i+1;
	imageHide = i;
	
	if (imageShow == NumOfImages) {
		SwapImage(0,imageHide);	
		i = 0;					
	} else {
		SwapImage(imageShow,imageHide);			
		i++;
	}
	
	var textIn = i+1 + ' of ' + NumOfImages;
	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;
}
