﻿//var myCarousel = null;

window.alert = function() {
	return;
};

$(function(){
/*	$(".box").prepend('<input type="text" id="focus-stealer" type="hidden" />');
	$("#focus-stealer").focus(); */
	
	/* habilita os links do menu somente se o javascript for carregado */
	$("#menu ul li").css('display', 'inline');
	
	$("#menu a").click(function(e){
		e.preventDefault();
		
		if($("div, td, img").is(":animated") || $(this).hasClass('active')){ return;}
		
		folder = $(this).attr('id');
		url = folder + '/index.html #secao > *';
			
		_out = $(".active").attr('id');
		_in  = $(this).attr('id');
		$('#' + _out).removeClass('active');
		$('#' + _in).addClass('active');
		
		switch(_out){
			case 'quem_somos': 			quem_somos_out(); break;
			case 'como_fazemos': 		como_fazemos_out(); break;
			case 'nossos_clientes': nossos_clientes_out(); break;
			case 'portfolio' : 			portfolio_out(); break;
			case 'novidades' : 			novidades_out(); break;
			case 'contato' : 				contato_out(); break;
		}
	}) /* click - fim */ 
}) /* funcao JQuery - fim */


function transicao (_in, url){

	$("#loading_index img").ajaxStart(function(){
		$(this).show();
	})
	
	if(_in == 'portfolio'){
		$.getScript('js/jcarousel/lib/jquery.jcarousel.js', function(){
			$("#secao").load(url, function(){
				//$('#google_media_kit-web').show().jcarousel({scroll:1, visible:1, animation:"slow", initCallback: mycarousel_init,
				$('#amex_day-imp').show().jcarousel({scroll:1, visible:1, animation:"slow", initCallback: mycarousel_init,
					itemVisibleInCallback: {onBeforeAnimation: caption_in},
					itemVisibleOutCallback: {onAfterAnimation: caption_out}				
				}).addClass('clicado');
				$('.jcarousel-skin-box2').jcarousel({scroll:6, visible:6, animation:"slow", initCallback: portfolio_in})
				$('#thumb_nc').find('.impresso + .icone').addClass('icone_impresso');
				$('#thumb_nc').find('.video + .icone').addClass('icone_video');
				$('#thumb_nc').find('.web + .icone').addClass('icone_web');
				
				$("#thumb_nc img").click(function(e_nc){
					e_nc.preventDefault();
					
					/* mostra banner embrio consult */
					
					if($(this).attr('id') == 'banner_h' && $(this).hasClass('web')){
						$('#banner_ec1').fadeIn(300, function(){
							$('#banner_horizontal #foto_2').hide();
							$(this).click(function(){return false;})
							banner_embrio_c1();
							$().click(function(){
								$('.banner_ec').fadeOut(300);
							})
						})
						return false;
					}
					else if($(this).attr('id') == 'banner_v' && $(this).hasClass('web')){
						$('#banner_ec2').fadeIn(300, function(){
							$('#banner_vertical #foto_2')
								.add('#banner_vertical #foto_3')
								.hide();
	
							$(this).click(function(){return false;})
							banner_embrio_c2();
							$().click(function(){
								$('.banner_ec').fadeOut(300);
							})
						})
						return false;
					}
					
					
					url_nc = $(this).attr('src');
					temp = new Array();
					temp = url_nc.split('/');
					id = '#' + temp[3];
					
					if($(this).hasClass('impresso')){id = id + '-imp'}
					else if($(this).hasClass('web')){id = id + '-web'}
					else if($(this).hasClass('video')){id = id + '-vid'}
					
					$('.jcarousel-skin-box1:visible').hide();
					
					seletor = '.jcarousel-skin-box1:has(' + id + ')';
					
					if($(id).hasClass('clicado')){
						$(seletor).show();
					}
					else {
						$(id).show().jcarousel({scroll:1, animation:450,
							itemVisibleInCallback: {onBeforeAnimation: caption_in},
							itemVisibleOutCallback: {onAfterAnimation: caption_out}
						}).addClass('clicado')					
					}
				})	
			})
		})
	}
	else if(_in == 'contato'){
	
		$("#secao").load(url,function(){
			contato_in(); 
			window.setTimeout(function(){
			muda_bg()}, 2600); 
			
			$('#but_enviar').click(function(e){
				e.preventDefault();
				
				$("#resposta").ajaxStart(function(){ 
					$(this).html('<img src="img/contato/loading.gif" border="0" alt="enviando ..." />'); 
				});
				
				var nome     = $('#nome').val();
				var empresa  = $('#empresa').val();
				var telefone = $('#telefone').val();
				var email    = $('#email').val();
				var mensagem = $('#mensagem').val();
				
				$.post('contato/mail/envia_mensagem.php', {nome: nome, empresa: empresa, telefone: telefone, email: email, mensagem: mensagem}, function(data, textStatus){
					$('#resposta').html(data);
					$("#formulario")[0].reset();
				})
				
				return false;
			})		
		})
	}
	else {
		$("#secao").load(url,function(){
			switch(_in){
				case 'quem_somos': 			
					quem_somos_in(); 
					window.setTimeout(function(){
						muda_bg()}, 2600); 
					break;
				case 'como_fazemos': 			
					como_fazemos_in(); 
					window.setTimeout(function(){
						muda_bg()}, 2600); 
					break;
				case 'nossos_clientes': 			
					nossos_clientes_in(); 
					window.setTimeout(function(){
						muda_bg()}, 2600); 
					break;
				case 'novidades': 			
					novidades_in(); 
					window.setTimeout(function(){
						muda_bg()}, 2600); 
					break;
			}
		})
	}
	
	$("#loading_index").ajaxComplete(function(){
		$(this).hide();
	})
}

