var aMultimedia;       		// Array
var aNoticias;         		// Array
var aCuriosidades;        // Array
var iActiveMultimedia; 		// Integer
var iActiveNoticia;    		// Integer
var iActiveCuriosidad;    // Integer

aMultimedia 	= new Array();	// Almacenará todos los contenidos multimedia destacados.
aNoticias   	= new Array(); 	// Almacenará todas las noticias destacadas.
aCuriosidades	= new Array(); 	// Almacenará todas las curiosidades destacadas.

iActiveMultimedia	= 0;
iActiveNoticia		= 0;
iActiveCuriosidad	= 0;

function rotateMultimedia(iDir) {iActiveMultimedia	= _rotate(iDir, iActiveMultimedia,	aMultimedia.length   - 1); showMultimedia();}
function rotateNoticia(iDir)    {iActiveNoticia			= _rotate(iDir, iActiveNoticia,			aNoticias.length   	 - 1); showNoticia();}
function rotateCuriosidad(iDir) {iActiveCuriosidad	= _rotate(iDir, iActiveCuriosidad,	aCuriosidades.length - 1); showCuriosidad();}

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 oCajaMultimedia;		// Object
	var oCajaNoticias;			// Object
	var oCajaCuriosidades;	// Object

	oCajaMultimedia 	= document.getElementById("caja_multimedia");
	oCajaNoticias   	= document.getElementById("caja_noticias");
	oCajaCuriosidades	= document.getElementById("caja_curiosidades");

	oCajaMultimedia.style.display 	= "none";
	oCajaNoticias.style.display   	= "none";
	oCajaCuriosidades.style.display	= "none";

	oCajaSelected = document.getElementById("caja_"   + sBoxName);

	oCajaSelected.style.display = "block";
}

function _getMultimedia(oXmlDoc) {
	// Se obtiene un array con todos los elementos.
	var aXmlData = oXmlDoc.getElementsByTagName("multimedia");

	// Se recorren los elementos.
	for(i = 0; i < aXmlData.length; i++) {
		aMultimedia[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":    aMultimedia[i]["id"]     = aAttributes[j].value; break;
				case "title": aMultimedia[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) {
									aMultimedia[i]["descripcion"] = 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": aMultimedia[i]["image_title"] = unescape(aChildAttributes[l].value); break;
									case "file":  aMultimedia[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") {
									aMultimedia[i]["fecha"] = aChildAttributes[l].value;
								}
							}

							break;
						}
					}

					break;
				}
			}
		}
	}

	showMultimedia();
}

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();
}

function _getCuriosidades(oXmlDoc) {
	// Se obtiene un array con todos los elementos.
	var aXmlData = oXmlDoc.getElementsByTagName("curiosidad");

	// Se recorren los elementos.
	for(i = 0; i < aXmlData.length; i++) {
		aCuriosidades[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":    aCuriosidades[i]["id"]     = aAttributes[j].value; break;
				case "title": aCuriosidades[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) {
									aCuriosidades[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": aCuriosidades[i]["image_title"] = unescape(aChildAttributes[l].value); break;
									case "file":  aCuriosidades[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") {
									aCuriosidades[i]["fecha"] = aChildAttributes[l].value;
								}
							}

							break;
						}
					}

					break;
				}
			}
		}
	}

	showCuriosidad();
}