var aNoticias;      // Array
var iActiveNoticia; // Integer

aNoticias = new Array(); // Almacenará todas las noticias destacadas.

iActiveNoticia = 0;

function rotateNoticia(iDir) {
	iActiveNoticia = _rotate(iDir, iActiveNoticia, aNoticias.length - 1);

	showNoticia();
}

function _rotate(iDir, iActive, iLast) {
	var iResult; // Integer

	iResult = iActive;

	switch(iDir) {
		case -1: if(iActive ==     0) iResult = iLast; else iResult--; break;
		case +1: if(iActive == iLast) iResult =     0; else iResult++; break;
	}

	return iResult;
}

function showBox(sBoxName) {
	var oCajaSelected;   // Object
	var oCajaNoticias;   // Object

	oCajaNoticias = document.getElementById("caja_noticias");

	oCajaNoticias.style.display   = "none";

	oCajaSelected = document.getElementById("caja_"   + sBoxName);

	oCajaSelected.style.display = "block";
}

function _getNoticias(oXmlDoc) {
	// Se obtiene un array con todos los elementos.
	var aXmlData = oXmlDoc.getElementsByTagName("noticia");

	// Se recorren los elementos.
	for(i = 0; i < aXmlData.length; i++) {
		aNoticias[i] = new Array();
		// Se obtiene un array con los atributos del elemento.
		aAttributes = aXmlData[i].attributes;

		// Se recorren los attributos del elemento.
		for(j = 0; j < aAttributes.length; j++) {
			switch(aAttributes[j].name) {
				case "id":    aNoticias[i]["id"]     = aAttributes[j].value; break;
				case "title": aNoticias[i]["titulo"] = unescape(aAttributes[j].value); break;
			}
		}

		// Se obtiene un array con los nodos hijos del elemento.
		var aChildren = aXmlData[i].childNodes;

		// Se recorren los nodos hijos del elemento.
		for(k = 0; k < aChildren.length; k++) {
		/*	 Valores que puede asumir la propiedad nodeType.
			 1 : ELEMENT_NODE 
			 2 : ATTRIBUTE_NODE 
			 3 : TEXT_NODE 
			 4 : CDATA_SECTION_NODE  
			 5 : ENTITY_REFERENCE_NODE 
			 6 : ENTITY_NODE 
			 7 : PROCESSING_INSTRUCTION_NODE 
			 8 : COMMENT_NODE  
			 9 : DOCUMENT_NODE  
			10 : DOCUMENT_TYPE_NODE  
			11 : DOCUMENT_FRAGMENT_NODE 
			12 : NOTATION_NODE 

			// Se procesan sólo los nodos que son elementos (tags).
		*/	switch(aChildren[k].nodeType) {
				case 1: {
					switch(aChildren[k].tagName) {
						case "description": {
							// Se obtiene un array con los nodos hijos del elemento.
							aChildren2 = aChildren[k].childNodes;

							// Se recorren los nodos hijos del elemento.
							for(l = 0; l < aChildren2.length; l++) {
								// Se procesan sólo los nodos que son texto.
								if(aChildren2[l].nodeType == 3) {
									aNoticias[i]["subtitulo"] = unescape(aChildren2[l].nodeValue); break;
								}
							}

							break;
						}
						case "image": {
							// Se obtiene un array con los atributos del elemento.
							aChildAttributes = aChildren[k].attributes;

							// Se recorren los attributos del elemento.
							for(l = 0; l < aChildAttributes.length; l++) {
								switch(aChildAttributes[l].name) {
									case "title": aNoticias[i]["image_title"] = unescape(aChildAttributes[l].value); break;
									case "file":  aNoticias[i]["image_file"]  = aChildAttributes[l].value; break;
								}
							}

							break;
						}
						case "date": {
							// Se obtiene un array con los atributos del elemento.
							aChildAttributes = aChildren[k].attributes;

							// Se recorren los attributos del elemento.
							for(l = 0; l < aChildAttributes.length; l++) {
								if(aChildAttributes[l].name == "value") {
									aNoticias[i]["fecha"] = aChildAttributes[l].value;
								}
							}

							break;
						}
					}

					break;
				}
			}
		}
	}

	showNoticia();
}