// JavaScript Document
var arrayMini = new Array
var arrayMax = new Array
function trocaFoto(id)
{
	imagem = aryImages[id];
	
	//imagem_maior = imagem.replace("produto_normal","produto_grande");
	document.getElementById("img_principal").src = aryImages[id];
	if ( arrayMax[id] && arrayMax[id] != "#" )
	{
		
		document.getElementById("link_imagem").href = arrayMax[id];
		document.getElementById("link_imagem2").href = arrayMax[id];
		
	}
	
	img_mini = document.getElementById(id);
	if( arrayMini.length == 4)
	{
		if(id == 0)
		{
		
			document.getElementById("0").src = 	arrayMini[0]
			document.getElementById("0").alt = "1"
			document.getElementById("0").onclick = function(){ trocaFoto(this.alt) }		
			document.getElementById("1").src = 	arrayMini[2]
			document.getElementById("1").alt = "2"
			document.getElementById("1").onclick = function(){ trocaFoto(this.alt) }
		}
		else
		{
			if(id == 1)
			{
				document.getElementById("0").src = 	arrayMini[0]
				document.getElementById("0").alt = "0"
				document.getElementById("0").onclick = function(){ trocaFoto(this.alt) }		
				document.getElementById("1").src = 	arrayMini[2]
				document.getElementById("1").alt = "2"
				document.getElementById("1").onclick = function(){ trocaFoto(this.alt) }	
			}
			else
			{
				document.getElementById("0").src = 	arrayMini[0]
				document.getElementById("0").alt = "0"
				document.getElementById("0").onclick = function(){ trocaFoto(this.alt) }		
				document.getElementById("1").src = 	arrayMini[1]
				document.getElementById("1").alt = "1"
				document.getElementById("1").onclick = function(){ trocaFoto(this.alt) }	
			}
		}
		contImg = 0;
		for (i=0; i < arrayMini.length-1; i++)
		{
			
			if(arrayMini[i] != img_mini.src)
			{
				
				if( contImg == 0)
				{
					elementImg = document.getElementById("0")
				}
				else
				{
					elementImg = document.getElementById("1")	
				}
				elementImg.src = arrayMini[i];
				//elementImg.id = contImg;	
				//numFoto.src = arrayMini[i]
				//elementImg.onclick = function(){ trocaFoto(this.id) }		
				//div_principal.appendChild(numFoto);	
				contImg = parseInt(contImg) + 1;
			}
		}
		
	}
	
	classImg = img_mini.className;
	
	for (i=0; i < arrayMini.length-1; i++)
	{
		if(i == id)
		{
			document.getElementById(i).className = "borda_cinza";	
		}
		else
		{
			document.getElementById(i).className = "borda_branca";
		}
	}
}
function carregaVetor()
{
	
	foto = document.getElementById("tfotos").value;
	fot = foto.split("|");
	arrayMini = document.getElementById("tfotosMini").value.split("|")
	arrayMax = document.getElementById("tfotosMax").value.split("|")
	qtd =  fot.length;
	
	var array = new Array(qtd);
	for (i=0;i < qtd-1;i++)
	{										
		array[i] = fot[i];			
	}
	
	loadImagens(array);
	if (arrayMini.length == 4)
	{
		contImg = 0;
		alturaMax = 0;
		for (i=0; i < arrayMini.length-1; i++)
		{
			
			if(aryImages[i] != document.getElementById("img_principal").src)
			{
				var div_principal = document.getElementById("miniaturas")
				var numFoto = document.createElement("img");
				if( i == 0)
				{
					numFoto.className = "borda_cinza";
				}
				else
				{
					numFoto.className = "borda_branca";	
				}
				
				numFoto.id = contImg;	
				numFoto.alt = i;
				numFoto.src = arrayMini[i]
				numFoto.onclick = function(){ trocaFoto(this.alt) }		
				div_principal.appendChild(numFoto);	
			
				contImg = parseInt(contImg) + 1;
				
			}
			
		}
	}
	else
	{
		for (i=0; i < arrayMini.length-1; i++)
		{
			var div_principal = document.getElementById("miniaturas")
			var numFoto = document.createElement("img");
			if( i == 0)
			{
				numFoto.className = "borda_cinza";
			}
			else
			{
				numFoto.className = "borda_branca";	
			}
			
			numFoto.id = i;	
			numFoto.src = arrayMini[i]
			numFoto.onclick = function(){ trocaFoto(this.id) }		
			div_principal.appendChild(numFoto);	
		}
	}
	
	
	
}
function loadImagens(arrayImages)
{
	qtdeImages = arrayImages.length;
	aryImages = arrayImages;
	for (i=0; i < arrayImages.length; i++)
	{
		var preload = new Image();
		preload.src = arrayImages[i];
	}
	
}

function trocarFoco(id,numero,idMudar)
{
	src = document.getElementById(id);
	if ( src.value.length == numero)
	{
		obj = document.getElementById(idMudar)
		if(obj)
		{
			obj.focus();	
		}
	}  	
}

