//<![CDATA[

/**
 * Activa los pop-ups de los enlaces con rel="external", y centra los pop-ups en pantalla.  
 * @author usaelraton.com
 * @param {int} ancho
 * @param {int} alto
 */
function activarPopups(ancho, alto)
{
	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) - 30;
	$("a[rel=external],a.external").click(function(e) // Activamos el popup al hacer clic.
	{
		window.open(this.href, "Externo", "width=" + ancho + ",height=" + alto + ",left=" + x + ",top=" + y + ",resizable=yes,scrollbars=yes,toolbar=yes");
		return false;
	});
}

/**
 * Busca las imágenes insertadas en Administra, les activa el fancybox y las centra
 * @author usaelraton.com
 */
function activarImagenes()
{
	$("img.galeria").each(function()
	{
		$(this).wrap("<a class='fancy' rel='galeria' href='" + $(this).attr("src").replace("miniaturas", "ampliaciones") + "'></a>");
	}).parents('p').css({'text-align':'center'});
}

/**
 * Busca los vídeos pre-insertados en Administra y los reemplaza por el vídeo original
 * @author usaelraton.com
 */
function activarVideos()
{
	$("img.video").each(function()
	{
		var ancho = $(this).attr("width");   
		var alto = $(this).attr("height");
		var ruta = decodeURI($(this).attr("title"));
		
		$(this).replaceWith(
			'<div style="text-align:center;">' +
			'<object type="application/x-shockwave-flash" data="' + ruta + '" width="' + ancho + '" height="' + alto + '">' +
			'<param name="movie" value="' + ruta + '" />' +
			'</object>' +
			'</div>'
		);
	});
}

$(document).ready(
	function(e)
	{
		$("tbody tr:even").css("background-color", "#e5e5e5");
		$("#contenido a[href^=http]").not("a[href*=logopedialogos.com]").addClass("external").attr("rel", "external");
		activarPopups(800,600);
		activarImagenes();
		activarVideos();
	}
);
//]]>