

//Funções que inicializam com o Site
$(document).ready(function(){
    
	//Url Padrão do Site
    baseUrl = base_url();
	
	//Plugin de marca d'água
	watermark.init();
	
	if($('#carrossel-capa').size()){
		$('#carrossel-capa').jcarousel({
			auto: 2,
			scroll: 3,
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
	}
	
	if($('#carrossel-telefones').size()){
		$('#carrossel-telefones').jcarousel({
			auto: 2,
			scroll: 1,
			wrap: 'last',
			initCallback: mycarousel_initCallback
		});
	}
	
	//Flash CLIENTES
	if($('.flash').size()){
		$('.flash').flash({
			src		  : baseUrl + 'assets/site/swf/clientes.swf',
			width	  : 974,
			height	  : 185,
			wmode	  : 'transparent',
			flashvars : {
				link  : baseUrl
			}
		});
	}
	
	//Flash AGENCIA
	if($('.case-swf').size()){
		$('.case-swf').flash({
			src		  : baseUrl + 'assets/site/swf/agencia.swf',
			width	  : 979,
			height	  : 220,
			wmode	  : 'transparent',
			flashvars : {
				link  : baseUrl
			}
		});
	}
	
	//Flash AGENCIA
	if($('.video').size()){
		$('.video').flash({
			src		  : baseUrl + 'assets/site/swf/video/video.swf',
			width	  : 327,
			height	  : 252,
			wmode	  : 'transparent',
			flashvars : {
				link  : baseUrl
			}
		});
	}
		
	/* CENTRALIZA A CLASSE ALINHAR */
	$('.alinhar').each(function(i){
		var parent_height 	= $(this).parent().height();
		var image_height 	= $(this).height();
		var top_margin 		= (parent_height - image_height)/2;
		$(this).css( 'margin-top' , top_margin);		
	});
	
	//PNG Fix para IE6
	if($.browser.msie && ($.browser.version == "6.0")){
		$(document).pngFix();
	}
	
	$("#phone").mask("(99) 9999-9999");

});

function base_url(){

    baseUrl = '';

    if($('base').length > 0){
        baseUrl = $('base').attr('href');
    }

    return baseUrl;

}

function mycarousel_initCallback(carousel)
{
	carousel.startAuto(0);
	// Disable autoscrolling if the user clicks the prev or next button.
	carousel.buttonNext.bind('click', function() {
		carousel.startAuto(0);
	});

	carousel.buttonPrev.bind('click', function() {
		carousel.startAuto(0);
	});

	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
};


/**
* var valEmail
* Expressão regular de validação de e-mail
*/
var valEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;

function enviaContato(){
	
	disabledFormButton(".bt");

	var msg = "";
	var lang = "pt";
	if($("#first_name").val() == "" || $("#first_name").val() == "Nome *" ){
		if(lang == 'pt') msg += "Nome não preenchido.\n";
		else if(lang == 'en') msg += "Please enter your name\n";
	}

	if($("#email").val() == ""){
		if(lang == 'pt') msg += "E-mail não preenchido.\n";
		else if(lang == 'en') msg += "Please enter your email.\n";
	} else if(!valEmail.test($("#email").val())){
		if(lang == 'pt') msg += "E-mail inválido.\n";
		else if(lang == 'en') msg += "Please enter a valid email address\n";
	}
	
	if($("#state").val() == "" || $("#state").val() == "Estado *"){
		if(lang == 'pt') msg += "Estado não selecionado.\n";
		else if(lang == 'en') msg += "Please select your state.\n"; 
	}
	
	if($("#phone").val() == "" || $("#phone").val() == "Telefone *"){
		if(lang == 'pt') msg += "Telefone não preenchida.\n";
		else if(lang == 'en') msg += "Please enter your phone.\n"; 
	}
	
	if($("#company").val() == "" || $("#company").val() == "Empresa *"){
		if(lang == 'pt') msg += "Empresa não preenchida.\n";
		else if(lang == 'en') msg += "Please enter your message.\n"; 
	}
	
	if($("#employees").val() == "--"){
		if(lang == 'pt') msg += "Selecione a quantidade de funcionários.\n";
		else if(lang == 'en') msg += "Please enter your message.\n"; 
	}
	
	if($("#description").val() == "" || $("#description").val() == "Mensagem *"){
		if(lang == 'pt') msg += "Mensagem não preenchida.\n";
		else if(lang == 'en') msg += "Please enter your message.\n"; 
	}

	if(msg != ""){
		if(lang == 'pt') msg = "Os seguintes campos encontram-se com problemas:\n" + msg;
		else if(lang == 'en') msg = "The following error(s) has occurred:\n" + msg;
		alert(msg);
		enabledFormButton(".bt");
	} else {
		$.ajax({
			type: "POST",
			url: baseUrl+"?on=contato&in=enviaContato",
			data: 'first_name='+$('#first_name').val()+'&email='+$('#email').val()+'&state='+$('#state').val()+'&phone='+$('#phone').val()+'&company='+$('#company').val()+'&employees='+$('#employees').val()+'&description='+$('#description').val(),
			success: function(msg){
				if(msg == '')
					jQuery.facebox("Erro na Transmissão. Tente mais tarde!");
				else {
					$("#frm").submit();
				}
			}
		});
	}
}

function enviaCurriculo(){
	var msg = "";
	var lang = "pt";
	if($("#nome_trabalhe").val() == "" || $("#nome_trabalhe").val() == "Nome *" ){
		if(lang == 'pt') msg += "Nome não preenchido.\n";
		else if(lang == 'en') msg += "Please enter your name\n";
	}
	
	if($("#cpf_trabalhe").val() == "" || $("#cpf_trabalhe").val() == "CPF *" ){
		if(lang == 'pt') msg += "CPF não preenchido.\n";
		else if(lang == 'en') msg += "Please enter your CPF\n";
	}

	if($("#email_trabalhe").val() == ""){
		if(lang == 'pt') msg += "E-mail não preenchido.\n";
		else if(lang == 'en') msg += "Please enter your email.\n";
	} else if(!valEmail.test($("#email_trabalhe").val())){
		if(lang == 'pt') msg += "E-mail inválido.\n";
		else if(lang == 'en') msg += "Please enter a valid email address\n";
	}
	
	if($("#file").val() == ""){
		if(lang == 'pt') msg += "Arquivo não anexado.\n";
		else if(lang == 'en') msg += "Please enter your CPF\n";
	}


	if(msg != ""){
		if(lang == 'pt') msg = "Os seguintes campos encontram-se com problemas:\n" + msg;
		else if(lang == 'en') msg = "The following error(s) has occurred:\n" + msg;
		
		//jQuery.facebox(msg);
		alert(msg);
		return false;
	} else {
		$("#frm_trabalhe").submit();
	}
}

function disabledFormButton(ct) { $(ct).attr('disabled','disabled').css('cursor','default').css('filter','alpha(opacity=40)').css('-moz-opacity','0.4').css('opacity','0.4'); }

function enabledFormButton(ct) { $(ct).attr('disabled','').css('cursor','pointer').css('filter','alpha(opacity=100)').css('-moz-opacity','1').css('opacity','1'); }


