
// set the starting image.
var i = 0;			

// The array of div names which will hold the images.
var image_slide = new Array();

// The number of images in the array.
var NumOfImages = 0;
	
// The time to wait before moving to the next image. Set to 4 seconds by default.
var wait = 12000;

var botonPlay = null;
var botonPause = null;
var divContador = null;
var idLink = "";
var contenedorLink = "";
var cssActivo = "";
var cssInactivo = "";

// The Fade Function
function SwapImage(x,y) {		
	$(image_slide[x]).appear({ duration: 0.5 });
	$(image_slide[y]).fade({duration: 0.5});
	
	cambiarEstilos($(idLink+x));
	
}

// the onload event handler that starts the fading.
function StartSlideShow(listaDivs,idLinks,idPlay,idPause,divCont,idContenedor,classActivo,classInactivo) {
	
	image_slide = listaDivs.split(';');
	NumOfImages = image_slide.length;
	botonPlay 	= $(idPlay);
	botonPause 	= $(idPause);
	divContador = $(divCont);
	idLink 		= idLinks;
	contenedorLink = idContenedor;
	cssActivo 	= classActivo;
	cssInactivo = classInactivo;

	play = setInterval('Play()',wait);
	
	botonPlay.hide();
	botonPause.appear({ duration: 0});
	
	updatecounter();
								
}

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);				
	botonPlay.appear({ duration: 0});
	botonPause.hide();
}

function GoNext() {
	clearInterval(play);
	botonPlay.appear({ duration: 0});
	botonPause.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);
	botonPlay.appear({ duration: 0});
	botonPause.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;
	divContador.innerHTML = textIn;
}

function cambiarEstilos(vinc){				//Cambia el estilo de los lnks

	$$('#'+contenedorLink+' a').each(function(check) { 
			//alert(check);
			check.className = cssInactivo;
		});
	vinc.className = cssActivo;

}

function GoPage(num_pag, detener) {
	
	clearInterval(play);
	botonPlay.appear({ duration: 0});
	botonPause.hide();	
	
	var imageShow, imageHide;

	imageShow = num_pag;
	imageHide = i;
	
	if (num_pag != i){
		SwapImage(num_pag,imageHide);	
		i = num_pag;
	}
	updatecounter();
	
}
