//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 = 0; //quantidade de imagens a ser mostradas, menos 1, ou seja, este exemplo mostra 4 - 1 = 3
qtimg = 0;
//img_proximo="off";
//img_anterior="off";
//img_anima="stop";
//txt_anima="Parar";
img_proximo="on";
img_anterior="off";
img_anima="play";
txt_anima="Animar";
function slide_show(qtimagem) {
	//indice = qtimagem;
	indice = (img_anima=="stop")?qtimagem:0;
	qtimg = qtimagem;
	mostra_slide();
}

function mostra_slide() {
	if (img_anima == "stop") {
		indice = (indice == qtimg) ? 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 = busca_slide;
		ajax.open('post','ajax/busca.php',true);
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		var parametros = 'posicao='+indice;
		ajax.send(parametros);
	}
}

function busca_slide() {
	var camada = document.getElementById('mostra_imagem');
	if(ajax.readyState==1) {
		camada.className = 'visible';
		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>';
	} else if(ajax.readyState==4) {
		if(ajax.status==200) {
			camada.innerHTML = ajax.responseText;
			if (img_anima == "stop")
				setTimeout("mostra_slide()",5000);
		}
	}
}

function proximo() {
	if ((img_anima == "play") && (indice < qtimg)) {
		indice = indice + 1;
		img_proximo = (indice == qtimg) ? 'off' : 'on';
		img_anterior = (indice == 0) ? 'off' : 'on';
		mostra_slide();
	}
}

function anterior() {
	if ((img_anima == "play") && (indice > 0)) {
		indice = indice - 1;
		img_proximo = (indice == qtimg) ? 'off' : 'on';
		img_anterior = (indice == 0) ? 'off' : 'on';
		mostra_slide();
	}
}
function anima() {
	if (img_anima == "stop") {
		img_anima = "play";
		txt_anima = "Animar";
		img_proximo = (indice == qtimg) ? '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";
		mostra_slide();
	}
}
