// JavaScript Document
$(document).ready(function(){
	$('#texto_certificado').hide();
	var intervalo;
	var intervalo2;
	var tempo = 0;
	$('#botoes img:gt(0)').css({
		opacity:'0.5'
	});
	$('#botoes img').css({
		cursor:'pointer'
	});
	$('#banner a img').each(function(){
		$('<p/>').html($(this).attr('alt')).appendTo('#linha');
	})
	$('#banner a img, #linha p, #botoes img').hide();
	$('#linha').css('width','0px')
	var i = 0;
	var j = $('#banner a').length-1;
	$('#botoes img').click(function(){
		clearInterval(intervalo);
		clearInterval(intervalo2);
		$('#banner a:eq('+i+') img').fadeOut(600);
		$('#botoes img:eq('+i+')').fadeTo(600,0.5);
		$('#linha p:eq('+i+')').fadeOut(600);
		i = $(this).index();
		if (i == 3) {
			tempo = 7000;
			$('#texto_principal').fadeOut(function(){
				$('#texto_certificado').fadeIn();
			})
		} else {
			tempo = 0;
			$('#texto_certificado').fadeOut(function(){
				$('#texto_principal').fadeIn();
			})
		}
		$('#banner a:eq('+i+') img').fadeIn(600);
		$('#botoes img:eq('+i+')').fadeTo(600,1);
		$('#linha p:eq('+i+')').fadeIn(600);
		invtervalo2 = setTimeout(function(){
			interval();
		},tempo);
	})
	function interval(){
		intervalo = setInterval(function(){
			$('#banner a:eq('+i+') img').fadeOut(600);
			$('#botoes img:eq('+i+')').fadeTo(600,0.5);
			$('#linha p:eq('+i+')').fadeOut(600);
			if (i+1 > j) {
				i = 0;
			} else {
				i++;
			}
			if (i == 3) {
				clearInterval(intervalo);
				$('#texto_principal').fadeOut(function(){
					$('#texto_certificado').fadeIn();
				})
				intervalo2 = setTimeout(function(){
					interval();
				},7000);
			} else {
				$('#texto_certificado').fadeOut(function(){
					$('#texto_principal').fadeIn();
				})
			}
			$('#banner a:eq('+i+') img').fadeIn(600);
			$('#botoes img:eq('+i+')').fadeTo(600,1);
			$('#linha p:eq('+i+')').fadeIn(600);
		},3000);
	}
	$('#linha').css('cursor','pointer').click(function(){
		window.location.href = $('#banner a:eq('+i+')').attr('href');
	})
	$('#banner img:eq(0)').fadeIn(600,function(){
		$('#botoes img:eq(0)').fadeIn(300,function(){
			$('#botoes img:eq(1)').fadeIn(300,function(){
				$('#botoes img:eq(2)').fadeIn(300,function(){
					$('#botoes img:eq(3)').fadeIn(300,function(){
						$('#linha').animate({
							width:'474px'
						},600,function(){
							$('#linha p:eq(0)').fadeIn(300,function(){
								interval();
							});
						})
					})
				});
			});										   
		});
	});
	//interval();
})

