$(function() {

	// Funcao mascara
	var mascaras = new Array('fone', 'cep', 'data', 'cpf', 'hora', 'ano');  
	$.fn.extend({
		mascara: function(type) {
			switch(type) {
				case 'fone': $(this).mask("(99) 9999-9999"); break;
				case 'cep': $(this).mask('99999-999'); break;
				case 'data': $(this).mask('99/99/9999'); break;
				case 'cpf': $(this).mask('999.999.999-99'); break;
				case 'hora': $(this).mask('99:99'); break;
				case 'ano': $(this).mask('9999'); break;
				default:;
			}
		} 
	});
	for (var i in mascaras) {
		$('form .' + mascaras[i]).mascara(mascaras[i]);
	}

	// Filled - Esconde labels, pega valor e preenche inputs
	var $filled = $('.filled');
	$('form').submit(function() {
		$(this).find('.filled').each(function() {
			var $label = $('label[for=' + $(this).attr('id') + ']:not([class~=error])');
			var label_text = $label.text();
			if ($(this).val() == $label.text())
				$(this).val('');
		});
	});
	$filled.each(function() {
		var $label = $('label[for=' + $(this).attr('id') + ']');
		var label_text = $label.text();

		$($label).css('display', 'none');
		if (!$(this).get(0).defaultValue) {
			$(this).addClass('gray');
			if ($(this).get(0).tagName.toLowerCase() != 'select') {
				$(this).val(label_text);
			} else
				$(this).find('option:first').text(label_text);
		}
	});
	$filled.live('focusin', function() {
		var $label = $('label[for=' + $(this).attr('id') + ']');
		$(this).removeClass('gray');
		if ($(this).val() == $label.text())
			$(this).val('');
	});
	$filled.live('focusout', function() {
		var $label = $('label[for=' + $(this).attr('id') + ']')
		if (!$(this).val()) {
			$(this).addClass('gray');
			if ($(this).get(0).tagName.toLowerCase() != 'select')
				$(this).val($label.text());
		}
	});

	// Links Externos
	$('a[rel=external], .target_blank').click(function() {
		window.open($(this).attr('href'));
		return false;
	});

	// Banner
	if ($('body.index').length) {
		$('#banner, #noticias')
			.append($('<a href="#" />').attr('class', 'cycle-prev').append('&lt;'))
			.append($('<a href="#" />').attr('class', 'cycle-next').append('&gt;'));
		$('#banner .cycle').cycle({
			fx: 'fade',
			next: '#banner .cycle-next',
			prev: '#banner .cycle-prev',
			timeout: 3000,
			pause: 1
		});
		$('#noticias .cycle').cycle({
			fx: 'scrollLeft',
			next: '#noticias .cycle-next',
			prev: '#noticias .cycle-prev',
			timeout: 10000,
			pause: 1
		});
	}

	// Abre fancybox para o video
	$("a.youtube").each(function() {
		$(this).fancybox({
			 'padding'             : 0,
			 'autoScale'   : false,
			 'transitionIn'        : 'none',
			 'transitionOut'       : 'none',
			 'title'               : this.title,
			 'width'               : 680,
			 'height'              : 495,
			 'href'                : this.href,
			 'type'                : 'swf',    // <--add a comma here
			 'swf'                 : {'allowfullscreen':'true', 'wmode':'transparent'} // <-- flashvars here
		 });
	}); 

	// Abre fancybox para as fotos
	$("a.img").fancybox({
		'showCloseButton'	: true,
		'titlePosition' 		: 'inside'
	});

	// Carrega menu destaque
	$('#index-video').tabs();

	// Title nossas empresas
	$("#nossas-empresas li").hover(
		function() {
			$(this).find('.title').animate({height: 58}, 100);
		},
		function() {
			$(this).find('.title').animate({height: 25}, 100);
		}
	);

/* FORMS */
	$('#form-fale-conosco').validate({
		rules: {
			nome: 'required',
			email: {required: true, email: true},
			telefone: 'required',
			cidade: 'required',
			mensagem: 'required',
			antispam: 'required',
			antispam: { equalTo: '#captcha' }
		}
	});
	$('#form-trabalhe-conosco').validate({
		rules: {
			nome: 'required',
			email: {required: true, email: true},
			telefone: 'required',
			cidade: 'required',
			mensagem: 'required',
			cargo: 'required',
			empresa: 'required',
			
		}
	});
	$('#form-informativo').validate({
		rules: {
			nome_informativo: 'required',
			email_informativo: {required: true, email: true},
			
		}
	});
});
function upperMe() {
	  var campo = document.getElementById('antispam');
	  var upperCaseVersion = campo.value.toUpperCase();
	  campo.value = upperCaseVersion;
	}
