
var randon = Math.random()*galeria.length;
var atual = Math.floor(randon);

function next()
{
	atual = parseInt(atual+1);
	total = parseInt(galeria.length-1);
	if(atual > total) atual = 0;
	mostra(atual);
	legenda(atual);
	botoes(atual);
}

function previous()
{
	atual = parseInt(atual-1);
	total = parseInt(galeria.length-1);
	if(atual < 0) atual = total;
	mostra(atual);
	legenda(atual);
	botoes(atual);
}

function play()
{
	atual = parseInt(atual+1);
	total = parseInt(galeria.length-1);
	if(atual > total) atual = 0;
	mostra(atual);
	legenda(atual);
	botoes(atual);
}			

function botoes(atual)
{

	var ultima = atual+1;

	document.getElementById('galeriaNavegacaoProxima').innerHTML = '<a href="javascript:next();" title="Próxima Foto"><img src="images/bt-galeria-proximo.gif" width="18" height="19" alt="Próxima Foto" title="Próxima Foto" /></a>';
	/*
	if(ultima>=galeria.length) 
	{
		document.getElementById('galeriaNavegacaoProxima').innerHTML = '<img src="images/bt-galeria-proximo-off.gif" width="18" height="19" alt="Próxima Foto" title="Próxima Foto" />';
	} else {
		document.getElementById('galeriaNavegacaoProxima').innerHTML = '<a href="javascript:next();" title="Próxima Foto"><img src="images/bt-galeria-proximo.gif" width="18" height="19" alt="Próxima Foto" title="Próxima Foto" /></a>';
	}
	*/
		document.getElementById('galeriaNavegacaoAnterior').innerHTML = '<a href="javascript:previous();" title="Foto Anterior"><img src="images/bt-galeria-anterior.gif" width="18" height="19" alt="Foto Anterior" title="Foto Anterior" /></a>';
	/*
	if(atual==0)
	{
		document.getElementById('galeriaNavegacaoAnterior').innerHTML = '<img src="images/bt-galeria-anterior-off.gif" width="18" height="19" alt="Foto Anterior" title="Foto Anterior" />';
	} else {
		document.getElementById('galeriaNavegacaoAnterior').innerHTML = '<a href="javascript:previous();" title="Foto Anterior"><img src="images/bt-galeria-anterior.gif" width="18" height="19" alt="Foto Anterior" title="Foto Anterior" /></a>';
	}
	*/			
}

function reverse()
{
	atual = parseInt(atual-1);
	total = parseInt(galeria.length-1);
	if(atual < 0) atual = total;
	mostra(atual);
}

function mostra(indice)
{
	var galeriaSplited = galeria[indice].split('|');
	document.getElementById('galeriaImagem').innerHTML = '<img src="'+galeriaSplited[0]+'" alt="'+galeriaSplited[1]+'" title="'+galeriaSplited[1]+'">';
}

function legenda(valor)
{
	var valor = valor+1;
	var tudo =  galeria.length;
	document.getElementById('galeriaNavegacao').innerHTML = valor+'/'+tudo;
}