$(document).ready(function(){
	rollovers()
	form_clientes()
	processo()
	
		/*
	$('nav').mouseenter(function(){
		mostra()
	})
	
	$('#bt-menu').mouseenter(function(){
		mostra()
	})
	
	$('nav').mouseleave(function(){
		volta()
	})
	*/
var timeout,
    delay = 200;

$('nav').mouseenter(function () {
    if (timeout) window.clearTimeout(timeout);
    timeout = window.setTimeout(function(){
            mostra();
        
    }, delay);
});

$('#bt-menu').mouseenter(function () {
    if (timeout) window.clearTimeout(timeout);
    timeout = window.setTimeout(function(){
            mostra();
        
    }, delay);
});

$('nav').mouseleave(function () {
    if (timeout) window.clearTimeout(timeout);
    timeout = window.setTimeout(function(){
        volta();
        
    }, delay);
})

	
	  getTwitters('tweet-container', { 
	  id: 'bardari', 
	  count: 1, 
	  onTimeoutCancel: true,
	  onTimeout: function() {
	  alert('Não possível completar a requisição. Tente mais tarde')
	  },
	  enableLinks: true, 
	  ignoreReplies: true, 
	  lang: 'pt-br',
	  template: '<h3> "%text%" <em>%time%<em></h3>'
	  
	  });
	
	
	$("#ul-projetos-recentes li a").fancybox({'titlePosition'  : 'inside'}  );
	$("#ul-todos-projetos li a").fancybox( {'titlePosition'  : 'inside'} );
	
	
	
	
})

/********** Navegação ****************/
function mostra(){
		
	
		$('header').clearQueue().stop().animate({
			top: '0px'
		},500,'easeOutExpo',ativaNav())
			
		$('#sc-content').clearQueue().stop().animate({
			paddingTop: '280px'
		},500,'easeOutExpo')
		
			
		
}

function volta(){
	
		$('header').clearQueue().stop().animate({
			top: '-164px'
		},500,'easeOutExpo')	
		
		$('#sc-content').clearQueue().stop().animate({
			paddingTop: '116px'
		},500,'easeOutExpo')	

}


function ativaNav(){
		$("nav ul").each(function(i){
			$(this).css("display", "block");

		});
	}
function desativaNav(){
		$("nav ul").each(function(i){
			$(this).css("display", "none");
		});
	}	
	



/**********   Rollovers    ***************/
	function rollovers(){
	$('#ul-projetos-recentes li a').mouseenter(function (){ 
			$('#ul-projetos-recentes li a').clearQueue()
			$(this).animate({ backgroundColor: "#0099ff" },300)
	})
	
	$('#ul-projetos-recentes li a').mouseleave(function(){ 
			$('#ul-projetos-recentes li a').clearQueue()
			$(this).animate({	backgroundColor: "#efefef" },300)
	 
	})
	
	$('#ul-todos-projetos li a').mouseenter(function (){ 
			$('#ul-todos-projetos li a').clearQueue()
			$(this).animate({ backgroundColor: "#cccccc" },300)
	})
	
	$('#ul-todos-projetos li a').mouseleave(function(){ 
			$('#ul-todos-projetos li a').clearQueue()
			$(this).animate({	backgroundColor: "#efefef" },300)
	 
	})
}





/******* Processo ********/
function padroniza(){
	if(nova != 'div-processo-1'){
		$('#div-processo-1').css({
			'background-image':'url(imgs/bg-processo-first.png)',
			'width':'128px',
			'height':'153px',
			'top':'15px'			
		})
	}
	if(nova != 'div-processo-2'){
		$('#div-processo-2').css({
			'background-image':'url(imgs/bg-processo-first-2.png)',
			'height':'128px',
			'width':'153px',
			'right':'15px'
		})
	}
	if(nova != 'div-processo-3'){
		$('#div-processo-3').css({
			'background-image':'url(imgs/bg-processo-first-3.png)',
			'width':'128px',
			'height':'153px',
			'bottom':'15px'
		})
	}
	if(nova != 'div-processo-4'){
		$('#div-processo-4').css({
			'background-image':'url(imgs/bg-processo-first-4.png)',
			'height':'128px',
			'width':'153px',
			'left':'15px'
		})
	}
}

function some(esse){
	var arr = new Array('div-processo-1','div-processo-2','div-processo-3','div-processo-4')
	var arra = new Array('div-processo-text-1','div-processo-text-2','div-processo-text-3','div-processo-text-4')
	for(i in arr){
		if(esse == arr[i]){
			$('#'+arra[i]).fadeIn(1000) 
		}else(
			$('#'+arra[i]).css('display','none') 
		)
	}
	
//	div-processo-text-1

}

