$(document).ready(function(){
	
	//AJAX FORM
	$('.ajaxForm').ajaxForm();
	
	$('#nav li ul').hide();
	$('#nav > li').hover(function(){
		$(this).find('ul').show();
	},function(){
		$(this).find('ul').hide();
	})
	
	//FUNÇÃO VOLTAR
	$('.btBack').click(function(){
		window.history.back();
	})
	
	//ANIMAÇÃO DO PLAY
	$('.play').css({'opacity':0});
	$('.videoGallery a').hover(function(){
		$(this).find('.play').stop().animate({'opacity':1}, 300);
	}, function(){
		$(this).find('.play').stop().animate({'opacity':0}, 300)
	})
	
	//ANIMAÇÃO DO PLAY 2
	$('.playMenor').css({'opacity':0});
	$('.videoGalleryMenor a').hover(function(){
		$(this).find('.playMenor').stop().animate({'opacity':1}, 300);
	}, function(){
		$(this).find('.playMenor').stop().animate({'opacity':0}, 300)
	})	
	
	//APLICANDO MASCARAS PARA OS CAMPOS DOS FORMULÁRIOS
	$(".fone").mask("(099) 9999-9999");
    $(".cpf").mask("999.999.999-99");
    $(".cep").mask("99.999-999");
    $(".rg").mask("9.999.999");
    $(".cnpj").mask("99.999.999/9999-99");
	
	//ENVIO DO FORM DE CONTATO
	/*$('p.log').hide();
	$('#formContato .send').click(function(){
		$('p.log').ajaxStart(function(){
			$(this).fadeIn().html("Mensagem sendo enviada.");
		})
		var nome     = $('#nome').val();
		var email    = $('#email').val();
		var mensagem = $('#mensagem').val();
		//alert(nome)
		//alert(email)
		//alert(mensagem)
		
		$.post("contato_envio.php", { 
				nome:nome, 
				email:email,
				mensagem:mensagem 
				}, 
				function(data){ 
					$('p.log').fadeIn().html(data);
					//$('p.log').delay(5000).fadeOut(); 
				}
		); 
		return false
	})*/
	
	//ENVIO DO FORM DE BANCO DE TALENTOS
	$('.logTalentos').hide();
	$('#formTalentos').submit(function(){
		campos = $(this).serialize();
		$('.logTalentos p').ajaxStart(function(){
			$(this).html("Dados sendo enviados.");
			$('.logTalentos, .ajaxLoader').fadeIn();
		})
		$.post("talentos_envio.php", { 
				campos:campos
				}, 
				function(data){
					if(data=='true'){
						$('input:text, textarea, input:password').each(function(){
							this.value = '';
						});
						$('select').each(function(){
							this.options[0].selected = "true";
						});
						$('.logTalentos p').html('Dados enviados com sucesso');
						$('.ajaxLoader').hide();
					}else{
						$('.logTalentos p').fadeIn().html(data);
						$('.ajaxLoader').hide();
					}
				}
		); 
		return false
	})
	
	
	//ENVIO DO FORM DE BANCO DE TALENTOS
	$('.logTalentos').hide();
	$('#formTalentosUpdate').submit(function(){
		campos = $(this).serialize();
		$('.logTalentos p').ajaxStart(function(){
			$(this).html("Dados sendo enviados.");
			$('.logTalentos, .ajaxLoader').fadeIn();
		})
		$.post("talentos_update.php", { 
				campos:campos
				}, 
				function(data){
					if(data=='true'){
						$('input:text, textarea, input:password').each(function(){
							this.value = '';
						});
						$('select').each(function(){
							this.options[0].selected = "true";
						});
						$('.logTalentos p').html('Dados atualizados com sucesso');
						$('.ajaxLoader').hide();
					}else{
						$('.logTalentos p').fadeIn().html(data);
						$('.ajaxLoader').hide();
					}
				}
		); 
		return false
	})
	//ENVIO DA ATUALIZAÇÃO DO FORM DE BANCO DE TALENTOS
	//$('.logTalentos').hide();
	//$('#formTalentosUpdate').submit(function(){
	//	campos = $(this).serialize();
	//	$('.logTalentos p').ajaxStart(function(){
	//		$(this).html("Dados sendo enviados.");
	//		$('.logTalentos, .ajaxLoader').fadeIn();
	//	})
	//	$.post("talentos_update.php", { 
	//			campos:campos
	//			}, 
	//			function(data){ 
	//				if(data=='true'){
	//					$('.logTalentos p').html('Dados atualizados com sucesso');
	//					$('.ajaxLoader').hide();
	//				}else{
	//					$('.logTalentos p').fadeIn().html(data);
	//					$('.ajaxLoader').hide();
	//					campos = '';
	//				}
	//			}
	//	);
	//	return false
	//})
	
	//ENVIO DO FORM DE FORNECEDORES
	$('.logFornecedores').hide();
	$('#formFornecedores').submit(function(){
		campos = $(this).serialize();
		$('.logFornecedores p').ajaxStart(function(){
			$('.logFornecedores, .ajaxLoader').fadeIn();
			$(this).html("Dados sendo enviados.");
		})
		$.post("fornecedores_envio.php", { 
				campos:campos
				}, 
				function(data){ 
					if(data=='true'){
						$('input:text, textarea, input:password').each(function(){
							this.value = '';
						});
						$('select').each(function(){
							this.options[0].selected = "true";
						});
						$('.logFornecedores p').html('Dados enviados com sucesso');
						$('.ajaxLoader').hide();
					}else {
						$('.logFornecedores p').fadeIn().html(data);
						$('.ajaxLoader').hide();
					}
				}
		); 
		return false
	})
	
	//ENVIO DO FORM DE LOGIN
	$('#formLogin .send').click(function(){
		var username    = $('#username').val();
		var password    = $('#password').val();
		var cpf    		= $('#cpf').val();
		
		$('p.logLogin').hide();
		$.post("talentos_checa_login.php", {
				username:username, 
				password:password,
				cpf:cpf
				}, 
				function(data){					
					if(data=='0'){
						$('p.logLogin').fadeIn().text('Usuario e(ou) Senha Inv\xE1lidos!');
					} else {
						window.location="talentos_form_editar.php?id="+data;
					}
				}
		);
		return false
	})
	
	//ENVIO DA NEWSLETTER
	var fileToSend = $('#boxNewsletter form').attr('action');
	
	$('#boxNewsletter form').attr('action','');
	$('#boxNewsletter form').submit(function(){
		var nome     = $('input[name=nome]').val();
		var email    = $('input[name=email]').val();
		
		$.post(fileToSend, {nome:nome, email:email},
			function(data){					
					$('#boxNewsletter form .log').html(data);
				}
		);
		return false
	})
	
	/*
    * ToggleFormText
    *
    * Author:   Grzegorz Frydrychowicz
    * E-mail:   grzegorz.frydrychowicz@gmail.com
    * Date:     16-11-2007
    */
	$("input:text, textarea, input:password").each(function(){
        if(this.value == '')
            this.value = this.title;
    });
    $("input:text, textarea, input:password").focus(function(){
        if(this.value == this.title)
            this.value = '';
    });
    $("input:text, textarea, input:password").blur(function(){
        if(this.value == '')
            this.value = this.title;
    });
    $("input:image, input:button, input:submit").click(function(){
        $(this.form.elements).each(function(){
            if(this.type =='text' || this.type =='textarea' || this.type =='password' ){
                if(this.value == this.title && this.title != ''){
                    this.value='';
                }
            }
        });
    });
	
});

//CENTRALIZANDO IMAGEM
$(window).load(function(){
	$('.centerV').each(function(){
		var contHeight = $(this).height();	
		var imgHeight  = $(this).find('img').height();
		var cetralizing = ((contHeight-imgHeight)/2);
		$(this).find('img').css({margin:cetralizing+'px 0 0 0'});
	})
})


//INICIANDO O SHADOWBOX
Shadowbox.init();

