$(document).ready(function()
{
	// tabs
	$("ul.tabs > li").each(function()
	{
		$(this).attr("tabClass", $(this).attr("title"));
		$(this).removeAttr("title");

		$(this).click(function()
		{
			$(this).parent().children().not(this).each(function()
			{
				$(this).removeClass("tabActive");
				$("." + $(this).attr("tabClass")).hide();
			});
			$(this).addClass("tabActive");
			$("." + $(this).attr("tabClass")).show();
		});
	});
	$("ul.tabs > li:first-child").click();

	// menus
	if("undefined" != typeof(menuActiveId) && menuActiveId) $("#"+menuActiveId).each(function() { $(this).addClass("menuActive").css("font-weight", "bold"); });
	$("ul.menu").each(function()
	{
		var ulMenu = $(this);
		$("li > a + ul", ulMenu).each(function()
		{
			$(this)
				.prev()
					.click(function()
					{
						$(this).next().toggle();
					})
					.parent().css("background", "url(img/mas.gif) 10px 7px no-repeat").end()
				.end()
				.hide();


		});
		$("li.menuActive").parents().show();
	});

	// tablas
	$("table.tabla_general tr td a").each(function()
	{
		$(this).parent()
			.mouseover(function() { $(this).addClass("fila_on"); })
			.mouseout(function() { $(this).removeClass("fila_on"); })
			.end();
	});
/*
	$("table.tabla_general tr").each(function()
	{
		$(this)
			.mouseover(function() { $(this).addClass("fila_on"); })
			.mouseout(function() { $(this).removeClass("fila_on"); });
	});
*/

	// listas
	$("dd:not(:first)").hide();
	$("dt a").click(function(){
		$("dd:visible").slideUp("slow");
		$(this).parent().next().slideDown("slow");
		return false;
	});

	// destacados aleatorios
	var dstList = [
		{ src:"destacados/picto1.jpg", url:"listado_trabajos.jsp?posMenu=mmu_34", title:"TRABAJOS CAT" },
		{ src:"destacados/picto2.jpg", url:"listado_publicaciones.jsp?posMenu=mmu_33", title:"PUBLICACIONES" },
		{ src:"destacados/picto3.jpg", url:"foro.jsp?posMenu=mmu_36", title:"FORO intercat" },
		{ src:"destacados/picto4.jpg", url:"listado_recopilaciones.jsp?nivel3=254&posMenu=mmu_37", title:"CTE. Código técnico" },
		null
	];
	var dstNum = 3;	// numero de destacados para mostrar
	for(var dstCnt=0; dstCnt < dstNum && dstList.length-1 > dstCnt; dstCnt++)
	{
		var i;
		do { i = parseInt(Math.random()*(dstList.length-1)) } while(dstList[i].portada);
		var D = dstList[i];
		D.portada = true;
		$("#destacados").append("<a href='"+D.url+"'><img src='"+D.src+"' alt='"+D.title+"' /></a><br />");
	}

});