/* ------------------------------ banners Embrio Consult */

function banner_embrio_c1 (){

	/* animação do primeiro banner */
	
	if($('span').is(':animated')){return;}

	$('#banner_horizontal').mouseover(function(){
		$('#banner_horizontal #foto_2').not(':animated').animate({height:'show'}, 300)
	})
	
	$('#banner_horizontal').mouseleave(function(){
		$('#banner_horizontal #foto_2').animate({height:'hide'}, 300)
	})	
}

function banner_embrio_c2 (){

	/* animação do segundo banner */
	
	if($('span').is(':animated')){return;}

	$('#banner_vertical #foto_1').mouseover(function(){					
		$('#banner_vertical #foto_2').not(':animated').fadeIn(450, function(){
			_timeOut = window.setTimeout(function(){
				$('#banner_vertical #foto_3').not(':animated').fadeIn(450)
			}, 1700)	
		})
	})
				
	$('#banner_vertical').mouseleave(function(){
		window.clearTimeout(_timeOut);
		$('#banner_vertical #foto_2')
			.add('#banner_vertical #foto_3')
			.fadeOut(function(){
				$('#banner_vertical #foto_1').fadeIn(250);
				return;
		})
	})
}



/* funcoes da galeria da seção 'nossos clientes' */

function caption_in (carousel, item, idx, state){
		alt = $(item).find('img').attr('alt');
		$(item).find('img').after('<span class="caption">' + alt + '</span>');
		$(item).find('img').next().stop(false,true).show();
}

function caption_out(carousel, item, idx, state){
	$(item).find('.caption').remove();
}

function mycarousel_init (carousel){
		myCarousel = carousel;
}

/*
function mycarousel_initReset (){
		myCarousel.reset();
}*/

/* funcões de manipulação do background */

function muda_bg (){

	if($("div, td, img").is(":animated")){ return;}

	num_al = (Math.floor(Math.random()*8) % 7) + 1;
	atual = $("#img_bg").find('img').attr('src');
	atual = atual.match(/\d{1}/, atual);
	
	if(num_al == atual || num_al == 0){
		num_al = (num_al % 7) + 1;
	}
	
	//img_url = 'img/bg/' + 'bg_' + num_al + '.html' + ' img';
	
	img_url = 'img/bg/' + 'bg_' + num_al + '.jpg';
	
	//$("#img_bg_step").load(img_url, function(){
		//img_conteudo = $(this).html();
		$("#img_bg").fadeOut(250, function(){
			//$(this).html(img_conteudo, function(){
				//$("#img_bg_step").empty();
			//})
			$(this).find('img').attr('src', img_url);
			$(this).fadeIn(250);
		})
	//})
}

function mostra_bg_filtro (){
	$("#bg_filtro").fadeIn(900)
}

