$(document).ready(function(){
	
	$(document)[0].oncontextmenu = function() {return false;}
	
	//remove o title do menu superior
	$('#nav a').removeAttr('title');
	
	$('#header .social, #blog .compartilhar').css('opacity', 0.4);
	
	Cufon.replace('.sc', { hover: true, fontFamily: 'Nilland-SmallCaps' });
	Cufon.replace('.eb', { hover: true, fontFamily: 'Nilland-ExtraBold' });
	Cufon.replace('.f-b', { hover: true, fontFamily: 'Nilland-ExtraBold' });
	Cufon.replace('.f-n', { hover: true, fontFamily: 'Nilland-ExtraBold' });
	Cufon.replace('.ip, .cf-ol label, .sobre_texto h3', { hover: true, fontFamily: 'InterstatePlus' });

	$('#blog .post:last').addClass('last');
	
	//Abrir comentarios
	$('.compartilhar .comentarios a').click(function(event){
		event.preventDefault();
		//fecha o que estiver aberto
		$('.box-comentarios').css({display:'none', width: 0, height: $(window).height() - 20 }); //numero mágico soma da distancia top e bottom
		
		var idPost = $(this).closest('.post').attr('id');
		var larguraBoxComentarios = ( ( $(document).width() - $('#wrapper').width() ) / 2 ) + 333; 
		var distanciaLateral = ($(document).width() - $('#wrapper').width() ) / 2;
		
		if ( $(window).width() < $(document).width() ) {
			$('#wrapper').css('position','relative');
		}
		
		$('#comentarios_'+ idPost).css({ display: 'block', right: distanciaLateral }).animate({
			width: '333px'
		}, 1000);
	});

	//Fechar comentarios
	$('.box-comentarios .close').click(function(){
		$(this).closest('.box-comentarios').animate({
			width: 0
		}, 500, function() { $('.box-comentarios').css('display','none'); });
	});

	//Botão de Limpar comentarios
	$.fn.clearForm = function() {
		return this.each(function() {
			var type = this.type, tag = this.tagName.toLowerCase();
			if (tag == 'form'){ return $(':input',this).clearForm(); }
			if (type == 'text' || type == 'password' || tag == 'textarea') { this.value = ''; }
			else if (type == 'checkbox' || type == 'radio') { this.checked = false; }
			else if (tag == 'select') { this.selectedIndex = -1; }
		});
	};
	
	
	//listagem de posts animação
	$('.list_jobs li img').css('opacity', 0.5);
	$('.list_jobs li a.ip').hover(
	  function(){ $(this).children('img').animate({ opacity: 1 },100) }, 
	  function () { $(this).children('img').animate({ opacity: 0.5 },100) }
	);

	
	//inicia com o height correto da imagem atual
	$('.job-full_galeria_image').height( $('.job-full_galeria_image li.atual img').attr('height') );
	//esconde todas as outras imagens
	$('.job-full_galeria_image li:not(.atual) img').css('opacity','0');
	
	//clique na listagem dos thumbs
	$(".job-full_galeria-list img").live('click', function() {
		$('html,body').animate({scrollTop: $('.job-full_galeria').offset().top}, 500);
		if( $(this).attr('name') != $('.atual img').attr('name') ) {
			
			//captura a proxima imagem e altura
			var nextImg = $(this).attr('name');
			var nextImgHeight = $('.job-full_galeria_image img[name='+ nextImg +']').height();
			
			//ajusta altura da proxima imagem
			$('.job-full_galeria_image').animate({
				height: nextImgHeight
			},500);
			//esconde a imagem atual
			$('.job-full_galeria_image .atual img').animate({
				opacity: 0
			},500,function(){ $(this).parent().removeClass('atual'); });
			//mostra a proxima imagem
			$('.job-full_galeria_image img[name='+nextImg+']').animate({
				opacity: 1
			},500,function(){ $(this).parent().addClass('atual'); });
			
		}
	});
	
	$(".job-full_galeria_image .atual").live('click',function() {
	
		$('html,body').animate({scrollTop: $('.job-full_galeria').offset().top}, 500);
	
		if ($('.job-full_galeria_image li').size() > 1) { 

			var nextImg = $(this).next().children().attr('name');
			if ( nextImg == null ){
				var nextImg = $('.job-full_galeria_image li:first').children().attr('name');
			}
			var nextImgHeight = $('.job-full_galeria_image img[name='+ nextImg +']').height();
				
			$('.job-full_galeria_image').animate({
				height: nextImgHeight
			},500);
			$('.job-full_galeria_image .atual img').animate({
				opacity: 0
			},500,function(){ $(this).parent().removeClass('atual'); });
			$('.job-full_galeria_image img[name='+nextImg+']').animate({
				opacity: 1
			},500,function(){ $(this).parent().addClass('atual'); });
		} 
	});
	
});


