// JavaScript Document
var indice=0;
var xmlDoc;
var raiz;

function mostrarAnuncio() {
	var nodo;
	var fotoPuesta;
	var textoPuesto;
	
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		// Para IE
		indice++;
		if (indice>=raiz.childNodes.length)
		{
			indice=0;
		}
		nodo=raiz.childNodes.item(indice);
		// Obtiene los resultados
		fotoPuesta=nodo.childNodes.item(0).text;
		textoPuesto=nodo.childNodes.item(1).text;
	}
	else
	// Para Firefox y los demas
	{
		// Buscamos el siguiente nodo
		indice++;
		var hijos=raiz.getElementsByTagName("anuncio");
		if (indice>=hijos.length)
		{
			indice=0;
		}
		nodo=hijos[indice];
		// Obtiene los resultados
		fotoPuesta=nodo.getElementsByTagName("imagen")[0].textContent;
		textoPuesto=nodo.getElementsByTagName("titular")[0].textContent;
	}
		// Pone el anuncio
		//document.getElementById("foto").style.backgroundImage="url(\""+nodo.getElementsByTagName("imagen")[0].textContent+"\")";
		document.getElementById("fotoAnuncio").src="./anuncios/"+fotoPuesta;
		// Pone el titulo
		document.getElementById("comentario").innerHTML = textoPuesto;
	
}

function inicializarAnuncios()
{
	if (navigator.appName == "Microsoft Internet Explorer")
	{
		// Para Internet Explorer
		xmlDoc = new ActiveXObject("Microsoft.XmlDom");
		xmlDoc.async=false;
		xmlDoc.load("./anuncios/anuncios.xml");
		raiz=xmlDoc.documentElement;
	}	
	else
  	{
		// Para los otros
		xhttp=new XMLHttpRequest();
		xhttp.open("GET","./anuncios/anuncios.xml",false);
		xhttp.send();
		xmlDoc=xhttp.responseXML;
		raiz=xmlDoc.getElementsByTagName("anuncios")[0];
	}
	indice=0;
	// Se establece la frecuencia de los anuncios
	setInterval('mostrarAnuncio()', 3000);
}

