// Fundos
var fundos = new Array()
for(cont=1;cont<=8;cont++) {
	fundos[cont] = '/imagens/<?php echo $secao ?>/fundo_thumb_'+cont+'.gif';
}

// Conta os thumbnails
nthumbs = 0; for(thumb in thumbs) nthumbs++;

// Já carregou 4 thumbs
indice=3;

// Carrega as imagens em cache
preload = new Array();
for(cont=3; cont<nthumbs; cont++) {
	preload[cont] = new Image();
	preload[cont].src=thumbs[cont]['thumbnail'];
}
for(cont=nthumbs-1; cont<nthumbs+8; cont++) {
	preload[cont] = new Image();
	preload[cont].src=fundos[cont];
}

function proximo() {
	for(cont=0; cont<4; cont++) {
		indice++;
		if(indice>=(nthumbs)) indice = 0;
		caixa = document.getElementById('sel_caixa'+cont);
		link1 = document.getElementById('sel_link1'+cont);
		link2 = document.getElementById('sel_link2'+cont);
		thumb = document.getElementById('sel_img'+cont);
		caixa.style.backgroundImage = 'url(' + fundos[Math.floor(Math.random()*8)+1] + ')';
		link1.href = thumbs[indice]['url'];
		thumb.src = thumbs[indice]['thumbnail'];
		link2.innerHTML = thumbs[indice]['nome'];
		link2.href = thumbs[indice]['url'];
	}
}

function anterior() {
	for(cont=3; cont>=0; cont--) {
		indice--;
		if(indice<0) indice = nthumbs-1;
		caixa = document.getElementById('sel_caixa'+cont);
		link1 = document.getElementById('sel_link1'+cont);
		link2 = document.getElementById('sel_link2'+cont);
		thumb = document.getElementById('sel_img'+cont);
		caixa.style.backgroundImage = 'url(' + fundos[Math.floor(Math.random()*8)+1] + ')';
		link1.href = thumbs[indice]['url'];
		thumb.src = thumbs[indice]['thumbnail'];
		link2.innerHTML = thumbs[indice]['nome'];
		link2.href = thumbs[indice]['url'];
	}
}