var arrFotos = new Array();
var arrLegendas = new Array();
var intervId = 0;

function showFoto(index){
	document.getElementById('foto').src = arrFotos[index];
	try{
		if(arrLegendas[index] != null)
			document.getElementById('legenda').innerHTML = arrLegendas[index];
	}catch(e){}
	if(arrLegendas[index] == null || arrLegendas[index] == "null") arrLegendas[index] = "";
	document.getElementById('foto').alt = arrLegendas[index];	
	
	try{
		document.getElementById('contagem').innerHTML = (parseInt(index) + 1);
	}catch(e){}
}

function nextFoto(){
	next_index = parseInt(document.getElementById('index').value) + 1;
	
	if(next_index > document.getElementById('n_fotos').value - 1){
		next_index = 0;
	}
	
	if(next_index <= document.getElementById('n_fotos').value - 1){
		showFoto(next_index);
		document.getElementById('index').value = next_index;
	}

	stopSlideShow();
}

function previousFoto(){
	previous_index = parseInt(document.getElementById('index').value) - 1;
	n_fotos = document.getElementById('n_fotos').value;
	
	if(previous_index < 0){
		previous_index = n_fotos - 1; 
	}
	
	if(previous_index >= 0){
		showFoto(previous_index);
		document.getElementById('index').value = previous_index;
	}
	
	stopSlideShow();
}

function startSlideShow(){
	if (intervId == 0){
		intervId = self.setInterval('slidePic()', 3000);
		document.getElementById("bot_slideshow").innerHTML = "<input type='submit' id='link_slide' onClick='stopSlideShow();' value='slide show [||]' />";
		
	}
}
																				
function stopSlideShow(){
	if (intervId != 0){
		self.clearInterval(intervId);
		document.getElementById("bot_slideshow").innerHTML = "<input type='submit' id='link_slide' onClick='startSlideShow();' value='slide show [»]' />";
		intervId = 0;
	}
}																							


function slidePic() { 
	if (document.getElementById('index').value >= arrFotos.length -1 )
		document.getElementById('index').value = -1;
		
	next_index = parseInt(document.getElementById('index').value) + 1;
	showFoto(next_index);
	document.getElementById('index').value = next_index;
}
