var imagenActual = 0;
var totalImagenes;
var intervaloImagenes;
var tiempoEspera= 8;  // Tiempo de espera entre casos expresado en SEGUNDOS
var tiempoFundido = 150; // Tiempo de fundido de los casos expresado en MILISEGUNDOS

$(document).ready(function() {

    // CARRUSEL TRABAJOS
    totalImagenes = $("#picMask img").length;
    // Solo se hace el efecto si hay más de una imagen
    if (totalImagenes != 1) {
        $("#picMask").removeClass("oculto");
        $("#picMask img").hide();
        $("#picMask img:first").show();
        clearInterval(intervaloImagenes);
        intervaloImagenes = setInterval(carruselImagenes, tiempoEspera * 1000);
    }

    // BOTONES NÚMERO DE IMAGEN CARRUSEL TRABAJOS
    //$("#picNum li a").stop().click(controlCarrusel);
    // DECORA
    //$("#picNum li a:first").addClass("actual").css("cursor", "text");
})




// FUNCIONES BOTONES CARRUSEL TRABAJOS

function controlCarrusel(){
	imagenActual =  $("#picNum li a").index($(this));
		// DECORA
		//$(this).addClass("actual").css("cursor", "text");
	carruselImagenes();
	return false;
}



// FUNCIONES CARRUSEL AUTOMÁTICO TRABAJOS

function carruselImagenes(){
	clearInterval(intervaloImagenes);
	$("#picMask img:eq("+imagenActual+")").fadeOut(tiempoFundido, muestraNuevaFoto)
	if (imagenActual<totalImagenes-1){
		imagenActual++;
	}else{
		imagenActual=0;
	}
}

function muestraNuevaFoto(){
	$("#picMask img").hide();
	$("#picMask img:eq("+imagenActual+")").fadeIn(tiempoFundido, function (){intervaloImagenes = setInterval(carruselImagenes, tiempoEspera*1000); });
	// DECORA
	//$("#picNum li a").removeClass("actual").css("cursor", "pointer");
	//$("#picNum li a:eq("+imagenActual+")").addClass("actual").css("cursor", "text");	
}


