/*
 * Scripts específicos desse sistema
 */
$(function(){

	//Links locais rolam de maneira suave
	if(jQuery.isFunction($.localScroll)){
		$.localScroll({'hash': false, 'easing': 'easeOutCubic'});	//localScroll
	}

	//Foco automático no primeiro campo
	$('.form-busca:last').find(':text:first').focus();

	//Adiciona um HOVER nas linhas das tabelas
	$('.tableStyle tr').live('mouseover', function(){
		$(this).addClass('hover');
	});
	$('.tableStyle tr').live('mouseout', function(){
		$(this).removeClass('hover');
	});

	//Máscara
	if( jQuery.isFunction(jQuery.fn.numeric) ) {
		$('input.cpf, input.rg, .numeric').numeric();
	}

	if( jQuery.isFunction(jQuery.fn.mask) ) {
		$('input.telefone').mask("(99) 9999-9999", {placeholder: " "});
		$('input.cep').mask("99999-999", {placeholder: " "});
		$('input.date').mask("99/99/9999", {placeholder: " "});
	}

	//
	//CPF e RG
	//
	if( jQuery.isFunction(jQuery.validator) ) {

		jQuery.validator.addMethod('checkCPF', function(value, element) { 
		  return this.optional(element) || validaCPF(value); 
		}, 'Informe o CPF corretamente');
	
		//Telefone
		jQuery.validator.addMethod("telefone", function(value, element) { 
		  return this.optional(element) || /^(\d{2,3}|\(\d{2,3}\)[ ])?\d{3,4}[-]?\d{3,4}$/.test(value);
		}, "N&uacute;mero de telefone no formato (12) 3456-7890.");
	
		//Para o CEP
		jQuery.validator.addMethod("cep", function(value, element) { 
		  return this.optional(element) || /^\d{5}-\d{3}$/.test(value); 
		}, "Por favor, forne&ccedil;a um cep v&aacute;lido.");
	
		//Validaçao
		jQuery.validator.setDefaults({ 
			'errorLabelContainer': '#lista-erros',
			'onkeyup': false,
			'onclick': true,
			'wrapper': 'li',
			'errorClass': 'erro',
			'errorPlacement': function(error, element) {
				element.addClass('erro');
			}
		});

		//Valida automaticamente formuláiros com essa classe
		$('form.validar').validate();
	}


	/* LightBox */
	if(jQuery.isFunction(jQuery.fn.lightbox)){
		$('.lightbox').lightbox({
			fileLoadingImage : 'css/lightbox/loading.gif',
			fileBottomNavCloseImage : 'css/lightbox/closelabel.gif',
			displayTitle: true,
			fitToScreen: false,
			disableNavbarLinks: true,
			imageClickClose: false
		});
	}

});