function esconde_bg_filtro (){
	$("#bg_filtro").fadeOut(900)
}

/* função para a seção 'novidades' */

function novidades (){
	$("#box2_nv li").not('#active').css('display','none');
	
	$("#box1_nv li a").click(function(e_nv){
		e_nv.preventDefault();
		index_1 = $("#box1_nv li a").index(this);
		$("#box2_nv li").attr('id','').filter(function(index_2){
			return (index_1 == index_2);
		}).attr('id','active').fadeIn(700)
		$("#box2_nv li").not("#active").hide();
		
		/* atualiza o estilo dos links e respectivas datas */
		$(this).removeClass('nome_inativo').addClass('nome_ativo');
		$("#box1_nv li a").not(this).removeClass('nome_ativo').addClass('nome_inativo');
		$(this).prev().removeClass('data_inativo').addClass('data_ativo');
		$("#box1_nv li a").not(this).prev().removeClass('data_ativo').addClass('data_inativo');
	})
}

/* funções de animção de entrada/saida na transição entre as seções */

function quem_somos_in(){
	$("#alca_qs").add("#box1_qs").add("#box2_qs").hide(0).css('margin-top','0px');
	$("#box1_qs *").add("#box2_qs *").hide(0);
	$("#box1_qs").css({'height':'42px', 'background-position':'0 -142px'});
	$("#box2_qs").css('height','27px');
	$("#alca_qs").add("#box1_qs").add("#box2_qs").stop().animate({width:'show'});
	$("#box2_qs").animate({marginTop:'123px', height:'185px'});
	$("#box1_qs").animate({height:'277px'}, function(){
		$("#box1_qs *").add("#box2_qs *").css('display','block').fadeIn(200, function(){
			$("#box1_qs").animate({backgroundPosition:'0 0'},200)})})
}

function quem_somos_out(){
	$("#box1_qs *").add("#box2_qs *").hide();
	$("#box1_qs").css('background-image','none');
	$("#box2_qs").stop().animate({height:'140px'}, function(){		
		$("#box2_qs").animate({width:'hide'}, 200, function(){
			$("#box1_qs").animate({height:'42px'}, 200, function(){
				$("#alca_qs").add("#box1_qs").animate({width:'toggle'}, function(){
					transicao(_in, url)})})})})
					
}

function como_fazemos_in(){
	$("#box1_cf").add("#box2_cf").add("#box3_cf").hide();
		$("#box2_cf *").add("#box3_cf *").hide();
		$("#box1_cf").css('background-position','64px -87');
		$("#box2_cf").css({'width':'292px'});
		$("#box3_cf").css({'height':'106px', 'margin-top':'0'});
		
		$("#box1_cf").stop().animate({width:'show'}, 170, function(){
			$("#box2_cf").slideDown(function(){
				$("#box2_cf").animate({width:'320px'}, 150,function(){
					$("#box3_cf").animate({width:'show'}, function(){
						$("#box3_cf").animate({height:'260px', marginTop:'-20px'}, 150, function(){
							$("#box1_cf *").add("#box2_cf *").add("#box3_cf *").fadeIn()
							$("#box1_cf").animate({backgroundPosition:'64px 0'})})})})})})

}

function como_fazemos_out(){
	$("#box3_cf *").add("#box2_cf *").hide(100);
	$("#box1_cf").css('background-image','none');
	$("#box3_cf").stop().animate({height:'106px', marginTop:'0'}, 300, function(){
			$("#box3_cf").animate({width:'toggle'},400);
			$("#box2_cf").animate({width:'292px'}, function(){
				$("#box2_cf").slideUp(function(){
					$("#box1_cf").animate({width:'toggle'}, function(){
						transicao(_in, url)})})})})
}

