var xmlDoc;

if (window.ActiveXObject)
{
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
else
if 
(document.implementation.createDocument)
{
    xmlDoc=document.implementation.createDocument("","",null);
}
else
{
    document.getElementById("noticias").innerHTML="";
}

xmlDoc.async=false;
xmlDoc.load("xml/noticias.xml");
noticias=xmlDoc.getElementsByTagName("noticia");
contNoticia=0;
if(noticias.length>1)
	timeout  = setTimeout("muestraNoticiasAut()", 30000);
estaActiva=true;

function showNoticia(i)
{ 
  txt="";
  activa="";
  if(noticias.length>0)
  {
	  desc=(noticias[i].getElementsByTagName("desc")[0].childNodes[0].nodeValue);
	  desc=desc.replace(/&quot;/gi, "\"");
	  desc=desc.replace(/&gt;/gi, ">");
	  desc=desc.replace(/&lt;/gi, "<");
	  desc=desc.replace(/&amp;/gi, "&");
	  
	  titulo=(noticias[i].getElementsByTagName("titulo")[0].childNodes[0].nodeValue);
	  titulo=titulo.replace(/&quot;/gi, "\"");
	  titulo=titulo.replace(/&gt;/gi, ">");
	  titulo=titulo.replace(/&lt;/gi, "<");
	  titulo=titulo.replace(/&amp;/gi, "&");
	  
	  fecha=(noticias[i].getElementsByTagName("fecha")[0].childNodes[0].nodeValue); 
	  activa=(noticias[i].getElementsByTagName("activa")[0].childNodes[0].nodeValue);

	  txt="<img src=\"images/newspaper.png\" alt=\"noticia\" /><h4><span>"+titulo+"</span></h4><h4>"+fecha+"</h4>"+desc;
  }
  else
  {
	  txt="<p>No hay noticias</p>";
  }
  
  estaActiva=true;
  if(activa=="true")
  {
  	  document.getElementById("noticia").innerHTML=txt;
  }
  else
  	estaActiva=false;
}

function noticiaSig()
{
	if(noticias.length>1)
		clearTimeout(timeout);
	document.getElementById("noticia").innerHTML="";
	if(contNoticia == noticias.length-1)
		contNoticia = 0;
	else
		contNoticia++;
	
	//Bucle para que se salte las noticias NO activas
	cont = 0;
	do
	{
		showNoticia(contNoticia);
		if(!estaActiva)
		{
			if(contNoticia == noticias.length-1)
				contNoticia = 0;
			else
				contNoticia++;			
		}
		cont++;
	}
	while(!estaActiva && cont<noticias.length);
	
	//new Effect.Highlight('noticia',{ startcolor: '#ffff99',endcolor: '#dfdfdf' });
}

function noticiaAnt()
{
	if(noticias.length>1)
		clearTimeout(timeout);
	if(contNoticia==0)
		contNoticia = noticias.length-1;
	else
		contNoticia--;
		
	//Bucle para que se salte las noticias NO activas
	cont = 0;
	do
	{
		showNoticia(contNoticia);
		if(!estaActiva)
		{
			if(contNoticia==0)
				contNoticia = noticias.length-1;
			else
				contNoticia--;			
		}
		cont++;
	}
	while(!estaActiva  && cont<noticias.length);		
	
	//new Effect.Highlight('noticia',{ startcolor: '#ffff99',endcolor: '#dfdfdf' });
}

function muestraNoticiasAut()
{
	noticiaSig();
	timeout  = setTimeout("muestraNoticiasAut()", 30000);
}