//VARIABLES PREVIAS
ult=2;
ult+=jQuery('#ForoIndiceTemas img:[title="Tema chincheta"]').length;
f=new Date();
pag=window.location.href;
indicef=new Array();
fsubforos=new Array();
//FIN VARIABLRES PREVIAS

//FUNCION FECHAS
function fecha(variable){
	variable=new Date(variable.replace('Hoy',f.getDate()+'/'+0+(f.getMonth()+1)+'/'+f.getFullYear()).replace('Ayer',(f.getDate()-1)+'/'+0+(f.getMonth()+1)+'/'+f.getFullYear()).replace('Ene','01').replace('Feb','02').replace('Mar','03').replace('Abr','04').replace('May','05').replace('Jun','06').replace('Jul','07').replace('Ago','08').replace('Sep','09').replace('Oct','10').replace('Nom','11').replace('Dic','12').replace(', ','').replace(':','/'));
}
//FIN FUNCION FECHAS

//ENLACE SUBFOROS A ÚLTIMO POST
if(jQuery('#ForoIndiceSubforos').length>0){
	jQuery('#ForoIndiceSubforos a:[href*="/users/"]').parent().append(' <a style="cursor:pointer;" title="Ir al último mensaje del subforo" class="ultimo_post"><img src="http://josepepe033.webcindario.com/indices+/imagenes/ultimo_post.gif" border="0" /></a>');
	jQuery('.ultimo_post').click(function(){
		window.location.href=jQuery(this).parent().parent().children('td:eq(1)').children('a:first').attr('href')+'#ultimomsg';
	});
}

if(jQuery('#ForoIndiceTemas').length>0){
	if(pag.substring(pag.length-10,pag.length)=='#ultimomsg'){
		//COMPARAR FECHAS
		if(jQuery('img[title="Tema chincheta"]').length>0){
			fsubforos[0]=jQuery('img[title="Tema chincheta"]:first').parent().parent().parent().children('td:last').children('span').text();
			fsubforos[1]=jQuery('#ForoIndiceTemas tr:eq('+ult+')').children('td:last').children('span').text();
			if(fsubforos[0]=='No hay respuestas'){fsubforos[0]=jQuery('img[title="Tema chincheta"]:eq(0)').parent().parent().parent().children('td:last').prev().prev().prev().children('span').text();}
			if(fsubforos[1]=='No hay respuestas'){fsubforos[1]=jQuery('#ForoIndiceTemas tr:eq('+ult+')').children('td:last').prev().prev().prev().children('span.texto_mini').text();}
			fecha(fsubforos[0]);
			fecha(fsubforos[1]);
			if(fsubforos[0]>fsubforos[1]){
				ult=2;
			}
		}else{
			ult=2;
		}
		//FIN COMPARAR FECHAS
		
		//REDIRIRECCIONAR
		if(jQuery('#ForoIndiceTemas tr:eq('+ult+')').children('td:last').children('a:[href$="#ultimomsg"]').length==0){
			window.location.href=jQuery('#ForoIndiceTemas tr:eq('+ult+')').children('td:last').prev().prev().prev().prev().children('div:first').children('a:first').attr('href')+'#ultimomsg';
		}else{
			window.location.href=jQuery('#ForoIndiceTemas tr:eq('+ult+')').children('td:last').children('a:[href$="#ultimomsg"]').attr('href');
		}
		//FIN REDIRECCIONAR
	}
}
//FIN ENLACE SUBFOROS A ÚLTIMO POST

if(jQuery('#ForoIndiceSubforos').length>0){

	//OBTENER FECHAS
	for(u=0;u<jQuery('.ultimo_post').length;u++){
		indicef[u]=jQuery('.ultimo_post:eq('+u+')').parent().children('span.texto_mini').text();
		fecha(indicef[u]);
	}
	//FIN OBTENER FECHAS
	
	//COMPARAR FECHAS
	fechamayor=0;
	usando=indicef[0];
	for(u=0;u<jQuery('.ultimo_post').length;u++){
		if(usando<indicef[u]){
			usando=indicef[u];
			fechamayor=u;
		}
	}
	//FIN COMPARAR FECHAS

	//TABLA ÚLTIMAS RESPUESTAS
	tdreciente=jQuery('.ultimo_post:eq('+fechamayor+')');
	if(tdreciente.parent().parent().children('td:eq(1)').children('a:first').text()==''){ncelda=2;}else{ncelda=1;}
	tabla_ultimos_posts='<table width="100%" cellspacing="'+jQuery('#ForoIndiceSubforos').attr('cellspacing')+'" cellpadding="'+jQuery('#ForoIndiceSubforos').attr('cellpadding')+'" class="tabla"><tr class="tabla_titulo"><td><a href="http://'+document.domain+'/forums/#ultimomsg">Último tema activo</a></td></tr><tr class="tabla_texto_1"><td width="100%"><a href="'+tdreciente.parent().parent().children('td:eq(1)').children('a:first').attr('href')+'#ultimomsg"><img src="http://josepepe033.webcindario.com/indices+/imagenes/ultimo_post.gif" border="0" /></a> '+tdreciente.parent().children('span').html().replace(', ',' a las ')+', por <a href="'+tdreciente.parent().children('a:first').attr('href')+'" title="Haz clic para ver el perfil del usuario">'+tdreciente.parent().children('a:first').html()+'</a> en <a href="'+tdreciente.parent().parent().children('td:eq('+ncelda+')').children('a:first').attr('href')+'">'+tdreciente.parent().parent().children('td:eq('+ncelda+')').children('a:first').html()+'</a></td></tr></table><div style="'+jQuery('#ForoIndiceSubforos').prev().attr('style')+'"></div>';
	
	jQuery('#ForoIndiceSubforos').before(tabla_ultimos_posts);
	//FIN TABLA ÚLTIMAS RESPUESTAS

	//REDIRECCIONAR
	if(pag.substring(pag.length-10,pag.length)=='#ultimomsg'){
		window.location.href=jQuery('.ultimo_post:eq('+fechamayor+')').parent().parent().children('td:eq(1)').children('a:first').attr('href')+'#ultimomsg';
	}
	//FIN REDIRECCIONAR
}
//FIN ENLACE SUBFOROS A ÚLTIMO POST
