//inicia ajax
function inicia_ajax() {
	ajax = null;
	if(window.XMLHttpRequest) { // Mozilla, Safari,...
		ajax = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) { // IE
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e) {
				ajax = null;
				//retorno_abre('formulario','Não foi possível carregar o AJAX!');
				alert('Não foi possível carregar o AJAX');
			}
		}
	}
}

indice=6; //quantidade de imagens a ser mostradas, menos 1, ou seja, este exemplo mostra 4 - 1 = 3
img_proximo="off";
img_anterior="off";
img_anima="stop";
txt_anima="Parar";
function slide_show() {
   if (img_anima == "stop")
		indice = (indice == 6) ? 0 : indice+1;
	//---------------------------------------
	var camada1 = document.getElementById('mostra_imagem');
	var camada2 = document.getElementById('controle_imagem');
	camada1.className = 'hidden';
	camada1.innerHTML = '';
	camada2.innerHTML = '<table width="224" cellpadding="0" cellspacing="0"><tr><td class="video2" align="center" valign="top"><input type="image" name="btn1" src="imagens/prior1_'+img_anterior+'.jpg" width="30" height="25" border="0" alt="Anterior" onclick="anterior();"></td><td align="center" valign="top" class="video2"><input type="image" name="btn2" src="imagens/'+img_anima+'1.jpg" width="30" height="25" border="0" alt="'+txt_anima+'" onclick="anima();"></td><td align="center" valign="top" class="video2"><input type="image" name="btn3" src="imagens/next1_'+img_proximo+'.jpg" width="30" height="25" border="0" alt="Próximo" onclick="proximo();"></td></tr></table>';
	//---------------------------------------
	inicia_ajax();
	if(ajax) {
		ajax.onreadystatechange = mostra;
		ajax.open('post','ajax/busca.php',true);
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var parametros = 'posicao='+indice;
		ajax.send(parametros);
	}
}

function mostra() {
	var camada = document.getElementById('mostra_imagem');
	if(ajax.readyState==1) {
		camada.innerHTML = '<table width="224" height="242" cellpadding="0" cellspacing="0" class="video"><tr><td align="center" valign="middle"><img src="indicator_snake.gif" border="0" alt="carregando..." /></td></tr></table>';
		camada.className = 'visible';
	}
	else if(ajax.readyState==4) {
		if(ajax.status==200) {
			camada.innerHTML = ajax.responseText;
		   if (img_anima == "stop")
				setTimeout("slide_show()",5000);
		}
	}
}
function proximo() {
   if ((img_anima == "play") && (indice < 6)) {
		indice = indice + 1;
		img_proximo = (indice == 6) ? 'off' : 'on';
		img_anterior = (indice == 0) ? 'off' : 'on';
      slide_show();
   }
}
function anterior() {
   if ((img_anima == "play") && (indice > 0)) {
		indice = indice - 1;
		img_proximo = (indice == 6) ? 'off' : 'on';
		img_anterior = (indice == 0) ? 'off' : 'on';
      slide_show();
   }
}
function anima() 
{
	if (img_anima == "stop") {
		img_anima = "play";
      txt_anima = "Animar";
		img_proximo = (indice == 6) ? 'off' : 'on';
		img_anterior = (indice == 0) ? 'off' : 'on';
		var camada = document.getElementById('controle_imagem');
		camada.innerHTML = '<table width="224" cellpadding="0" cellspacing="0"><tr><td class="video2" align="center" valign="top"><input type="image" name="btn1" src="imagens/prior1_'+img_anterior+'.jpg" width="30" height="25" border="0" alt="Anterior" onclick="anterior();"></td><td align="center" valign="top" class="video2"><input type="image" name="btn2" src="imagens/'+img_anima+'1.jpg" width="30" height="25" border="0" alt="'+txt_anima+'" onclick="anima();"></td><td align="center" valign="top" class="video2"><input type="image" name="btn3" src="imagens/next1_'+img_proximo+'.jpg" width="30" height="25" border="0" alt="Próximo" onclick="proximo();"></td></tr></table>';
   }
   else {	  
		img_anima = "stop";
      txt_anima = "Parar";
		img_proximo="off";
		img_anterior="off";
	   slide_show();
   }
}
