$(document).ready(function(){
	
/* Eventos de navegacao */
		
		$.history.init(function(hash){
				if(hash == "inicial") {
					$('html, body').animate({scrollTop : '0'}, 2000, 'easeInOutQuint', function(){ $('#setas div:nth-child(1)').fadeIn(500); });
				}
				if(hash == "sobre") {
					$('html, body').animate({scrollTop : '1000px'}, 2000, 'easeInOutQuint', function(){ $('#setas div:nth-child(2)').fadeIn(500); });
				}
				if(hash == "portfolio") {
					$('html, body').animate({scrollTop : '2000px'}, 2000, 'easeInOutQuint', function(){ $('#setas div:nth-child(3)').fadeIn(500); });
					$('#portfolio-robo').animate({'margin-top' : '0'}, 1000,  'easeOutQuart');
					$('#content #area_portfolio div.direita').animate({'top' : '-150%'}, 1000,  'easeOutQuart');
				}
				if(hash == "portfolio-web") {
					portfolio_visualizacao('web');
				}
				if(hash == "portfolio-animacao") {
					portfolio_visualizacao('animacao');
				}
				if(hash == "portfolio-ilustracao") {
					portfolio_visualizacao('ilustracao');
				}
				if(hash == "contato") {
					$('html, body').animate({scrollTop : '3000px'}, 2000, 'easeInOutQuint', function(){ $('#setas div:nth-child(4)').fadeIn(500); });
				}
		},{ unescape: ",/" });
		
		$(window).scroll(function(){
			
			troca_fundos();
			if($(window).scrollTop() <= 3000){
				$('#inicial-robo-braco').css({'margin-left': ((2750 + ($(window).scrollTop() * 5.5)) * -1) + 'px'});
				$('#content').css({'margin-left': ((2250 + ($(window).scrollTop() * 4.5)) * -1) + 'px'});
				$('#robos').css({'margin-left': ((1750 + ($(window).scrollTop() * 3.5)) * -1) + 'px'});
				$('#setas').css({'margin-left': ((1250 + ($(window).scrollTop() * 2.5)) * -1) + 'px'});
				
				$('#transicao-1').css({'margin-left': (2250 - ($(window).scrollTop() * 4.5)) + 'px'});
				$('#transicao-2').css({'margin-left': (6750 - ($(window).scrollTop() * 4.5)) + 'px'});
				$('#transicao-3').css({'margin-left': (11150 - ($(window).scrollTop() * 4.5)) + 'px'});
			}else{
				$('#inicial-robo-braco').css({'margin-left': '-19250px'});
				$('#content').css({'margin-left': '-15750px'});
				$('#robos').css({'margin-left': '-12250px'});
				$('#setas').css({'margin-left': '-8750px'});
			}
			
		});
		
		$('#nav h1 a, #nav ul li a, a.navegacao').click(function(){
			$.history.load(endereco(this.href));
			return false;
		});
		
/* Galeria na página inicial */

		$('#content #area_inicial a:nth-child(2), #content #area_inicial a:nth-child(3)').click(function(){
			galeria_inicial( endereco(this.href) );
			return false;
		});
		
		$('#ultimos div ul li a').hover(function(){
			$('img', this).animate({'margin-top': '20px'}, {duration: 200, queue: false},  'easeOutQuart');
		},function(){
			$('img', this).animate({'margin-top': '0'}, {duration: 200, queue: false},  'easeOutQuart');
		});
		
		$('#ultimos .fechar a, #ultimos div ul li a').click(function(){
			galeria_fechar();
			if(endereco(this.href) == ''){ return false; }
		});
		
/* Portfolio - rolagem entre os cases */

	$('#area_portfolio a.esquerda, #area_portfolio a.direita').click(function(){
		if(endereco(this.href) == 'e'){  sinal = '-'; }else{  sinal = '+'; }
		$('#content #area_portfolio div.direita div:nth-child(1)').animate({scrollTop : sinal + '=500px'}, 1000, 'easeInOutQuint');
		return false;
	});
		
/* Portfolio - Ilustracao */
		
	$(".fancybox").fancybox({
		openEffect	: 'none',
		closeEffect	: 'none'
	});
		
/* Portfolio - Animacoes */
		
	$(".various").fancybox({
		maxWidth	: 800,
		maxHeight	: 600,
		fitToView	: false,
		width		: '70%',
		height		: '70%',
		autoSize	: false,
		closeClick	: false,
		openEffect	: 'none',
		closeEffect	: 'none'
	});
		
		
/* Contato */

	$('.campos').click(function(){ if (this.value == this.defaultValue){ this.value = ''; }});
	$('.campos').blur(function(){ if (this.value == ''){ this.value = this.defaultValue; }});
		
});