nova = 'div-processo-1' // variavel global que determina qual esta bg rosa inicia div-processo-1;
function processo (){
	$('#div-processo').find('a').mouseover(function(){
		padroniza()
		var id_ele = $(this).parent().attr('id')
			if(nova != id_ele && id_ele == 'div-processo-1'){
				$('#div-processo-1').css({
					'background-image':'url(imgs/bg-processo-hover.png)',
					'width':'128px',
					'height':'153px'
				})
			}
			if(nova != id_ele && id_ele == 'div-processo-2'){
				$('#div-processo-2').css({
					'background-image':'url(imgs/bg-processo-hover-2.png)',
					'height':'128px',
					'width':'153px'
				})
			}
			if(nova != id_ele && id_ele == 'div-processo-3'){
				$('#div-processo-3').css({
					'background-image':'url(imgs/bg-processo-hover-3.png)',
					'width':'128px',
					'height':'153px'
				})
			}
			if(nova != id_ele && id_ele == 'div-processo-4'){
				$('#div-processo-4').css({
					'background-image':'url(imgs/bg-processo-hover-4.png)',
					'height':'128px',
					'width':'153px'
				})
			}
			
			
	}).mouseout(function(){					
			padroniza()
	
	}).click(function(){
		var id_elea = $(this).parent().attr('id')
		
		nova = id_elea // variavel global que determina qual esta bg rosa
		padroniza()
		
			switch(id_elea){
				case 'div-processo-1':
					$('#div-processo-1').css({
						'background-image':'url(imgs/bg-processo-selected.png)',
						'height': '178px',
						'top':'-10px'
					}) 
					
					break;
				case 'div-processo-2':
					$('#div-processo-2').css({
						'background-image':'url(imgs/bg-processo-selected-2.png)',
						'width': '178px',
						'right':'-10px'
					})
					break;
				case 'div-processo-3':
					$('#div-processo-3').css({
						'background-image':'url(imgs/bg-processo-selected-3.png)',
						'height': '178px',
						'bottom':'-10px'
					})
					break;
				case 'div-processo-4':
					$('#div-processo-4').css({
						'background-image':'url(imgs/bg-processo-selected-4.png)',
						'width': '178px',
						'left':'-10px'
					})
					break;
			}
			some(id_elea)
			return false
	})

}

/***************** Form Control *************/	
function chama_form(){
	
	$('#divForm').css('display','block')
	document.getElementById('nome').value = ""
	document.getElementById('tel').value = ""
	document.getElementById('email').value = ""
	document.getElementById('msg').value = ""
	var alter = document.getElementById('divResultado')
	alter.innerHTML = ''; 
}


function form_clientes(){
		$('#usuario').focus(function(){
			if($(this).val() == 'Login'){
				$(this).val('')
			}
		}).blur(function(){
			if($(this).val() == ''){
				$(this).val('Login')
			}
		})	
		
		$('#senha').focus(function(){
			if($(this).val() == 'Senha'){
				$(this).val('')	
				//document.getElementById('senha').type = 'password'
				
				var input=document.getElementById('senha');
				var input2= input.cloneNode(false);
				input2.type='password';
				input.parentNode.replaceChild(input2,input);
				
			}
		}).blur(function(){
			if($(this).val() == ''){
				$(this).val('Senha')
				//document.getElementById('senha').type = 'text'
				
			}
		})	
		
			
}
	 
 

i = 0;
$(window).scroll(function(){
		if($("body").scrollTop() >= 335 && i != 1){
			$('header').css('border-bottom','1px solid #ececec')
			i = 1
		}else if($("body").scrollTop() < 335){
			$('header').css('border-bottom','none')
			i = 0
		}
	})
	
	
function posicaoTela(posi){
	
	//Fecha todos os projetos , caso esteja aberto
	$('#ul-todos-projetos li').css('display','none')
	$('#sc-pct-projetos').css({"height":"0"})
	$('#bt-proj').text("ver mais projetos")
	
	$('html, body').animate({
   		 scrollTop: posi
	}, 1500,'easeInOutQuint');
	
}






/**********   Todos os projetos    ***************/
conta = 0
tam = 950
function todosProjetos(){
	
	if(conta == 0){
		
		$('#sc-pct-projetos').animate({	height: tam},1500,'easeInOutQuint',
	
			function(){
			$('#ul-todos-projetos').css('display','block')
			$('#ul-todos-projetos li').css('display','none')
			$('#ul-todos-projetos li').eachDelay(
				
						function(){

								$(this).fadeIn(); }, 80
						);
						
						
			
		})
		setTimeout(function(){ 
					$('#bt-proj').text("mostrar apenas projetos recentes")
				},500);
		
		$('html, body').animate({
   		 scrollTop: 340
	}, 1500,'easeInOutQuint');
		conta = 1
		
	}else{
			
			
			$('#ul-todos-projetos li').each(
				
						function(){

								$(this).fadeOut(); }
						)
		
			setTimeout(function(){ 
					$('#sc-pct-projetos').animate({height:0},1000,'easeInOutQuint') 
					$('#bt-proj').text("ver mais projetos")
				},500);
		
		$('html, body').animate({
   		 scrollTop: 340
	}, 1500,'easeInOutQuint');
		
		conta = 0
	}
}

// verifica se os campos foram preenchidos
function validaForm(){
	var nome = $('#nome').val()
	var tel = $('#tel').val()
	var email = $('#email').val()
	var msg = $('#msg').val()
	exp = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/
	var aa = 0
	if(nome.length <= 0){
		$('#nome').focus()
		$('#cnome').css('visibility','visible')
		aa++
		return false
	}
	
	else if(!exp.test(email)){
		$('#email').focus()
		$('#cemail').css('visibility','visible')
		aa++
		return false
	}
	else if(msg.length <= 0){
		$('#msg').focus()		
		$('#cmsg').css('visibility','visible')
		aa++
		return false
	}
	
	if(aa == 0){
		return true
	}
	
}


//mascaras

function mascara(o,f){
    v_obj=o
    v_fun=f
    setTimeout("execmascara()",1)
}

function execmascara(){
    v_obj.value=v_fun(v_obj.value)
}

function telefone(v){
    v=v.replace(/\D/g,"")                
    v=v.replace(/^(\d\d)(\d)/g,"($1) $2")
    v=v.replace(/(\d{4})(\d)/,"$1-$2")
    return v
}


