String.prototype.trim = function(){return(this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, ""))}
String.prototype.startsWith = function(str){return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str){return (this.match(str+"$")==str)}

function computeCertifica () {
	var f = document.getElementById('certifica');
	f.src = f.src;
}

function carregaFoto(f) {

	if(f != "") {
		var imagem = "<div id=\"imgGrande\"><img src='{nome_imagem}' border=0 id='{cod}' class='imgGaleria' style='max-width: 506px;'></div></br>";
		imagem     += "<div id=\"credito\"></div><br>";
		imagem     += "<div id=\"galeria-topo\"><img src=\"/_arquivos/galerias/spacer.gif\" width=\"574\" height=\"8\" border=\"0\"></div>";
        imagem     += "<div id=\"galeria-centro\"><p class=\"texto\">{legenda}</p></div>";
		imagem     += "<div id=\"galeria-rodape\"><img src=\"/_arquivos/galerias/spacer.gif\" width=\"574\" height=\"8\" border=\"0\"></div>";

		var nome = new String();
		nome = f.split("g");
		var aux = nome[1];
		var img = foto[aux-1].split("|");
		var mostra_id      = imagem.replace("{cod}",nome[1]);
		var mostra_foto    = mostra_id.replace("{nome_imagem}", ((img[2].startsWith("http://")) ? img[2] : "http://casa.abril.com.br/" + img[2]));
		var mostra_credito = mostra_foto.replace("{alt}",img[3]);
        var mostra_tudo    = mostra_foto.replace("{legenda}", img[4]);
		document.getElementById("fotogaleria").innerHTML = mostra_tudo;
        document.getElementById("fotoNumber").innerHTML = "Foto " + aux + " de " + foto.length;
		var escolhido = "#img"+aux;
		$(".imagem").css("border","0");
		$(".imagem").css("margin","2px");
		$(escolhido).css("margin","0");
		$(escolhido).css("border","2px solid #c4151c");
		
	}else {
		var imagem = "<div id=\"imgGrande\"><img src='{nome_imagem}' border=0 class='imgGaleria' id='1' class='imgGaleria' style='max-width: 506px;'></div><br />";
        imagem     += "<div id=\"credito\"></div><br>";
		imagem     += "<div id=\"galeria-topo\"><img src=\"/_arquivos/galerias/spacer.gif\" width=\"574\" height=\"8\" border=\"0\"></div>";
        imagem     += "<div id=\"galeria-centro\"><p class=\"texto\">{legenda}</p></div>";
		imagem     += "<div id=\"galeria-rodape\"><img src=\"/_arquivos/galerias/spacer.gif\" width=\"574\" height=\"8\" border=\"0\"></div>";
		var img = foto[0].split("|");

		var mostra_foto    = imagem.replace("{nome_imagem}", ((img[2].startsWith("http://")) ? img[2] : "http://casa.abril.com.br/" + img[2]));
		var mostra_credito = mostra_foto.replace("{alt}",img[3]);
        var mostra_tudo    = mostra_foto.replace("{legenda}", img[4]);
		document.getElementById("fotogaleria").innerHTML = mostra_tudo;
        document.getElementById("fotoNumber").innerHTML = "Foto 1 de " + foto.length;
	}

 	function remove(str, sub) {
		  i = str.indexOf(sub);
		  r = "";
		  if (i == -1) return str;
		  r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
		  return r;
	}


	var here = "";
	here =location.href;
	var folder = here.split(".com.br/");
	var filename = here.split("/");
	filename2 = (filename[filename.length-1]);
	filename3 = remove(filename2,".shtml");
	var folder2 = here.split(".shtml");
	var aux_path = folder2[0].split(".com.br");
	var path = remove(aux_path[aux_path.length-1],filename3);
	
	
	pageTracker._trackPageview('/galeriafotos'+path);
	
}


function next()
{
	var aux = $(".imagem").attr('id');

	var i = aux.split("g")[1];
	var next;
	(parseInt(i)+5)<= foto.length ? next = parseInt(i)+5 : next = foto.length;

	while(next%5!=0 && next!=foto.length)
		next++;
	mostra_pequenas(next);

}

function back()
{
	var aux = $(".imagem").attr('id');


	var i = parseInt(aux.split("g")[1])+4;
	var back;
	(parseInt(i)-5)> 0 ? back = parseInt(i)-5 : back = 1;
	/*while(back%5!=0 && back!=i)
		next++;*/

	if(back==1)
		back=5;
	mostra_pequenas(back);

}


function mostra_pequenas(max) {
	var i;
	var resultado = "";

	for(max-5<=0? i=0 : i = max-5; i < max; i++) {
		var img  = foto[i].split("|");
		var imagem         = "<div class='box_imagem'><a href=\"javascript:carregaFoto(\'"+img[0]+"\');\"><img src='{url_p}'";
			imagem        += "id='{pic}' class='imagem' border='0' width='85' height='85'";
		    imagem        += "'></a>{chamada}</div>";
			
		/*var imagem         = "<div class='box_imagem'><img src='{url_p}' onclick=\"carregaFoto(\'";
		    imagem        += img[0];
			imagem        += "\');\"' id='{pic}' class='imagem' border='0' width='85' height='85'";
		    imagem        += "'>{chamada}</div>";*/
		var mostra_foto    = imagem.replace("{pic}",img[0]);
        var mostra_chamada = mostra_foto.replace("{chamada}", img[5]);
		var mostra_tudo    = mostra_chamada.replace("{url_p}", ((img[1].startsWith("http://")) ? img[1] : "http://casa.abril.com.br/" + img[1]));
        resultado += mostra_tudo;
		
		
		
		
	}


	$(".area-scroll").html(resultado);
}