//<![CDATA[

/**
 * Genera el efecto de menú desplegable.
 */
function activarDesplegables () {
	$("#categorias li").hover(
		function() { $(this).children("ul").slideDown(); },
		function() { $(this).children("ul").slideUp(); }
	);
	$("#categorias li li").hover(
		function() { $(this).children("ul").css("display", "block"); },
		function() { $(this).children("ul").css("display", "none"); }
	);
}

function activarImagenes()
{
	$("img.foto,img.galeria").each(function()
	{
		$(this).wrap("<a class='thickbox' title='" + $(this).attr("title") + "' href='" + $(this).attr("src").replace("miniatura", "ampliacion") + "'></a>");
	});
	
	$(".thickbox").not("[href*=inline]").removeAttr("rel");
	$(".thickbox").not("[href*=inline]").attr("rel", "galeria");
	
	$("p:has(.galeria)").css("text-align", "center");
}

function activarVideos()
{
	$("img.video").each(function()
	{
		var ancho = $(this).attr("width");   
		var alto = $(this).attr("height");
		var ruta = decodeURI($(this).attr("title"));
		
		$(this).replaceWith(
			"<object type='application/x-shockwave-flash' data='" + ruta + "' width='" + ancho + "' height='" + alto + "'>" +
			"<param name='movie' value='" + ruta + "' />" +
			"</object>"
		);
	});
	
	$("#textos object").wrap("<div style='text-align:center;'></div>");
}

/**
 * Activa los pop-ups de los enlaces con rel="external", y centra el pop-up en la pantalla. 
 * Hace uso de la biblioteca jQuery. 
 * @param {int} ancho
 * @param {int} alto
 */
function activarPopups(ancho, alto)
{
	$("#contenido a[href^=http]").not("a[href*=quadtreros],a[href*=tiendadequad],a[href*=productosusados]").addClass("popup");
	
	if (ancho > screen.width) { ancho = screen.width;}
	if (alto > screen.height) { alto = screen.height;}
	var x = (screen.width - ancho) / 2;
	var y = ((screen.height - alto) / 2);
	$("[rel=external], .popup").click(function(e) // Activamos el popup al hacer clic.  
	{
		window.open(this.href, null, "width=" + ancho + ",height=" + alto + ",left=" + x + ",top=" + y + ",resizable=yes,scrollbars=yes");
		return false;
	});
}

function iluminarPortalActivo()
{
	var portalActivo = document.URL.substring(document.URL.indexOf(":") + 3, document.URL.lastIndexOf(".") + 3);
	$("#portales a[href*=" + portalActivo + "]").css("background-image", "url('http://www.quadtreros.com/media/iconos/cuadrado-relleno.gif')");
}

$(document).ready(function(e){
	activarDesplegables();
	activarImagenes();
	activarVideos();
	activarPopups((screen.width  * 0.9), (screen.height * 0.9));
	iluminarPortalActivo()
	$("ul.entradas img:odd").css({"float":"right","margin":"0 0 0 2em"});
	$("div#contenido .publicidad, div#cierre.publicidad, div#textos table").wrap('<div style="text-align:center;"></div>');
	$(".thickbox").fancybox({'imageScale':false,'centerOnScroll':false}); 
});

//]]>