//<![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],div#textos a").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;
	});
}

/**
 * Pone el foco en el primer input, textarea o select del documento
 * @author usaelraton.com
 */
function ponerFocoEnPrimerCampo()
{
    var etiquetas = document.getElementsByTagName("label");
    var campos;
    var tipoDeCampo;
    var focoPuesto = false;
    var i = 0;

    if (etiquetas.length > 0) // hay etiquetas en el documento
    {
        campos = etiquetas[0].childNodes; // obtenemos los hijos de la primera etiqueta
        /* Recorremos los hijos de la etiqueta hasta encontrar un input, y le asignamos el foco */
        while ((i < campos.length) && (focoPuesto == false))
        {
            tipoDeCampo = campos[i].nodeName.toLowerCase();
            if ((tipoDeCampo == "input") || (tipoDeCampo == "textarea") || (tipoDeCampo == "select"))
            {
                campos[i].focus();
                focoPuesto = true;
            }
            i++;
        }
    }
}

/**
 * Traduce a español el widget de Twitter
 * @author usaelraton.com
 */
function personalizarTwitter()
{
	var cadenas = new Array("minute", "hour", "day", "about", "an", "ago");
	var reemplazos = new Array("minuto", "hora", "día", "aproximádamente", "1", "");
	var texto = '';
	var tiempo = '';
	var i;
	
	$("#twitter_update_list li").each(function(){
		texto = $("span", $(this)).text();
		tiempo = $("a[href*=twitter.com][href*=status]", $(this)).text();
		for(i = 0; i < cadenas.length; i++)
		{
			tiempo = tiempo.replace(cadenas[i], reemplazos[i]);
		}
		$(this).html('<a href="http://twitter.com/turismoas">' + jQuery.trim(texto) + ' <span>(hace ' + jQuery.trim(tiempo) + ')</span></a>');
		
	});	
}

$(document).ready(
	function(e)
	{
		activarPopups(1024,768);
		personalizarTwitter();
		//ponerFocoEnPrimerCampo();
		$("tbody tr:odd").css("background-color", "#eee");
		$("tbody tr:odd td:has(img)").css("background-color", "#fff");
		$("a[rel=external]:has(img),#contenido a.external:has(img)").css({"background-image" : "none", "padding-right" : "0"});
	}
);
//]]>