// JavaScript Document
$(function() {

	//	Basic carousel
	$('#foo0').carouFredSel();
	
	//	Basic carousel + timer
	$('#foo1').carouFredSel({
		auto: {
			pauseOnHover: 'resume',
			onPauseStart: function( percentage, duration ) {
				$(this).trigger( 'configuration', ['width', function( value ) { 
					$('#timer1').stop().animate({
						width: value
					}, {
						duration: duration,
						easing: 'linear'
					});
				}]);
			},
			onPauseEnd: function( percentage, duration ) {
				$('#timer1').stop().width( 0 );
			},
			onPausePause: function( percentage, duration ) {
				$('#timer1').stop();
			}
		}
	});
	
	//	Scrolled by user interaction
	$('#foo2').carouFredSel({
		prev: '#prev2',
		next: '#next2',
		pagination: "#pager2",
		auto: false
	});
	
	//	Variable number of visible items with variable sizes
	$('#foo3').carouFredSel({
		width: 360,
		height: 'auto',
		scroll: 1,
		next: '#next3',
		prev: '#prev3',
		auto: false
	});
	
	//	Fluid layout examples
	$('#fooF0').carouFredSel({
		items: {
			visible: 1,
			width: 'variable'
		}
	});
	
	$(window).resize(function() {
		var newWidth = $(window).width();
	
		$('#fooF0').width( newWidth * $('#fooF0').children().length ); // set width of carousel, to ensure the items fit next to eachother
		$('#fooF0').parent().width( newWidth ); // set width of carousel-wrapper
		$('#fooF0').children().width( newWidth - 22 ); // set width of items, -22px for border and margin
	
		$('#fooF1').carouFredSel({
			width: newWidth,
			scroll: 2
		});
	}).resize();
	
	/* Lightbox */
	 $('#gallery a').lightBox();
	
	
	/* Mascara */
	$('#formPedido .mask-fone').mask('(99) 9999-9999'); // Telefone
	$('#form .mask-fone').mask('(99) 9999-9999'); // Telefone
	$('#formPedido .mask-cpf').mask('999.999.999-99'); // CPF
	$('#formPedido .mask-cnpj').mask('99.999.999/9999-99'); // CNPJ
	
	
	/* Validador */
	$("#pagSeguro").click(function(){
		$("#formPedido .formaPagamento").attr("value", "pagSeguro");
	});
	
	$("#boleto").click(function(){
		$("#formPedido .formaPagamento").attr("value", "boleto");
	});
	
	$.validator.setDefaults({
		submitHandler: function() {	document.formPedido.submit(); }
	});
	
	$("#formPedido").validate({
		
		errorLabelContainer: $("#formPedido div.error"),
		
		rules: {
			
			nome: "required",
			cpf: "required",
			email: {
				required: true,
				email: true
			},
			login: {
				required: true,
				minlength: 5,
				maxlength: 20
			},
			senha: {
				required: true,
				minlength: 5
			},
			senha2: {
				required: true,
				minlength: 5,
				equalTo: "#senha"
			},
			telefone: "required",
			termo: "required"
		},
		messages: {
			
			nome: "Preencha o nome completo",
			cpf: "Preencha o CPF corretamente",
			email: "Preencha o e-mail corretamente",
			login: {
				required: "Preencha o campo login",
				minlength: "Login deve ter pelo menos 5 caracters",
				maxlength: "Login deve ter até 20 caracters"
			},
			senha: {
				required: "Preencha a senha",
				minlength: "Sua senha deve ter no mínimo 5 caracteres"
			},
			senha2: {
				required: "Preencha a confirmação de senha",
				minlength: "Sua senha deve ter no mínimo 5 caracteres",
				equalTo: "Preencha com a mesmo senha acima"
			},
			telefone: "Preencha o telefone corretamente",
			termo: "Aceite nossos termos de uso"
			
		}
	});
	
});
	

function carrega(pagina, container)
{			
	//$(container).fadeOut(0);
	$(container).load(pagina);
	//$(container).fadeIn(1000);
	return false;
}

function escolhePessoa(tipo)
{
	if (tipo == 'fisica'){
		$(".bloco_cpf").css("display","block");
		$(".bloco_razao").css("display","none");
		$(".bloco_cnpj").css("display","none");
	}
	else
	{
		$(".bloco_cpf").css("display","none");
		$(".bloco_razao").css("display","block");
		$(".bloco_cnpj").css("display","block");
	}	
}

function exibeErro(erro)
{
	alert(erro);
	$("#form .error").text(erro);	
}
