function ajax()
{
	if(window.XMLHttpRequest)
	{
		return new XMLHttpRequest()
	}
	else
	{
		try
		{
			return new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(e)
		{
			alert(e);
			return;
		}
   	}
}

/* Funcion para leer las noticias desde un archivo XML y crear una tabla con ellas*/
function leerXML()
{
	aj = new ajax();
	try 
	{
		aj.open('get', '../noticias/noticias.xml', true);
		aj.onreadystatechange = function()
		{
			if (aj.readyState == 4) 
			{
				var table = document.createElement("table");
				var tBody = document.createElement("tbody");
				xml = aj.responseXML.getElementsByTagName('noticia');
				for (i = 0; i < xml.length; i++) 
				{
					var trTitle = document.createElement("tr");
					var tdTitle = document.createElement("td");
					tdTitle.setAttribute("align", "left");
					tdTitle.setAttribute("class", "titulo_noticias");
							
					var trBody = document.createElement("tr");
					var tdBody = document.createElement("td");
					tdBody.setAttribute("align", "left");
					tdBody.setAttribute("class", "contenido_noticias");
							
					var salto = document.createElement("br");
					var tr = document.createElement("tr");
					var td = document.createElement("td");
						
					var title = document.createTextNode(xml[i].getElementsByTagName('title')[0].firstChild.data);
					var body = document.createTextNode(xml[i].getElementsByTagName('body')[0].firstChild.data);
						
					tdTitle.appendChild(title);
					trTitle.appendChild(tdTitle);
					tBody.appendChild(trTitle);
								
					tdBody.appendChild(body);
					trBody.appendChild(tdBody);
					tBody.appendChild(trBody);
								
					td.appendChild(salto);
					tr.appendChild(td);
					tBody.appendChild(tr);
				}
				table.appendChild(tBody);
				document.getElementById("tablaNoticias").appendChild(table);
							
				aj.onreadystatechange = null;
			}
		}
		aj.send(null);
	} 
	catch (e) 
	{
		alert(e);
		return;
	}
}


/* Secuencia de la animacion con cadena de callbacks, es decir, la primer 
 * animacion se ejecuta y llama a la siguiente en estricto orden*/
jQuery(function($){
	var valor1 = $('#valor1');
	var valor2 = $('#valor2');
	var valor3 = $('#valor3');	
	var modal = $("#pop");
	
	modal.dialog({	
		autoOpen: false,
		bgiframe: true,
		height: 400,
		width: 500,
		modal: true,
		draggable: false,
		resizable: false		
	});

	$('#libertades').click(function(){
		modal.dialog('open');
	});
	
	$('#decoItem')
		.css({backgroundPosition: '0px 0'})
		.animate({backgroundPosition: '-5px -300px'}, 1000, 'linear', crearV); 
	
	function crearV(){		
		$('#letra').animate({width: '220px'}, 500, crearTitle);
	}
	
	function crearTitle(){
		$('#title').animate({height:'40px', textIndent: '0px'}, 500 , crearValor1);
	}
	
	function crearValor1(){
		valor1.animate({height:'40px', textIndent: '0px'}, 500 , moverValor1);
	}
	
	function moverValor1(){
		valor1.animate({marginLeft: '50px'}, 500, crearValor2);
	}
	
	function crearValor2(){
		valor2.animate({height: '40px', textIndent: '0px'}, 500, moverValor2);
	}
	
	function moverValor2(){
		valor2.animate({marginLeft: '75px'}, 500, crearValor3);
	}
	
	function crearValor3(){
		valor3.animate({height: '40px', textIndent: '0px'}, 500, moverValor3);
	}
	
	function moverValor3(){
		valor3.animate({marginLeft: '100px'}, 500, crearItem1);		
	}
	
	function crearItem1(){
		$('#item1').animate({width: '20px'}, 500, crearItem2);
	}
	
	function crearItem2(){
		$('#item2').animate({width: '20px'}, 500, crearItem3);
	}
	
	function crearItem3(){
		$('#item3').animate({width: '20px'}, 500, crearTransparencia);
	}
	
	function crearTransparencia() {
		$('#transparencia').animate({height: '220px'}, 2000, crearLogo); 
	}
	
	function crearLogo() {
		$('#logo').animate({height: '130px'}, 1000);
	}
});
