function seguir(contador) {
	contador = contador+1;
	if(contador == 3) {
		contador = 0;
	}
	mover();
	setTimeout('seguir('+contador+')', 13000);
}

function mover() {
	var paso = 0;
	$('.desplazado img').each(function(i, v) {
		if ($(this).hasClass('mostrar') && paso == 0) {
			if (i == ($('.desplazado img').size()-1)) {
				$(this).removeClass('mostrar').fadeOut(2000);
				$('.desplazado img:eq(1)').addClass('mostrar').show(1).animate({ opacity: 1 }, 2000);
				/*$('.etiqueta').animate({ marginTop: 0, height: 0 }, 500, function() {*/
				$('.etiqueta').animate({ marginTop: 0 }, 1000, function() {
					$(this).css({ 'margin-left':'-100%', 'margin-top':'-50px' }).html($('.desplazado img:eq(1)').attr('alt')).animate({ marginLeft: 0 }, 1000);
				});
				paso = 1;
			}
			else {
				$(this).removeClass('mostrar').fadeOut(2000);
				$('.desplazado img:eq('+(i+1)+')').addClass('mostrar').show(1).animate({ opacity: 1 }, 2000);
				/*$('.etiqueta').animate({ marginTop: 0, height: 0 }, 500, function() {*/
				$('.etiqueta').animate({ marginTop: 0 }, 1000, function() {
					$(this).css({ 'margin-left':'-100%', 'margin-top':'-50px' }).html($('.desplazado img:eq('+(i+1)+')').attr('alt')).animate({ marginLeft: 0 }, 1000);
				});
				paso = 1;
			}
		}
	});
}

function animar() {
	var src = $('.galeriathumbdentro img:first').attr('src');
	var alt = $('.galeriathumbdentro img:first').attr('alt');
	$('.galeriathumbdentro img:eq(1)').animate({ opacity: 1 }, 2000);
	$('.galeriathumbdentro img:first').css({ 'z-index':'100' }).animate({ opacity: 0.1 }, 1000, function(i, v) { $(this).remove(); $('.galeriathumbdentro').append("<img src='"+src+"' alt='"+alt+"' />").children('img:gt(0)').css({ 'opacity':'0' }); });
	setTimeout('animar()', 10000);
}

$(document).ready(function() {

	$('.desplazado img:gt(0)').animate({ opacity: 0 }, 1)
	$('.etiqueta').html($('.desplazado img:eq(0)').attr('alt')).animate({ marginLeft: 0 }, 1000);
	setTimeout('seguir(1)', 14000);

	var max = 0;
	$('.bloquedentrocontenido').each(function(i, v) {
		if ($(this).height() > max) {
			max = $(this).height();
		}
	});

	$('.bloquedentrocontenido').css({ 'height': max+'px' });
	$('.galeriathumbdentro img:gt(0)').css({ 'opacity':'0' });
	setTimeout('animar()', 10000);

});
