var xmlDoc;
// code for IE


pg = 1;
maxCol = 4;
maxLin = 5;
maxImg = maxLin*maxCol;
img = 0;

function categoria(cat){
	catalogo = cat;
	if (window.ActiveXObject)
		{	
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;		
		xmlDoc.load("xml/"+catalogo+".xml");		
		}
		// code for Mozilla, Firefox, Opera, etc.
		else if (document.implementation.createDocument)
		{
			var xmlhttp = new window.XMLHttpRequest();
			xmlhttp.open("GET", "xml/"+catalogo+".xml", false);
			xmlhttp.send(null);
			xmlDoc = xmlhttp.responseXML.documentElement;
			
		}
	else
	{
		alert('Seu navegador não suporta os scripts desta página.');
	}	
	
	
	x=xmlDoc.getElementsByTagName("IMAGEM");
	img = 0;
	pg = 1;
	totalImg = x.length;
	maxPg = Math.floor(totalImg/maxImg)+1;
	gerarCatalogo(pg);		
}

function gerarIndice(pg){
	html="<font color='#999999'>Anterior</font>";
	if(pg>1) html="<a href='javascript:pagAnt()'>Anterior</a>";
	for(i=1; i<=maxPg; i++){
		if(i==pg){
			html+=" <big>" +i+"</big>";
		}else{
			html+="<a href='javascript:passarPg("+i+")'> "+i+"</a>";
		}
	}
	if(pg<maxPg){
		html+="<a href='javascript:proxPag()'> Pr&#243;xima</a>";
	}else{
		html+="<font color='#999999'> Pr&#243;xima</font>";
	}
	document.getElementById("indice01").innerHTML=html;
	document.getElementById("indice02").innerHTML=html;
}

function gerarCatalogo(pg){
	img = x.length-((pg-1)*maxImg)-1;
	
	html = "<table>";
	for (lin=0; lin<maxLin; lin++){
		html+= "<tr>";
			for (col=0; col<maxCol; col++){
				if(img<0){
					html+= "<td></td>";
				}else{
					imagem = x[img].getElementsByTagName("NOME_ARQUIVO")[0].childNodes[0].nodeValue;
					desc = x[img].getElementsByTagName("DESC")[0].childNodes[0].nodeValue;
												
					html+= "<td>";
					html+= "<div class='img'>";
					html+= "<a target='_blank' href='down.html?catalogo="+catalogo+"&imagem="+imagem+"'><name='tips'><img src='imgs/thumbs/"+catalogo+"/"+imagem+".jpg' title='"+desc+"'></a>";
					html+= "<div class='desc'><a target='_blank' href='down.html?catalogo="+catalogo+"&imagem="+imagem+"' title='"+desc+"'>Ampliar</div></a>";
					html+= "</div>";
					html+= "</td>";
				}
				img--;				
			}
		html+= "</tr>"
	}
	html+= "</table>";
	document.getElementById("thumbs").innerHTML=html;
	gerarIndice(this.pg);
}

function proxPag(){
	if (pg<=maxPg){
		pg++;	
		gerarCatalogo(pg);	
	}
}

function pagAnt(){
	if(pg>1){
		pg--;	
		gerarCatalogo(pg);	
	}
}

function passarPg(npg){
	pg=npg;
	gerarCatalogo(pg);
}
