$.fn.ready(function(){
	// Variaveis
	var $projeto = $('#projeto');
	var $projetoExtendido = $('#projetoExtendido');
	var $vagas = $('#vagas');
	var $clientes = $('#clientes');
	var $single = $('#singleCase');
	var $home = $('.home');
	var $guest = $('#respond');
	
	////////////////////////////////////////////////////////////////////
	
	////////////////////////////////////////////////////////////////////
	
	// Clicks false
	$('#projetoAnterior, #projetoProximo').click(function(){ return false; });
	
	
	// Funçao para aparecer itens
	var showItens = function(eElement, fFind, dDelay) {
		// Animação para projetos
		eElement.find(fFind).each(function(i){
			var $this = $(this);
			$this.delay(dDelay).fadeTo(500, 1);
			
			dDelay += 100;
		});
	}
	
	////////////////////////////////////////////////////////////////////
	
	// Default values nos formulários
	if($guest.length) {
		var $nameGuest = document.getElementById('author');
		var $emailGuest = document.getElementById('email');
		
		var $nameVal = $nameGuest.value;
		
		$nameGuest.onfocus = function() {
			if($nameGuest.value == 'Nome_' || $nameGuest.value == 'Name_') {
				$nameGuest.value = '';
			}
		}
		$nameGuest.onblur = function() {
			if($nameGuest.value == '') {
				$nameGuest.value = $nameVal;
			}
		}
		
		$emailGuest.onfocus = function() {
			if($emailGuest.value == 'Email_') {
				$emailGuest.value = '';
			}
		}
		$emailGuest.onblur = function() {
			if($emailGuest.value == '') {
				$emailGuest.value = 'Email_';
			}
		}
	}
	
	////////////////////////////////////////////////////////////////////
	
	// Adicionar classe c1 - clientes; Efeito clientes
	if($clientes.length) {
		$clientes.find('section:nth-child(3n-2)').addClass('c1');
		
		$clientes.find('section').mouseenter(function(){
			var $this = $(this);
			var $logo = $this.find('.logoCliente');
			var $desc = $this.find('.descCliente');
			
			$logo.filter(':not(:animated)').fadeOut('fast');
			$desc.filter(':not(:animated)').fadeIn();
		});
		
		$clientes.find('section').mouseleave(function(){
			var $this = $(this);
			var $logo = $this.find('.logoCliente');
			var $desc = $this.find('.descCliente');
			
			$desc.fadeOut('fast');
			$logo.fadeIn();
		});
		
		showItens($clientes, 'section', 300);
	}
	
	////////////////////////////////////////////////////////////////////
	
	// Voltar topo
	$('#voltarTopo').click(function(){
		$('body, html').animate({scrollTop: 0});
		
		return false;
	});
	
	////////////////////////////////////////////////////////////////////
	
	// Projetos	
	if($projeto.length && $projetoExtendido.length) {
		// Animação para projetos
		showItens($projetoExtendido, 'section', 300);
		
		////////////////////////////////////////////////////////////////////
		
		$('#projetosCircle').find('a').click(function(){
			var $this = $(this);
			var $href = $this.attr('href');
			var $id = $this.data('id');
			
			var $cookie = document.cookie = 'case' + '-' + $id + '=' + 'visited' + '; path=/';
			
			if($cookie) {
				if($('.wrap-facebook').length) {
					window.open($href);
				}
				else {
					document.location = $href;
				}
			}
			
			return false;
		});
		
		////////////////////////////////////////////////////////////////////
		
		// Reduzir e Expandir Projetos
		$('#reduzirProjeto').click(function(){
			$projetoExtendido.filter(':not(:animated)').slideUp();
			
			return false;
		});
		
		$('#expandirProjeto').click(function(){
			$projetoExtendido.filter(':not(:animated)').slideDown();
			
			return false;
		});
		
		// Adicionar classes box trabalhe conosco
		$('.wrap #projeto #projetoExtendido').find('section:nth-child(4n-2)').addClass('secondBox');
		$('.wrap #projeto #projetoExtendido').find('section:nth-child(4n-1)').addClass('thirdBox');
		
		$('.wrap-facebook #projeto #projetoExtendido').find('section:nth-child(2n+0)').addClass('secondBox-facebook');
		

	}
	
	////////////////////////////////////////////////////////////////////
	
	// Hover home e projetos
	if($projetoExtendido.length) {
		/*
		 * Hover cases
		 */
		$projetoExtendido.find('section').hover(function(){
			var $this = $(this);
			var $top = $this.find('.caseTop');
			var $bottom = $this.find('.caseBottom');
			var $bg = $this.find('.caseBackground');
			
			
			$bg.filter(':not(:animated)').fadeIn('fast');
			$bottom.stop().animate({ 'bottom': '-80px'}, 'fast');
			$top.stop().animate({ 'top': '0px'}, 'fast');
			
		}, function(){
			var $this = $(this);
			var $top = $this.find('.caseTop');
			var $bottom = $this.find('.caseBottom');
			var $bg = $this.find('.caseBackground');
			
			$bg.fadeOut();
			$bottom.stop().animate({ 'bottom': '-200px'});
			$top.stop().animate({ 'top': '-200px'});
		});
		
		// Adiciona links na section
		$projetoExtendido.find('section').click(function(){
			var $this = $(this);
			var $id = $this.attr('id');
			var $link = $this.find('a').attr('href');
			
			var $cookie = document.cookie = 'case' + '-' + $id + '=' + 'visited' + '; path=/';
			
			if($cookie) {
				if($('.wrap-facebook').length) {
					window.open($link);
				}
				else {
					document.location = $link;
				}
			}
			
			return false;
		});
	}
	
	////////////////////////////////////////////////////////////////////
	
	if($vagas.length){
		// Animação para vagas - trabalhe conosco
		showItens($vagas, 'section', 300);
		
		$('.wrap #vagas').find('section:nth-child(4n-2)').addClass('secondBox');
		$('.wrap #vagas').find('section:nth-child(4n-1)').addClass('thirdBox');
		
		$('.wrap-facebook #vagas').find('section:nth-child(2n+0)').addClass('secondBoxVagas-facebook');
	}
	
	////////////////////////////////////////////////////////////////////
	
	if($home.length) {
		$home.find('#header').fadeTo(500, 1, function(){
			$home.find('.garotaHome').fadeTo(1500, 1, function(){
				$home.find('#floatTeia').animate({'width':'100%'}, 1100, function(){
					$home.find('.translateHome, .detailsHome').fadeTo(550, 1, function(){
						$home.find('#menu').fadeTo(550, 1, function(){
							$home.find('#content').slideDown(700, function(){
								showItens($projetoExtendido, 'section', 300);
								$home.find('.linkMaisProjetos').fadeIn().css('display', 'block');
								$home.find('#footer').fadeTo(500, 1);
							});
						});
					});
				});
			});
		});
		
		$('#content #projetoExtendido').find('section:nth-child(2n+0)').addClass('secondBoxHome');
		
	}
});