function portfolio_in(){
	$(".jcarousel-skin-box2 .jcarousel-container *")
		.add(".jcarousel-skin-box2 .jcarousel-container")
		.add(".jcarousel-skin-box1 .jcarousel-container *")
		.add(".jcarousel-skin-box1 .jcarousel-container")
		.add("#alca1_nc").hide(0);

	$("#alca2_nc").hide(0).stop().animate({width:'show'}, 200, function(){	
		$(".jcarousel-skin-box2 .jcarousel-container")
			.css({'height':'23px', 'margin-top':'70px'})
			.animate({width:'show'}, 200)
			.animate({marginTop:'7px',height:'86px'}, function(){
				$(".jcarousel-skin-box2 .jcarousel-container *").fadeIn(200)})})
	
	$("#alca1_nc").stop().animate({width:'show'}, 200, function(){	
		$(".jcarousel-skin-box1 .jcarousel-container")
			.css({'height':'159px', 'margin-top':'40px'})
			.animate({width:'show'}, 200)
			.animate({marginTop:'-15px',height:'312px'}, function(){	
				$(".jcarousel-skin-box1 .jcarousel-container *").fadeIn(200, function(){
					mostra_bg_filtro()})})})
}

function portfolio_out(){
	$(".jcarousel-skin-box2 .jcarousel-container *").fadeOut(200);
	$(".jcarousel-skin-box2 .jcarousel-container").stop()
		.animate({height:'23px', marginTop:'70px'}, 450)
		.animate({width:'toggle'}, 200, function(){
			$("#alca2_nc").stop().animate({width:'toggle'}, 150, function(){
			$(".jcarousel-skin-box1 .jcarousel-container *").fadeOut(200);
			$(".jcarousel-skin-box1 .jcarousel-container").stop()
				.animate({height:'159px', marginTop:'40px'}, 450)
				.animate({width:'toggle'}, 200, function(){
					$("#alca1_nc").stop().animate({width:'toggle'}, 150, function(){
						transicao(_in, url)
						esconde_bg_filtro()})})})})
}

function nossos_clientes_in(){
	$("#alca1_cl, #alca2_cl, #box1_cl, #box1_cl *").hide();	
	$("#box1_cl").animate({width:"show"}, function(){
		$("#alca1_cl").slideDown();
		$("#alca2_cl").slideDown(function(){
			$("#box1_cl *").fadeIn();
		}).css('display','block');
	})
}

function nossos_clientes_out(){
	$("#alca1_cl").slideUp();
	$("#alca2_cl").slideUp(function(){
		$("#box1_cl *").fadeOut(100);
		$("#box1_cl").animate({width:'hide'}, 750, function(){
				transicao(_in, url);
		})
	})
}

function novidades_in(){
	$("#alca1_nv")
		.add("#box1_nv")
		.add("#alca2_nv")
		.add("#box2_nv")
		.add("#box1_nv *")
		.add("#box2_nv *").hide();

	$("#box1_nv").css('height','25px');
	$("#box2_nv").css('height','34px');
	
	$("#alca1_nv").stop().animate({width:'show'})
	$("#box1_nv").stop().animate({width:'248px'}, 100, function(){
		$("#box1_nv").animate({height:'113px'}, 150, function(){
			$("#alca2_nv").add("#box2_nv").animate({width:'show'}, 300, function(){
				$("#box2_nv").animate({height:'205px'}, function(){
					$("#box1_nv *").add("#box2_nv *").fadeIn(function(){
						novidades();
					})})})})})
}

function novidades_out(){
	$("#box2_nv *").add("#box1_nv *").stop().hide();	
	$("#box2_nv").css('overflow','hidden').stop().animate({height:'34px'}, function(){
		$("#box2_nv").add("#alca2_nv").animate({width:'toggle'}, 200, function(){
			$("#box1_nv").animate({height:'25px'}, 200, function(){
				$("#alca1_nv").add("#box1_nv").stop().animate({width:'toggle'}, 200, function(){
					transicao(_in, url)})})})})
}

function contato_in(){
	$("#alca_ct").add("#box1_ct").hide();
	$("#box1_ct").css({'height':'16px', 'margin-top':'80px'});
	$("#box1_ct *").hide();
	$("#alca_ct").add("#box1_ct").stop().animate({width:'show'}, function(){
		$("#box1_ct").animate({height:'420px', marginTop:'0'}, function(){  // 340px
			$("#box1_ct *").fadeIn()})})
}

function contato_out(){
	$("#resposta").hide();
	$("#box1_ct *").stop().hide(0);
	$("#box1_ct").stop().animate({height:'16px', marginTop:'80px'}, function(){
		$("#alca_ct").add("#box1_ct").animate({width:'toggle'}, function(){
			transicao(_in, url)})})
		
}

