function slideSwitch() {
    var $active = $('#slideshow IMG.active');
    if ( $active.length == 0 ) $active = $('#slideshow IMG:last');
    var $next =  $active.next().length ? $active.next()
        : $('#slideshow IMG:first');
    $active.addClass('last-active');
    $next.css({opacity: 0.0})
        .addClass('active')
        .animate({opacity: 1.0}, 1000, function() {
            $active.removeClass('active last-active');
        });
}

$(function() {
    setInterval( "slideSwitch()", 4000 );
	
	$secActual = 0;
	
	$(".listado_general").click(function(){
		if ($(this).attr('rel') != "0"){
			$pulsado = $(this).attr('rel');
			$("#subsec_dch2 div").each(function(){			
				$(this).css("display", "none");
				if($(this).attr('rel') == $pulsado){
					$("#subsec_dch").fadeOut(200);
					$(this).fadeIn(200);
					$("#subsec_dch2").delay(200).fadeIn(200);
				}
			});
//			$("#subsec_dch").fadeOut(200);
//			$("#subsec_dch2").delay(200).fadeIn(200);
		}else{
			$("#subsec_dch2").fadeOut(200);
			$("#subsec_dch").delay(200).fadeIn(200);
			$("#subsec_izq2").fadeOut(200);
			$("#subsec_izq3").delay(200).fadeIn(200);
		}
	});
	
	$("#cerrar_pipetas").click(function(){
		$("#subsec_dch").fadeOut(200);
		$("#subsec_izq3").fadeOut(200);
		$("#subsec_izq2").delay(200).fadeIn(200);
	});
	
	$("#consulta").click(function(){
		$("#subsec_izq").fadeOut(200);
		$("#subsec_izq2").fadeIn(200);
		$("#subsec_dch").fadeOut(200);
		$("#subsec_dch2").fadeOut(200);
	});
	
	$("#menu li").click(function(){
		$sec = "#sec" + $(this).attr("id");
		$secActual = $sec;
		$("#menu").stop().animate({"top":"630px"}, 1000).delay(100).animate({"top":"-40px"}, 1000); // posibilidad 9px el men&uacute; se muestra en el TOP
		$("#logo").stop().animate({"top":"546px"}, 1000).delay(100).animate({"top":"-120px"}, 1000); 

		$($sec).stop().delay(1100).animate({"top":"0px"}, 1000);
		$("#volver").delay(2000).fadeIn(500);
	});
	
	function volverMenu(){
		$("#volver").fadeOut(500);
		$("#menu").stop().animate({"top":"630px"}, 1000).delay(100).animate({"top":"330px"}, 1000);
		$("#logo").stop().animate({"top":"546px"}, 1000).delay(100).animate({"top":"250px"}, 1000);
		
		$($secActual).stop().animate({"top":"660px"}, 1000);
	}
	
	$("#volver").click(function(){
		volverMenu();
	});

});
