function cambiarClase(direccion) {
    var arrElements = document.getElementById("ulNoticias").getElementsByTagName("li");

    for(var i = 0; i < arrElements.length; i++){
        if (arrElements[i].className == "noticiaVisible") {
           arrElements[i].className =  "noticiaInvisible";
           if (direccion == "adelante") { 
               if (i < ((arrElements.length)-1)) arrElements[i+1].className = "noticiaVisible";
               else arrElements[0].className = "noticiaVisible"; 
           }
           else {
               if (i > 0) arrElements[i-1].className = "noticiaVisible";
               else arrElements[(arrElements.length)-1].className = "noticiaVisible"; 
           }    
           return false;
        }
    }
    return false;
}


function paraInicio() {
    var arrElements = document.getElementById("ulNoticias").getElementsByTagName("li");
    
    for(var i = 1; i < arrElements.length; i++){
       arrElements[i].className = "noticiaInvisible"; 
    }
}



function crearEnlaces() {
    var enlaceIzq = document.createElement("a");
    var enlaceDer = document.createElement("a");
    var enlaceAll = document.createElement("a");
    var enlaceRss = document.createElement("a");
    var imagenIzq = document.createElement("img");
    var imagenDer = document.createElement("img");
    var nodotexto = document.createTextNode('Todas las noticias');
    var nodotexto2 = document.createTextNode('RSS');

    enlaceIzq.setAttribute("href", '#');
    enlaceDer.setAttribute("href", '#');
    enlaceAll.setAttribute("href", '/websi/contenidos/es/CTICalDia/salaDePrensa/noticias/');
    enlaceRss.setAttribute("href", '/es/rss.html');
    enlaceRss.setAttribute("id", 'rss');
    enlaceAll.setAttribute("id", 'noticiaAll');
    



    enlaceIzq.onclick = function (){cambiarClase('atras'); return false;};
    enlaceDer.onclick = function (){cambiarClase('adelante'); return false;};

    imagenIzq.setAttribute("src", "/websi/contenidos/es/resources/img/css/iconos/flechaIzq1.gif");
    imagenDer.setAttribute("src", "/websi/contenidos/es/resources/img/css/iconos/flechaDer1.gif");

    imagenIzq.setAttribute("width", "15");
    imagenDer.setAttribute("width", "15");

    imagenIzq.setAttribute("height", "10");
    imagenDer.setAttribute("height", "10");


    imagenIzq.setAttribute("alt", "Noticia anterior");
    imagenDer.setAttribute("alt", "Noticia siguiente");

    enlaceIzq.appendChild(imagenIzq);
    enlaceDer.appendChild(imagenDer);
    enlaceAll.appendChild(nodotexto);
    enlaceRss.appendChild(nodotexto2);
    document.getElementById("paraFlechas").appendChild(enlaceIzq);
    document.getElementById("paraFlechas").appendChild(enlaceDer);
    document.getElementById("paraFlechas").appendChild(enlaceAll);
    document.getElementById("paraFlechas").appendChild(enlaceRss);

}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(paraInicio);
addLoadEvent(crearEnlaces);

