// JavaScript Document

function slideSwitch(prox) {
	
	//Retiramos last active
	$('#banner .last-active').removeClass('last-active');
	
	var $active = $('#banner .active');
	$active.addClass('last-active');
	
	//Próximo
	var proximo = '#img'+prox;
	
	if($(proximo)[0]) {
		var $next = $(proximo);
	} else {
		var $next =  $active.next().length ? $active.next() : $('#banner .item:first');
	}
		
	//Retiramos a hint
	$("#bn-infos a.checked").removeClass('checked');
		
	//Inserimos no proximo
	var nextinfo = $next.attr('rel');
	$("#bn-infos  #link"+nextinfo).addClass('checked');
		
	//Proximo
	$next.css({opacity: 0.0})
	.addClass('active')
	.animate({opacity: 1.0}, 1000, function() {
		$active.removeClass('active last-active');
	});
	
}

//Instanciamos a variavel
var fadebanner;

$(document).ready(function(){
	
	fadebanner = setInterval("slideSwitch('')", 8000 );
	
	$("#banner #bn-infos a").click(function(){
		var alvo = $(this).attr("rel");
		
		clearInterval(fadebanner);
		slideSwitch(alvo);
		
		fadebanner = setInterval("slideSwitch('')", 8000 );
		return false;		
	});
	
});
	
