$(document).ready(function() {

$('.paginable a').click(function() {
		if (!$(this).parent().hasClass('activo')) {
			var destino = $(this).attr('class').split('_');
			
			if (destino[1] == 'anterior') {
				newDestino = $('.paginable .activo a').attr('class').split('_');
				destino[1] = parseInt(newDestino[1]);
			}else if (destino[1] == 'siguiente') {
				newDestino = $('.paginable .activo a').attr('class').split('_');
				destino[1] = parseInt(newDestino[1])+2;
			}else {
				destino[1] = parseInt(destino[1])+1;
			}
			
			if ($('.lista_preguntas').length) {
				$('.lista_preguntas').removeClass('activo').hide();
				var newElem = $('#pregs .lista_preguntas:nth-child('+destino[1]+')');
			}else if ($('.lista_preguntas_in').length) {
				$('.lista_preguntas_in').removeClass('activo').hide();
				var newElem = $('.lista_preguntas_in:nth-child('+destino[1]+')');
			}else if ($('.lista_news').length) {
				$('.lista_news').removeClass('activo').hide();
				var newElem = $('.lista_news:nth-child('+destino[1]+')');
			}
			
				var newListPregHeight = newElem.height();
				newElem.fadeTo(200, 1.0).addClass('activo');
				
				destino[1] = parseInt(destino[1])-1;
			
			($('.pag_'+destino[1]).parent().hasClass('first'))?$('.paginable .pag_anterior').hide():$('.paginable .pag_anterior').show();
			($('.pag_'+destino[1]).parent().hasClass('last'))?$('.paginable .pag_siguiente').hide():$('.paginable .pag_siguiente').show();
			//($('.pag_'+destino[1]).parent().hasClass('first'))?$('.pag_anterior').fadeTo(0,0.0):$('.pag_anterior').fadeTo(0,1.0);
			//($('.pag_'+destino[1]).parent().hasClass('last'))?$('.pag_siguiente').fadeTo(0,0.0):$('.pag_siguiente').fadeTo(0,1.0);
			$('.paginable li').removeClass('activo');
			$('.paginable a[class="pag_'+destino[1]+'"]').parent().addClass('activo');
			
			
		}
		return false;
	});



});
