// JavaScript Document//

//Desenvolvido por: Luiz Alberto Libralon//
//E-mail:luiz.libralon@estudiocurumim.com.br//

// Funcao rotacao de imagens - banner home

var vCurrent = 0;
var vTotal = 0;
var vDuration = 7000;
var intInterval = 0;
var vGo = 0;

jQuery(document).ready(function() {	
	vTotal = $(".banner_slides").children().size() -1;
	$(".banner_info").text($(".banner_slide").children().children().attr("title"));	
	intInterval = setInterval(fnLoop, vDuration);
	
	$("#btn_voltar").click(function() {
		vGo = -1;
		fnChange();
	});
		
	$("#btn_avancar").click(function() {
		vGo = 1;
		fnChange();
	});
});

function fnChange(){
	clearInterval(intInterval);
	intInterval = setInterval(fnLoop, vDuration);
	fnLoop();
}

function fnLoop(){
	if(vGo == -1){
		vCurrent == vTotal ? vCurrent = 0 : vCurrent++;
	} else {
		vCurrent == -1 ? vCurrent = vTotal : vCurrent--;
	}
		
	$("#banner").find(".banner_slide").each(function(i) { 
		if(i == vCurrent){
			$(".banner_info").text($(this).children().children().attr("title"));
			$(this).animate({ opacity: 'show', width: 'show' }, 1000);
		} else {
			$(this).animate({ opacity: 'hide', width: 'hide' }, 1000);
		}
	});
}
