self.focus();
inicio = 0;
ft_thumbs   = new Array();
ft_fotos    = new Array();
ft_preload  = new Array();
ft_legendas = new Array();
ft_creditos = new Array();
ft_emails   = new Array();
fotoAtual = 1;
limiteMax = 21;
colunas = 7;
img_vazio  = "http://image.ig.com.br/chic/imagens/spacer.gif";

function montaThumbs() {
	parse = "<table width='422' border='0' cellspacing='0' cellpadding='0' class='bg_carinhas2'><tr>";

	for(i=1; i<=limiteMax; i++) {
		parse += "	<td width='56' bgcolor='#E9E9E9'><img src='" + ((typeof ft_thumbs[i+inicio] == "undefined") ? img_vazio : ft_thumbs[i+inicio]) + "' width='56' height='56' border='0'" + ((typeof ft_thumbs[i+inicio] != "undefined") ? " onclick='mostraImagem(" + (i + inicio) + ");'" : "") + "></td>\n";
		
		if(i%colunas > 0) {
			parse += "	<td width='5'><img src='http://image.ig.com.br/chic/imagens/spacer.gif' width='5' height='1'></td>\n";
		} else if(i%colunas == 0) {
			parse += "</tr><tr><td width='422' colspan='13' height='5'><img src='http://image.ig.com.br/chic/imagens/spacer.gif' width='1' height='1'></td></tr><tr>\n";
		}
	}
	parse += "</tr></table>";

	document.getElementById("thumbs").innerHTML = parse;
}

function mudaSessao(dir, navegacao) {
	if(dir == ">") {
		if((inicio + limiteMax) > 1 && (inicio + limiteMax) < (Math.ceil((ft_thumbs.length-1) / limiteMax) * limiteMax)) {
			inicio = inicio + limiteMax;
	
			mostraImagem(inicio + 1);
			montaThumbs();				
		}
	} else if(dir == "<") {
		if((inicio - limiteMax) >= 0 && (inicio - limiteMax) < (Math.ceil((ft_thumbs.length-1) / limiteMax) * limiteMax)) {
			inicio = inicio - limiteMax;
	
			if(!navegacao) {
				mostraImagem(inicio + 1);
			} else {
				mostraImagem(fotoAtual - 1);
			}
			montaThumbs();				
		}
	}
}

function mostraImagem(id) {
	parent.document.painelImagens.src = ft_fotos[ id ];

	parent.document.getElementById("restantes").innerHTML = id + " de " + (ft_thumbs.length-1);
	parent.document.getElementById("legenda").innerHTML = unescape(ft_legendas[ id ]);
	parent.document.getElementById("creditos").innerHTML = ft_creditos[ id ];

	fotoAtual = id;
}

function navegacao(dir) {
	if(dir == ">" && fotoAtual < (ft_thumbs.length - 1)) {
		if(fotoAtual%limiteMax == 0 && fotoAtual < (ft_thumbs.length-1)) {
			mudaSessao(dir, 1);
		} else {
			fotoAtual++;
		}	
	} else if(dir == "<" && fotoAtual > 1) {
		if(fotoAtual%limiteMax == 1 && fotoAtual > 1) {
			mudaSessao(dir, 1);
		} else {
			fotoAtual--;
		}	
	}
	mostraImagem(fotoAtual);
}