
// 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', 'image-3', 'image-4');

// 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 = 10000;

// The Fade Function
function SwapImage(x,y) {		
	$(image_slide[x]).appear({ duration: 1 });
	$(image_slide[y]).fade({duration: 2});
	ChangeNumImagen(x);		
}

// The Fade Function
function SwapImageNextPrev(x,y) {		
	$(image_slide[x]).appear({ duration: 0.25 });
	$(image_slide[y]).fade({duration: 0.25});
	ChangeNumImagen(x);		
}

// the onload event handler that starts the fading.
function StartSlideShow() {
	play = setInterval('Play()',wait);
	$('PlayButton').hide();
	$('PauseButton').appear({ duration: 0});	
	ChangeNumImagen(0);
}

function Reanudar(){
	play = setInterval('Play()',wait);
	$('PlayButton').hide();
	$('PauseButton').appear({ duration: 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) {
		SwapImageNextPrev(0,imageHide);	
		i = 0;					
	} else {
		SwapImageNextPrev(imageShow,imageHide);			
		i++;
	}
	
	ImpedirImagenColgada.delay(5, imageShow);
	
}

function GoPrevious() {
	clearInterval(play);
	$('PlayButton').appear({ duration: 0});
	$('PauseButton').hide();

	var imageShow, imageHide;
				
	imageShow = i-1;
	imageHide = i;
	
	if (i == 0) {
		SwapImageNextPrev(NumOfImages-1,imageHide);	
		i = NumOfImages-1;		
		
		//alert(NumOfImages-1 + ' and ' + imageHide + ' i=' + i)
					
	} else {
		SwapImageNextPrev(imageShow,imageHide);			
		i--;
		
		//alert(imageShow + ' and ' + imageHide)
	}

	ImpedirImagenColgada.delay(7.5, imageShow);
}

function ImpedirImagenColgada(z){
	
	cargaOK = false;	
	for(j=0;j<NumOfImages;j++){
		if(document.getElementById(image_slide[j]).style.display==''){
			cargaOK=true;
		}
	}

	if(!cargaOK){
		if($(image_slide[z])!=null){
			$(image_slide[z]).appear({ duration: 0.5 });
			ChangeNumImagen(z);
		}else{
			$(image_slide[1]).appear({ duration: 0.5 });
			ChangeNumImagen(0);
		}
		
	}

}

function SwapImageConcreta(x) {
	clearInterval(play);
	$('PlayButton').appear({ duration: 0});
	$('PauseButton').hide();
	
	if(document.getElementById(image_slide[x-1]).style.display=='none'){
		for(j=0;j<NumOfImages;j++){
			if(j+1!=x){
				$(image_slide[j]).fade({duration: 0.5});
			}
		}		
		$(image_slide[x-1]).appear({ duration: 0.5 });
	
		ImpedirImagenColgada.delay(5, x-1);
		ChangeNumImagen(x-1);
	}
}

function ChangeNumImagen(x){
	
	botonNum=x+1;
	botonStr='botonBanner'+botonNum;

	for(j=0;j<NumOfImages;j++){
		botonNum2=j+1;
		botonStr2='botonBanner'+ botonNum2;
		$(botonStr2).innerHTML='<img src="pages/img/slideshow/boton_B.gif" border="0" />';
	}
	$(botonStr).style.fontSize='54px';
	$(botonStr).innerHTML='<img src="pages/img/slideshow/boton_A.gif" border="0" />';
}

