$(document).ready(function(){
	verificaViewPort();

	if($('body').attr('id') == 'index'){
		
		$('body').css('overflow-y','scroll');
		
		//embed youtube
		var params = { allowScriptAccess: "always" };
		var atts = { id: "myplayerid1" };
		swfobject.embedSWF("http://www.youtube.com/v/785KKhJ1XEM&hl=pt-br&fs=1&enablejsapi=1&playerapiid=myplayerid1?rel=0", "flashdiv1", "800", "437", "8", null, null, params, atts);
		
		$(window).load(function(){
			var path = window.location.href;
			path = path.slice(-7);
			if(path == 'codigox'){
				$('body,html').css('overflow','visible');
				$('.box').fadeOut();
				$('#header .bt-home').removeClass('current');
				$('#header .bt-codigox').addClass('current');
				$('#slide01').animate({
					left:'-2000px',
					opacity:0
				},1000);
				$('.nav-dons').animate({
					right:0,
					opacity:1
				},1000);
				$('#slide02').delay(100).animate({
					left:0,
					opacity:1
				},1100);
			}
		})
				
		$('#header').localScroll(800);
		$('.bt-voltar-codigox').localScroll(800);

		//animacao slide01 - slide02
		$('#slide01 .sumir,#header .bt-codigox,.bt-voltar-codigox').click(function(e){
			$('.box').fadeOut();
			$('#header .wrapper,#footer .wrapper').css('left',7);

			$('body,html').css('overflow','visible');
			$('#header .bt-home').removeClass('current');
			$('#header .bt-codigox').addClass('current');
			$('.nav-dons a').removeClass('current');
			$('#slide01').animate({
				left:'-2000px',
				opacity:0
			},1000);
			$('.nav-dons').animate({
				right:0,
				opacity:1
			},1000);
			$('#slide02').delay(100).animate({
				left:0,
				opacity:1
			},1100);
			$('.bt-voltar-codigox').stop().hide();
			e.preventDefault();
		});
		
		$('.bt-home').click(function(e){
			// var posicao_scroll = parseInt($(window).scrollTop());
			if(!$('#intuicao').hasClass('inview')){
				$('.bt-home').attr('href','#home');
				$('#header .wrapper,#footer .wrapper').css('left',0);
				$('body,html').css('overflow','hidden');
				$('body').css('overflow-y','scroll');
				$('#header .bt-codigox').removeClass('current');
				$('#header .bt-home').addClass('current');
				$('#slide02').animate({
					left:'2000px',
					opacity:0
				},1000);
				$('.nav-dons').animate({
					right:'-2000px',
					opacity:0
				},1000);
				$('#slide01').delay(100).animate({
					left:8,
					opacity:1
				},1100,function(){
					$('.box').fadeIn();
				});
				e.preventDefault();
			}
		});
		
		
		$('#slide02 .sumir').click(function(e){

			$('#header .wrapper,#footer .wrapper').css('left',0);
			// $('#header .wrapper').css('right',7);
			
			$('body,html').css('overflow','hidden');
			$('body').css('overflow-y','scroll');
			$('#header .bt-codigox').removeClass('current');
			$('#header .bt-home').addClass('current');
			$('#slide02').animate({
				left:'2000px',
				opacity:0
			},1000);
			$('.nav-dons').animate({
				right:'-2000px',
				opacity:0
			},1000);
			$('#slide01').delay(100).animate({
				left:8,
				opacity:1
			},1100,function(){
				$('.box').fadeIn();
			});
			e.preventDefault();
		});

		//auxiliares para evitar que o scroll seja tagueado varias vezes
		var scrollado33  		= 0,
			scrollado66  		= 0,
			scrollado100 		= 0,
			scrollInstinto 		= 0,
			scrollCriatividade  = 0,
			scrollSensibilidade = 0,
			scrollInquietude 	= 0,
			scrollIntuicao 		= 0;
			
		var clicado = false;
/*			
			$('.nav-dons a').click(function(){
				clicado 			= true;
				scrollInstinto 		= 1;
				scrollCriatividade  = 1;
				scrollSensibilidade = 1;
				scrollInquietude 	= 1;
				scrollIntuicao 		= 1;
			});
*/
/*			
		$('.nav-dons').click(function(){
			scrollInstinto 		= 2;
			scrollCriatividade  = 2;
			scrollSensibilidade = 2;
			scrollInquietude 	= 2;
			scrollIntuicao 		= 2;
		});
*/	
		var intervalo;
		
		$(window).scroll(function(){
			var posicao_scroll = parseInt($(window).scrollTop());
			//ajustando posicao do rodape de acordo com a posicao do scroll
			//verificando ipad
			if($('html').hasClass('ipad')){
				//ajustando posição do menu
				if(posicao_scroll > 0){
					$('#footer').css({
						'top':posicao_scroll+625,
						'bottom':'auto'
					});
					$('#header').css({
						'position':'absolute',
						'top':posicao_scroll
					});
					$('.nav-dons').css({
						'position':'absolute',
						'top':posicao_scroll+200
					});
				}else if(posicao_scroll == 0){
					$('#footer').css({
						'position':'fixed',
						'top':'auto',
						'bottom':0
					});
					$('#header').css({
						'position':'fixed',
						'top':0
					});
					$('.nav-dons').css({
						'position':'absolute',
						'top':226
					});
					$('.nav-dons a').removeClass('current');
				}
			}
			//end configuracoes ipad

			//evitando que o usuario fique entre dois dons
			window.clearInterval(intervalo);
			intervalo = window.setInterval(function(){
				if(posicao_scroll > 300 && posicao_scroll < 1499){
					$('html,body').animate({
						scrollTop:1020
					},800);
					window.clearInterval(intervalo);
				}else if(posicao_scroll > 1500 && posicao_scroll < 2499){
					$('html,body').animate({
						scrollTop:1890
					},800);
					window.clearInterval(intervalo);
				}else if(posicao_scroll > 2500 && posicao_scroll < 3349){
					$('html,body').animate({
						scrollTop:2760
					},800);
					window.clearInterval(intervalo);
				}else if(posicao_scroll > 3350 && posicao_scroll < 4199){
					$('html,body').animate({
						scrollTop:3630
					});
					window.clearInterval(intervalo);
				}else if(posicao_scroll >= 4200){
					$('html,body').animate({
						scrollTop:4500
					});
					window.clearInterval(intervalo);
				}
			},1000);

			if(posicao_scroll > 720 && posicao_scroll < 1499){
				$('.nav-dons a,.bt-codigox').removeClass('current');
				$('.nav-dons .bt-instinto').addClass('current');
				$('.bt-voltar-codigox').stop().show();
			}else if(posicao_scroll > 1500 && posicao_scroll < 2499){
				$('.nav-dons a,.bt-codigox').removeClass('current');
				$('.nav-dons .bt-criatividade').addClass('current');
				$('.bt-voltar-codigox').stop().show();
			}else if(posicao_scroll > 2500 && posicao_scroll < 3349){
				$('.nav-dons a,.bt-codigox').removeClass('current');
				$('.nav-dons .bt-sensibilidade').addClass('current');
				$('.bt-voltar-codigox').stop().show();
			}else if(posicao_scroll > 3350 && posicao_scroll < 4199){
				$('.nav-dons a,.bt-codigox').removeClass('current');
				$('.nav-dons .bt-inquietude').addClass('current');
				$('.bt-voltar-codigox').stop().show();
			}else if(posicao_scroll >= 4200){
				$('.nav-dons a,.bt-codigox').removeClass('current');
				$('.nav-dons .bt-intuicao').addClass('current');
				$('.bt-voltar-codigox').stop().show();
			}else if(posicao_scroll < 719){
				$('.nav-dons a').removeClass('current');
				$('.bt-voltar-codigox').stop().hide();
			}
			
			//quando o ultimo don estiver parcialmente visivel o link home tem seu href alterado
			if($('#intuicao').hasClass('inview') && posicao_scroll >= 4100){
				$('.bt-home').attr('href','http://www.clightcodigox.com.br/');
			}else{
				$('.bt-home').attr('href','#home');
			}
			
			//GA baseado no scroll
			var bottom = $(window).height() + $(window).scrollTop();
			var height = $(document).height();
			var porcentagemScroll = Math.round(100*bottom/height);
			//se o usuario ja tiver scrollado o tagueamento e feito apenas uma vez
			if(porcentagemScroll > 33){
				if(scrollado33 == 0){
					scrollado33 = 1;
					_gaq.push(['_trackEvent', 'Conteudo','33', 'Codigox']);
				}
			}
			if(porcentagemScroll > 66){
				if(scrollado66 == 0){
					scrollado66 = 1;
					_gaq.push(['_trackEvent', 'Conteudo','66', 'Codigox']);
				}
			}
			if(porcentagemScroll > 90){
				if(scrollado100 == 0){
					scrollado100 = 1;
					_gaq.push(['_trackEvent', 'Conteudo','100', 'Codigox']);
				}
			}

		});
		
	};

	$(function(){
		$(window).resize(function(){
			verificaViewPort();
		});
		
		$('.item').addClass('fixbg');
		$('.item').removeClass('fixbg');

		$('.nav-dons').localScroll(800);

		$('.nav-dons a').click(function(){
			$('.nav-dons a,#header .bt-codigox').removeClass('current');
			$(this).addClass('current');
		});

		//verificando ipad
		if($('html').hasClass('ipad')){
			$('#home').css('height',660);
			$('.itens').hide();
			$("#footer").css('position', 'absolute');
			$('.itens .item .sumir,.itens .item').css('background-attachment','scroll');
			$('.itens .item').css('background-position','center -150px');
			//setando posicao do rodape e header de acordo com o don clicado
			$('.nav-dons a').click(function(){
				$('.itens ').show();
				//ajustando posição do menu
				var target = $(this).attr('href');
					target = $(target).position().top + 200;

				$('#footer').css({
					'top':target+426,
					'bottom':'auto'
				});
				$('#header').css({
					'position':'absolute',
					'top':target-200
				});
				$('.nav-dons').css({
					'position':'absolute',
					'top':target
				});
			});
			//ajusanto posicao do menu ao clicar em home ou codigox
			$('.bt-home,.bt-codigox,.bt-voltar-codigox a').click(function(){
				$('#footer').css({
					'position':'fixed',
					'top':'auto',
					'bottom':0
				});
				$('#header').css({
					'position':'fixed',
					'top':0
				});
				$('.nav-dons').css({
					'position':'absolute',
					'top':226
				});
			});
			
		}else{
			$('.item').scrollParallax({
				'speed':-0.2
			});
			$('.item .sumir').scrollParallax({
				'speed':0.5
			});
		}
		//end configuracoes ipad
	});

	if($('.twitter-feed').length){
		//twiiter feed
		$(".twitter-feed #feedContent").getTwitter({
			userName: "clightcodigox",
			numTweets: 3,
			loaderText: "Carregando tweets...",
			slideIn: false,
			slideDuration: 750,
			showHeading: false,
			headingText: "Últimos twitts",
			showProfileLink: false,
			showTimestamp: false
		});	
		
		$('.twitter-feed .footer ol li').click(function(){
			$('.twitter-feed #feedContent li').hide();
			$('.twitter-feed #feedContent li').eq($(this).html()).show();
			// $('.twitter-feed #feedContent li')
			$('.twitter-feed .footer li').removeClass('current');
			$(this).addClass('current');
		})
	}


	//lightbox video
	$('.ver-video,.bt-peca').click(function(e){
		$('.overlay .video iframe').attr('src',$(this).attr('href'));
		$('.overlay,.overlay .video').fadeIn();
		e.preventDefault();
	});
	
	$(document).keyup(function(e){
		if(e.keyCode == 27){
			if(document.getElementById('myplayerid1')){
				var player = document.getElementById('myplayerid1')
				player.stopVideo();
			};
			$('.overlay').fadeOut();
		}
	});
	
	//previnindo que o video seja fechado ao clicar no play || problema só ocorria no firefox
	$('.overlay .video').click(function(event){
		event.stopPropagation();
	});
	
	$('.overlay').click(function(){
		if(document.getElementById('myplayerid1')){
			var player = document.getElementById('myplayerid1')
			player.stopVideo();
		};
		$(this).fadeOut();
	});

	if($('body').attr('id') == 'mulheresx'){
		//embed youtube
		var params = { allowScriptAccess: "always" };
		var atts = { id: "myplayerid1" };
		swfobject.embedSWF("http://www.youtube.com/v/uqYyI4ONt2A&hl=pt-br&fs=1&enablejsapi=1&playerapiid=myplayerid1?rel=0", "flashdiv1", "800", "437", "8", null, null, params, atts);
	//controle tabela horario
		$(function(){

			var abas 	= $('.tabela-horarios-header a'),
				aberto 	= $('.tabela-horarios .current'),
				alvo;
		
			$(abas).click(function(e){
				alvo = $(this).attr('href');
				aberto = $('.tabela-horarios .current');
			
				$(abas).removeClass('current');
				$(this).addClass('current');
			
				$('.tabela-horarios .content .current').removeClass('current').css('top','300px');

				$(alvo).css('top','0').addClass('current');

				e.preventDefault();
			});

		});
	}

	if($('body').attr('id') == 'novo-clight'){
			//TOOLTIP
			$('a.ico').bind({ 
				mouseenter:	function(){
					text = $(this).text();
					tooltip = '<div class="tooltip"><div class="tooltip-middle"><p class="' + text + '-tip">' + text + '</p></div><div class="tooltip-right"></div></div>' 
					$(this).parent().prepend(tooltip);
					$('.tooltip').fadeIn('slow');
				},
				mouseleave:	function(){
					$('.tooltip').fadeOut('slow').remove();
				}	
			});

			//HOME
			$('a.logo-clight').live('click', function(e){
				e.preventDefault();
				$('a.ico').removeClass('active');
				$('.list-gallery').hide();
				$('.text-gallery').hide();
				$('.text-home').show();
				$('.splash-home').show();	
			});

			//GALLERY
			$('a.ico').live('click', function(e){
				$('.col-right').addClass('bgnone');
				$('.nova-embalagem').addClass('none');
				$('.nova-formula').removeClass('none');
				e.preventDefault();
				rel_item = parseInt($(this).attr('rel'));
				rel_a = rel_item * '-368';
				totalSize = 0;

				//THUMB ACTIVE
				$('a.ico').removeClass('active');
				$(this).addClass('active');

				//LINK AJAX		
				link = $(this).attr('href');
				$('.ver-tabela').attr('rel', rel_item);

				//HIDE HOME		
				$('.text-home').hide();
				$('.splash-home').hide();

				//SHOW GALLERY
				$('.list-gallery').show();
				$('.text-gallery').show();

				$('.items-gallery').hide();
				$('.items-gallery').css('left', rel_a).attr('rel', rel_a);
				$('.items-gallery').fadeIn('slow');
			});

			$('.list-gallery .previous').live('click', function(e){
				e.preventDefault();
				rel_position = 	parseInt($('.items-gallery').attr('rel'));
				position = parseInt($('.items-gallery').attr('rel')) + 368;
				
				//capturando sabor anterior
				var saborAnterior = $('.icos-list .active').parents('li').prev().find('a').attr('class');
				if(!saborAnterior){
					//se o sabor ativo for o primeiro da lista, pega o ultimo sabor
					saborAnterior = $('.icos-list li:last-child a').attr('class');
				}
				saborAnterior = 'Sabor_'+saborAnterior.slice(4)+'_seta';
				saborAnterior = saborAnterior.replace('-','_');
				_gaq.push(['_trackEvent','Conteudo','Visualizar',saborAnterior]);

				//THUMB ACTIVE REMOVE
				$('a.ico').removeClass('active');

				if(rel_position == 0){
					totalImgs = $('.items-gallery div.item').length - 1;
					totalLeft = totalImgs * '-368';
					$('.items-gallery').animate({ left: totalLeft });
					$('.items-gallery').attr('rel', totalLeft);			

					//LINK AJAX	
					ico_href = $('a[rel="' + totalImgs + '"]').attr('href');		
					$('.ver-tabela').attr('rel', totalImgs);	

					//THUMB ACTIVE
					$('a[rel="' + totalImgs + '"].ico').addClass('active');

				}	
				else{
					if(position <= 0){
						$('.items-gallery').animate({ left: position });
						$('.items-gallery').attr('rel', position);

						//LINK AJAX	
						link_rel = 	$('.trig-ajax').attr('rel') - 1;
						ico_href = $('a[rel="' + link_rel + '"]').attr('href');		
						$('.ver-tabela').attr('rel', link_rel);

						//THUMB ACTIVE
						$('a[rel="' + link_rel + '"].ico').addClass('active');
					}
				}
			});

			$(".list-gallery .next").live('click', function(e){
				e.preventDefault();
				rel_position = 	parseInt($('.items-gallery').attr('rel'));
				position = parseInt($('.items-gallery').attr('rel')) - 368;
				last = $('.items-gallery').attr('rel');
				totalImgs = $('.items-gallery div.item').length - 1;
				totalLeft = totalImgs * '-368';

				//capturando proximo sabor
				var proximoSabor = $('.icos-list .active').parents('li').next().find('a').attr('class');
				if(!proximoSabor){
					//se o sabor ativo for o ultimo da lista, pega o primeiro sabor
					proximoSabor = $('.icos-list li:first-child a').attr('class');
				}
				proximoSabor = 'Sabor_'+proximoSabor.slice(4)+'_seta';
				proximoSabor = proximoSabor.replace('-','_');
				_gaq.push(['_trackEvent','Conteudo','Visualizar',proximoSabor]);

				//THUMB ACTIVE REMOVE
				$('a.ico').removeClass('active');

				if(rel_position == parseInt(totalLeft)){
					$('.items-gallery').animate({ left: 0 });
					$('.items-gallery').attr('rel', 0);

					//LINK AJAX	
					link_rel = 	0;
					ico_href = $('a[rel="' + link_rel + '"]').attr('href');		
					$('.ver-tabela').attr('rel', link_rel);

					//THUMB ACTIVE
					$('a[rel="' + link_rel + '"].ico').addClass('active');
				}
				else{
					if(position >= parseInt(totalLeft)){
						$('.items-gallery').animate({ left: position });
						$('.items-gallery').attr('rel', position);

						//LINK AJAX	
						link_rel = 	parseInt($('.trig-ajax').attr('rel')) + 1;
						ico_href = $('a[rel="' + link_rel + '"]').attr('href');		
						$('.ver-tabela').attr('rel', link_rel);

						//THUMB ACTIVE
						$('a[rel="' + link_rel + '"].ico').addClass('active');	
					}
				}
			});

			//AJAX
	}

	$('a.trig-ajax').live('click', function(e){
		e.preventDefault();
		$('.ajax-loader').show();
		//MASK
		outer_height = $('body').innerHeight() + 200;

		var url = $(this).attr('href');
		$('.mask').css({ height:outer_height }).show();

		$('.ajax-result').show();
		$('.ajax-content').hide();

		function carregaHtm(url){
			$('.ajax-content').load(url + ' .ajax-inner', function(){
				atualizaValidacao();

				$('.ajax-loader').hide();
				$('.ajax-content').show();
			});
		}
		carregaHtm(url);

		//ANALYTICS
		if($(this).hasClass('ver-tabela') == true){
//			page = '/' + $.trim($('a.active').attr('name')) + '/Tabela-Nutricional';
//			_gaq.push(['_trackPageview', page]);
		}
	});

        $('a.close').live('click', function(e){
		e.preventDefault();
		$('.mask').hide();
		$('.ajax-result').hide();
	});	

	$('.mask').live('click', function(){
		$(this).hide();
		$('.ajax-result').hide();	
	});

	//função trace para debug
	function trace(mensagem) {
		try { 
			console.log(mensagem); 
		} 
		catch (e) {
			//caso queira executar alguma função em caso de falta de console
		}
	}

	//checagem de existencia de um elemento.
	if ($('#carrossel').size() >0) {
		$('#carrossel').jcarrossel();
	}
	
	//link externo
	$('.external').click(function(e) {
		e.preventDefault();
		var url = $(this).attr('href');
		window.open(url);
	});
	
	//ga
	var pathname = window.location.pathname+window.location.search;
	$('.ga').click(function(e) {
		var tagGa = $(this).attr('rel');
		_gaq.push(['_trackEvent', tagGa]);
	});
	
	$('.bt-home').click(function(){
		_gaq.push(['_trackPageview','/index.html']);
	});
	$('.bt-codigox').click(function(){
		_gaq.push(['_trackPageview','/codigox.html']);
	});
	
	$('#slide01 .ver-video').click(function(){
		_gaq.push(['_trackEvent','Video','Assistir_home','Clightcodigox']);
	});
	
	$('#slide01 .sumir').click(function(){
		_gaq.push(['_trackEvent','Conteudo','Visualizar','Codigox_seta']); 
	});
	
	$('#slide02 .sumir').click(function(){
		_gaq.push(['_trackEvent','Conteudo','Visualizar','Home_seta']); 
	});

	$('#slide02 .ver-video').click(function(){
		_gaq.push(['_trackEvent','Video','Assistir_codigox','Clightcodigox']);
	});

	$('.twitter-feed .footer li').click(function(){
		var numeroTweet = parseInt($(this).html());
		numeroTweet = numeroTweet+1;
		_gaq.push(['_trackEvent','Social','Visualizar','Home_codigox',numeroTweet]);
	});

	$('.nav-dons a').click(function(){
		var href = $(this).attr('href'),
			html = '';
		switch (href){
			case '#instinto':
				html = '/codigox_instinto.html';
			break;
			case '#criatividade':
				html = '/codigox_criatividade.html';
			break;
			case '#sensibilidade':
				html = '/codigox_sensibilidade.html';
			break;
			case '#inquietude':
				html = '/codigox_inquietude.html';
			break;
			case '#intuicao':
				html = '/codigox_intuicao.html';
			break;
		}
		_gaq.push(['_trackPageview', html]);
	});

	$('.bt-voltar-codigox').click(function(){
		_gaq.push(['_trackEvent','Conteudo','Voltar','Codigox']);	
	});

	$('.icos-list a').click(function(){
		var nomeSabor = $(this).attr('href');
		nomeSabor = '/Produto_sabor_'+nomeSabor.slice(5);
		_gaq.push(['_trackPageview',nomeSabor]);
	});
	
	//botao ver-tabela
	$('.trig-ajax').click(function(){
		var nomeSabor = $(this).attr('href');
		nomeSabor = 'Sabor_'+nomeSabor.slice(5,-5)+'_tabela_nutricional';
		nomeSabor = nomeSabor.replace('-','_');
		_gaq.push(['_trackEvent', 'Conteudo', 'Visualizar', nomeSabor]);
	});

	$('.bt-peca').click(function(){
 		_gaq.push(['_trackEvent', 'Video', 'Assistir', 'Teatro_as_olivias']);
	});

	$('.mulheresx p a.external').click(function(){
		_gaq.push(['_trackEvent', 'Social', 'Visitar', 'facebook.com/asolivias']);
	});
	
	$('.tabela-horarios-header a').click(function(){
		var cidade = $(this).attr('class');
		switch (cidade){
			case 'sp':
				cidade = 'Saopaulo';
			break;
			case 'rj':
				cidade = 'Riodejaneiro';
			break;
			case 'bh':
				cidade = 'Belohorizonte';
			break;
			case 'poa':
				cidade = 'Portoalegre';
			break;
			case 'ctba':
				cidade = 'Curitiba';
			break;
		}
		_gaq.push(['_trackEvent', 'Conteudo_as_olivias', 'Visualizar', cidade]);
	});
	
	$('.tabela-horarios .detalhes a').click(function(){
		var cidade = $('.tabela-horarios-header .current').attr('href');
		switch (cidade){
			case '#sao-paulo':
				cidade = 'Saopaulo';
			break;
			case '#rio-de-janeiro':
				cidade = 'Riodejaneiro';
			break;
			case '#belo-horizonte':
				cidade = 'Belohorizonte';
			break;
			case '#porto-alegre':
				cidade = 'Portoalegre';
			break;
			case '#curitiba':
				cidade = 'Curitiba';
			break;
		}
		cidade = cidade+'_site_teatro';
		_gaq.push(['_trackEvent','Conteudo_as_olivias', 'Visualizar', cidade]);
	});

	$('.social a').click(function(){
		_gaq.push(['_trackEvent','Social','Visitar',pathname]);
	});	

	//track like facebook
	FB.Event.subscribe('edge.create', function(targetUrl) {
		_gaq.push(['_trackEvent','Social','Curtir_Facebook',pathname]);
	});
	
	//track twitter
	twttr.events.bind('tweet', function(event){
		if (event){
			_gaq.push(['_trackEvent','Social','Tweetar',pathname]);
		}
	});

	//track twitter seguir	
	twttr.events.bind('follow', function(event){
		if (event){
			_gaq.push(['_trackEvent','Social','Seguir_tweeter','Home_codigox']);
		}
	});
	
	$('#slide01 .bt-teste-agora').click(function(event) {
		_gaq.push(['_trackEvent', 'Social', 'Teste_Descubraseucodigox', 'Home']);
	});
	$('#slide02 .bt-teste-agora').click(function(event) {
		_gaq.push(['_trackEvent', 'Social', 'Teste_Descubraseucodigox', 'Codigox']);
	});
	
	//fim ga

	function atualizaValidacao(){
		$('input[name="ddd"]').mask('99');
		$('input[name="telefone"]').mask('9999-9999');
		$('input[name="cep"]').mask('99999-999');
		$('input[name="nascimento"]').mask('99/99/9999');		
		
		$('input[type="text"]').focus(function(){
			$(this).removeClass('error');
		});
		$('select').focus(function(){
			$(this).removeClass('error');
		});
		$('textarea').focus(function(){
			$(this).removeClass('error');
		});
		//EMAIL
		function checkEmail() {
			var email = document.getElementById('emailaddress');
			var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (!filter.test(email.value)) {
				$('input[name="email"]').addClass('error');
			}
		}
		
		//SELECTS		
		function checkSelect(){		
			$('select').each(function(){
				select_val = $(this).find('option:selected').val();	
				if(select_val == ""){
					$(this).addClass('error');
				}
			});
			if($('select').hasClass('error') == false){
				return true;
			}
		}

		//TEXTAREA
		function checkText(){
			text_men = $('textarea').val();
			if(text_men == ""){
				$('textarea').addClass('error');
			}else{ return true;	}
		}
		
		//INPUT
		function checkInput(){
			$('input[type="text"]').each(function(){
				input_val = $(this).val();
				if($(this).attr('name') != 'complemento'){
					if(input_val == ""){
						$(this).addClass('error');
					}
				}
			});
			if($('input').hasClass('error') == false){
				return true;
			}
		}

		$('.disabled').live('click', function(){
			input = checkInput();
			select = checkSelect();
			email = checkEmail();
			text = checkText();
			if(input == true && select == true && text == true){
				$('.info-error').css('display', 'none');
			
				$('.ajax-content').hide();
				$('.ajax-loader').show();
				var data_form = $('form').serializeArray();
				$.post('php/enviar.php', data_form).success(function() { 
					$('.ajax-content').load('fale-conosco-sucesso.html' + ' .ajax-inner');
					$('.ajax-loader').hide();						
					$('.ajax-content').show();
					 
				});
			}
			else {
				$('.info-error').css('display', 'block');
			}
		});

	}
});

var booleana = true;

function verificaViewPort(){

	if(booleana){
		$('.box,.logo').fadeIn();
		booleana = false;
	}

	if($(window).innerHeight() <= '900'){
		$('#home').css({'backgroundPositionY':-188});
	}else if($(window).innerHeight() >= '950'){
		$('#home').css({'backgroundPosition':'center top'});
	}

	if($(window).innerWidth() >= '970'){
		var larguraMain = 940;
		var tamanhoJanela = $(window).innerWidth();

		var x = parseInt((tamanhoJanela - larguraMain) / 2);
		var bgp = x + ' 0' 
		
		$('.box').css('left',x+415);
		$('.bt-voltar-codigox').css('right',x);
		$('.box.novo-clight,.logo').css('left',x);

		$('.item .sumir').css('left',x);
		$('.item .sumir').css({'backgroundPositionX': x });
	};
}
