$(function(){
	
	$(document).ready(function(){
		
		//Logo rollover
		var twitter		= $('h1').data('twitter');
		var linkedin	= $('h1').data('linkedin');
		var dribbble	= $('h1').data('dribbble');
		var html		= '<div class="nav-logo">';
		html			+= '<a href="'+ twitter +'" target="_blank">Twitter</a>, ';
		html			+= '<a href="'+ linkedin +'" target="_blank">Linkedin</a>, ';
		html			+= '<a href="'+ dribbble +'" target="_blank">Dribbble</a>';
		html			+= '</div>';
		
		$('.title h1').append(html);
		$('.nav-logo').css({'opacity':0,'display':'block'});
		$('.title h1').hover(
			function(){
				$('.nav-logo').stop().animate({
					opacity: 1,
					top: '40',
				}, 200);
			},
			function(){
				$('.nav-logo').stop().animate({
					opacity: 0,
					top: '30',
				}, 200);
			}
		);
		
		//Main Nav rollover
		var n1		= $('.nav li.n-1 a').data('alt');
		var n2		= $('.nav li.n-2 a').data('alt');
		var n3		= $('.nav li.n-3 a').data('alt');
		
		$('.nav li.n-1').append('<p>'+ n1 +'</p>');
		$('.nav li.n-2').append('<p>'+ n2 +'</p>');
		$('.nav li.n-3').append('<p>'+ n3 +'</p>');
		
		$('.nav li p').css({'opacity':0,'display':'block'});
		$('.nav li a').hover(
			function(){
				$(this).parent().children('p').stop().animate({
					opacity: 1,
					top: '45',
				}, 200);
			},
			function(){
				$(this).parent().children('p').stop().animate({
					opacity: 0,
					top: '30',
				}, 200);
			}
		);
		
		//Projects rollover
		$('#featured-projects article figure a').append('<p class="study">Click and see the study</p>');
		$('#featured-projects p.study').css({'opacity':0,'display':'block'});
		$('#featured-projects article').children('figure').hover(
			function(){
				$(this).parent().find('a.title').css('color','#9b6ea8');
				$(this).parent().find('p.study').stop().animate({opacity:1}, 200);
			},
			function(){
				$(this).parent().find('a.title').css('color','#999');
				$(this).parent().find('p.study').stop().animate({opacity:0}, 200);
			}
		);
		$('#featured-projects article').children('h2').hover(
			function(){
				$(this).parent().find('a.title').css('color','#9b6ea8');
				//$(this).parent().children('a.role').css('border-bottom','2px dashed #ccc');
				$(this).parent().find('p.study').stop().animate({opacity:1}, 200);
			},
			function(){
				$(this).parent().find('a.title').css('color','#999');
				//$(this).parent().children('a.role').css('border-bottom','none');
				$(this).parent().find('p.study').stop().animate({opacity:0}, 200);
			}
		);
		
		//Contact Mail encoding
		$('a.mail').attr('href','mailto:brunomarinho@gmail.com');
		$('a.mail').text('brunomarinho@gmail.com');
		
		//Facebook Like
		$('.fb-like').css({'opacity':0});
		$(window).scroll(function(){
		scrollPercentage = $(window).scrollTop() / ( $(document).height() - $(window).height() ); 
			if (scrollPercentage == 1) {
				$('.fb-like').stop().animate({bottom:'0',opacity:1},300, function(){$('.fb-like .arrow').animate({top:'31px'},300)});
			};
			if ($(window).scrollTop() < ($(document).height()-$(window).height())) {
				//$('.fb-like').css({'bottom':'-70px','opacity':0});
				//$('.fb-like .arrow').css({'top':'70px'});
				$('.fb-like').stop().animate({opacity:0},300,function(){
					$('.fb-like').css({'bottom':'-70px','opacity':0});
					$('.fb-like .arrow').css({'top':'70px'});	
				});
			};
		});
	});
	
});

function goToByScroll(id){
	$('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
	return false;
}
