/** Funções em jQuery - A GERADORA
 * Desenvolvedor: Hilder Santos
**/

// Função para resetar os formulários
jQuery.fn.extend({
opacidade: function(opacidade, tempo){
if (tempo == null) {
	tempo = 0;
}
this.animate({'opacity': opacidade}, tempo)
}
});

jQuery(document).ready(function(){
						   
// Validação dos Formulários

// Validação do formulário da proposta
	var form = false;	
	jQuery("#frmFaleConosco").bind("submit", function(e){
		var ipt_nome = jQuery('#Nome', this).val();
		var ipt_email = jQuery('#Email', this).val();
		var ipt_telefone = jQuery('#Telefone', this).val();
		var ipt_filial = jQuery('#Filial', this).val();
		var ipt_mensagem = jQuery('#Mensagem', this).val();
		var msgForm = "";
		jQuery(".obrigatorio, #Filial").each(function() {
				jQuery(this).removeClass("naopreenchido");
				
				if(jQuery.trim(jQuery(this).val()) == "") {
				jQuery(this).addClass("naopreenchido");				
				form = true;
			}	else {
			form = false;
			} 		
		});	
		 if (form == true) {
			 msgForm += "- Existem campos obrigatórios não preenchidos!\n";
		}
		var email = jQuery('#Email',this).val();
		if(email.indexOf("@") == -1 || email.indexOf(".") == -1) {
			msgForm += "- O Email digitado é inválido.\n";
			jQuery('#Email',this).addClass("naopreenchido");
		}
		if(jQuery('#Filial', this).val() == 'padrao') {
			msgForm += "- Por favor, selecione uma filial.\n";
			jQuery('#Filial',this).addClass("naopreenchido");
		}
		if(msgForm != "") {
			alert(msgForm);
			jQuery(".naopreenchido:first").focus();
		//	e.preventDefault();
		} else {
			jQuery('#frmFaleConosco').before('<p class="msg_aguarde">Aguarde, enviado sua mensagem...</p>');
			// Se o formulário foi enviado com sucesso
			jQuery.post(html+'sendmail.php', {Filial: ipt_filial,  Nome: ipt_nome, Email: ipt_email, Telefone: ipt_telefone, Mensagem: ipt_mensagem}, function() {
				// alert('Mensagem enviada com sucesso!');
				jQuery('.msg_aguarde').html('Mensagem enviada com sucesso!');
				jQuery('#frmFaleConosco').each(function() {this.reset();});
			});
		}
	e.preventDefault();
	});
	

	
						   
	/*jQuery('body').fadeOut(0);
	jQuery('body').fadeIn('normal');
	
	jQuery('a').each(function(){
		jQuery(this).click(function(){
			var lnk = jQuery(this).attr('href');
			jQuery(this).removeAttr('href');
			jQuery('body').fadeOut('normal', function(){ window.location=lnk; });
	   });
	});*/
	
	//Aplico as bordas sombreadas nos blocos
	/*jQuery('.BlocoParafusos').each(function(){
		var iHtml 		= jQuery(this).html();
		var bTop 		= "<span class=\"bdr bdrTop\">&nbsp;</span>";
		var bBot 		= "<span class=\"bdr bdrBot\">&nbsp;</span>";
		var parafusos	= "<br /><span class=\"parafuso pTopL\">&nbsp;</span><span class=\"parafuso pTopR\">&nbsp;</span><span class=\"parafuso pBotL\">&nbsp;</span><span class=\"parafuso pBotR\">&nbsp;</span>";
		
		jQuery(this).html(bTop+iHtml+bBot+parafusos);
	});*/
	//---------------------------------------
	//Menu
	
	var tMenu = 0;
	jQuery('#Menu > ul > li').each(function(){
		tMenu++;
		jQuery(this).children('a').addClass("bt00"+tMenu);
	});
	
	jQuery('#Menu > ul > li:last').addClass('last');
	
	jQuery('#Menu ul li:has(ul) ul').each(function(){
											  
		jQuery(this).children('li:first').css({'padding-left':0});		
		jQuery(this).children('li:last').css({'border-left':0});
		
	});
	
	jQuery('.setaMenu').hide();
	
	jQuery('#Menu > ul > li').hoverIntent(function(){
		jQuery(this).children('ul').fadeIn('fast');
		
		p = (this.offsetLeft+jQuery(this).width()/2)-8;
		jQuery('.setaMenu').css({'left':p+'px'});
		
		jQuery('.setaMenu').fadeIn('fast');
	},
	function(){
		jQuery(this).children('ul').fadeOut('fast');
		
		jQuery('.setaMenu').fadeOut('fast');
	});	
	
	/*jQuery('#Menu').mousemove(function(e){
		n = jQuery(this).parent().get(0).offsetLeft;
		jQuery('.setaMenu').css({'left':(e.pageX-n)+'px'});
	});*/
	
	//-----------------------------------------
	//Scroll
	
	var scrHtml = jQuery('#ScrollClientes').html();
	var fades	= "<span class=\"fadeLeft\">&nbsp;</span><span class=\"fadeRight\">&nbsp;</span>";
	
	jQuery('#ScrollClientes').html(fades+scrHtml);
	
	jQuery('#ScrollClientes ul li:first').css({'margin-left':0});
	jQuery('#ScrollClientes ul li:last').css({'margin-right':0});
	jQuery('#ScrollClientes').SlideMenu({orientation: 'horizontal', scrSpeed: 80, elementFather: '#Geral'});
	
	jQuery('.scrLeft').click(function(){
		l = jQuery('#ScrollClientes ul').css('left');
		l = l.substr(0, l.length-2);
		
		if (l > -260) {
			l-=50;
			jQuery('#ScrollClientes ul').animate({'left': l}, 300);
		}
	});
	
	jQuery('.scrRight').click(function(){
		l = jQuery('#ScrollClientes ul').css('left');
		l = l.substr(0, l.length-2);
		l = Number(l);
		
		if (l <= -50) {
			l+=50;
			jQuery('#ScrollClientes ul').animate({'left': l}, 300);
		}
	});
	
	//-----------------------------------------
	
	//Topo
	jQuery(".btTopo").click(function () {
		jQuery('html,body').animate({scrollTop: 0});
	});
	
	jQuery('.BtsBottom').each(function(){	
		
		pos = this.offsetTop;
		
		jQuery(this).parent().parent().parent().each(function(){
			pos+=this.offsetTop;
		});
		
		if (jQuery(window).height() > pos) {
			jQuery(this).hide();
		}
  	});
	
	//--------
	
	//Box Descricao Marcas
	jQuery('body').append("<div class=\"BoxDesc\"><span class=\"seta\">&nbsp;</span><span class=\"conteudo\">Esse é o nome da empresa.</span></div>");
	jQuery('.BoxDesc').hide();
	jQuery('body').mousemove(function(e){
												   
	    jQuery(this).children('.BoxDesc').css({'left':(e.pageX-25)+'px', 'top':(e.pageY+2)+'px'});

	});
	
	jQuery('#ScrollClientes ul li img').each(function(){
		jQuery(this).attr('nome', jQuery(this).attr('title'));
		
		jQuery(this).removeAttr('title');
		jQuery(this).removeAttr('alt');
	});
	
	jQuery('#ScrollClientes ul li').hoverIntent(function(){
													
		nome = jQuery(this).children('img').attr('nome');
		
		jQuery('.BoxDesc .conteudo').text(nome);
		
		jQuery('.BoxDesc').fadeIn('normal');
	},
	function(){
		
		jQuery('.BoxDesc').fadeOut('fast');
	});
	
	
  jQuery(document).ready(function(){
		jQuery('#esp').hide();
		jQuery("#Nascimento").mask("99/99/9999",{placeholder:" "});
		jQuery("#Telefone,#Celular").mask("(99)9999-9999",{placeholder:" "});
		
    	//jQuery("#frmCurriculo").validate();
	var container = jQuery('div.container');
	// validate the form when it is submitted
	var validator = jQuery("#frmCurriculo").validate({
		errorContainer: container,
		errorLabelContainer: jQuery("ol", container),
		wrapper: 'li',
		meta: "validate"
	});
	jQuery('#esp_sim').click(function(){
		jQuery('#esp').show();
		jQuery('#especifique').addClass("{validate:{required:true}}");
	});
	jQuery('#esp_nao').click(function(){
		jQuery('#esp').hide();
		jQuery('#especifique').removeClass("{validate:{required:true}}");
	});
	});
  
});
