var mensajeActual = 0;
var totalMensajes;
var intervaloMensajes;
var tiempoEspera= 5;  // Tiempo de espera entre casos expresado en SEGUNDOS
var tiempoFundido = 1000; // Tiempo de fundido de los casos expresado en MILISEGUNDOS


$(document).ready(init);
function init(){
	


// ENLACES EXTERNOS
	$(".aExterno").attr("target", "_blank");
	$(".pdf").attr("target", "_blank");
	$("#dep-tecnico #contents a").attr("target", "_blank");
	$("#material #contents a").attr("target", "_blank");
	
	// MENU PRINCIPAL
	$("#mainMenu li ul li").css("opacity", 0);
	$("#mainMenu li:has(ul)").hover(showInfo, hideInfo);

	// SLIDESHOW HOME
	totalMensajes = $("#index #contents-home #mask div").length;
	$("#index #contents-home #mask div").hide();
	$("#index #contents-home #mask div:first").show();
	clearInterval(intervaloMensajes);
	intervaloMensajes = setInterval(carruselMensajes, tiempoEspera*1000);
	
	// DESPLEGABLE AVISO ENVIAR CV
	$("#bolsaTrabajo #link_cv").click(showCVInfo);

	// AYUDA FORMULARIO ENVIO OFERTAS
	$("#form_ofertas .close img").css("cursor", "pointer");
	$("#form_ofertas .close img").stop().hover(showHelp, hideHelp);
	
	// SECCION ENLACES
	$("#listaEnlaces li h3").css("cursor", "pointer");
	$("#listaEnlaces li h3").click(showLinks);
	
	// ESPACIO CIRCULARES
	$("#circulares .modCircular").css("padding", "8px 0px 8px");

}


// FUNCIONES MENU PRINCIPAL
function showInfo(){
	var cssMenuOver = {
      'color' : '#fff',
      'background' : 'url(img/btn_mainMenu_over.gif)'
    }
	$(this).find("p").css(cssMenuOver);
	$(this).find("ul").removeClass("oculto").animate({"opacity": 1}, 500);
	$(this).find("ul li").removeClass("oculto").animate({"opacity": 1}, 500);
}
function hideInfo(){
	var cssMenuOut = {
      'color' : '#c1051d',
      'background' : 'url(img/btn_mainMenu.gif)'
    }
	$(this).find("p").css(cssMenuOut);
	$(this).find("ul").animate({"opacity": 0}, 200).addClass("oculto");
	$(this).find("ul li").animate({"opacity": 0}, 200).addClass("oculto");
}
function cambiaEstilo(id, value) {
    document.getElementById(id).style.display = value;
}


// FUNCIONES SLIDESHOW HOME

function carruselMensajes(){
	clearInterval(intervaloMensajes);
	$("#index #contents-home #mask div:eq("+mensajeActual+")").fadeOut(tiempoFundido, muestraNuevoMensaje)
	if (mensajeActual<totalMensajes-1){
		mensajeActual++;
	}else{
		mensajeActual=0;
	}
}

function muestraNuevoMensaje(){
	$("#index #contents-home #mask div").hide();
	$("#index #contents-home #mask div:eq("+mensajeActual+")").fadeIn(tiempoFundido, function (){intervaloMensajes = setInterval(carruselMensajes, tiempoEspera*1000); });
}


// FUNCIONES AYUDA FORMULARIO ENVIO OFERTAS

function showHelp(){
	$(this).next().removeClass("oculto").animate({"opacity": 1}, 1000);
}
function hideHelp(){
	$(this).next().removeClass("oculto").animate({"opacity": 0}, 500);
}


// FUNCIONES DESPLEGABLE AVISO ENVIAR CV

function showCVInfo(){
	$(this).next().slideUp("slow");
	if ($(this).next().is(":hidden")) {
	$(this).next().slideDown("slow");
	} else {
	$(this).next().hide();
}

}

// FUNCIONES SECCION ENLACES

function showLinks(){
	$("#listaEnlaces li h3").removeClass("selected");
	$("#listaEnlaces li ul li").css("height", "auto");
	$("#listaEnlaces li ul").slideUp("slow");
	if ($(this).next().is(":hidden")) {
	$(this).next().slideDown("slow");
	$(this).addClass("selected");
	} else {
	$(this).next().hide();
}

}



