// JavaScript Document

	//Define a posicao atual e move a tela para o proximo(ou anterior) item do menu
	function move( n ){
		
		var home      = $("#home").position().left;
		var trabalhos = $("#trabalhos").position().left;
		var contato   = $("#contato").position().left;
		var twitter   = $("#twitter").position().left;
		var container = Math.abs( $(".container").position().left );
		var slide     = new Array();
		
		
		slide[0] = new Array(home     , "trabalhos", "twitter"   ,"home")
		slide[1] = new Array(trabalhos, "contato"  , "home"      ,"trabalhos")
		slide[2] = new Array(contato  , "twitter"  , "trabalhos" ,"contato" )
		slide[3] = new Array(twitter  , "home"     , "contato"   ,"twitter")
		
		for( var c = 0; c < slide.length; c++ ){
			
			if( slide[c][0] == container ){
				
						
				//Marca o evento no google analytics
				trackEvent( (n == 1 ? "preview" : "next" ), slide[c][3] );
				
				document.location = "#!/" + slide[c][n];
				return;
			}
			
		}
		
	}
	
	
	
	//Define a posicao da div de conteudo, dependendo da url aberta
	function setPos(){
		
		if( location.hash.length > 0 ){
		
			var dest = location.hash.replace("#","").replace("!","").replace("/","");
			var dPos = $("#" + dest).position();
			$(".container").css({ left: -dPos.left, top: (-dPos.top) + 110});
			refreshMain( dPos, dest );

		}
		
		$(window).resize();
	}
	
	
	//Almenta ou diminui o tamanho do main para gerar ou remover o scroll da pagina e ser possivel visualizar todo o conteudo
	function refreshMain( dPos, dest ){
					
		//Se tiver chegado, ajusta o tamanho da tela.
		 cPos = $("div.container").position();
		 
		 if( Math.abs( cPos.top ) == (dPos.top - 110) && Math.abs( cPos.left ) == dPos.left ){
			 
			 $('html, body').animate({scrollTop:0}, 'slow');
			 $.dHeight = $("#" + dest).height() + 110;
			 $(window).resize();
			
		 }
		
	}
	
	
	//Funçao que abre o blog na pagina correta
	function abrirBlog(url){
		
		var height = $(window).height();
		
		jQuery.easing.def = "easeInOutCubic";
		
		$(".header, .main, .footer .center").fadeOut(1000);
		//$(".footer").append('<iframe src="' + url + '" name="frameblog" scrolling="auto" frameborder="no" align="center"></iframe>');
		//$(".footer iframe").hide().fadeIn(1000);
		$(".footer").animate( { height: height }, 1000, function(){
				
				document.location = url;
				//jQuery.easing.def = "easeInOutBounce";
				//$(".header, .main, .footer .center").remove();
				//$(window).resize( function(){
				//		$("div.footer").css( { height: $(window).height(), width: $(window).width() } );
				//	});
		
			});
		
	}
