

	// JavaScript Document
	$(document).ready(function(){
		
			//Efeito de transiçao da pagina
			jQuery.easing.myease = function(a, curtime, startval, endval, totaltime){
					
					curtime = curtime / totaltime;
					var ret = 0;
					var amp = 1;
					var ts  = Math.pow(curtime,2);
					var tc  = Math.pow(curtime,3);
					var pos = startval + endval;
					
					//ret = Math.pow( curtime, 3 ) - curtime * amp * Math.sin(curtime * Math.PI);		//BACKEASE
					//ret = pos - Math.sqrt( 1 - Math.pow(curtime,2));		//CIRCLE
					//ret = pos * Math.pow(curtime,3);								//CUBIC
					//ret = pos * ((Math.exp( amp * curtime ) - 1) / (Math.exp(amp) - 1));		//Exponensial
					//ret = pos * (1 - Math.sin(1 - curtime) * (Math.PI / 2));  //SINE EASE, NAO SEI POR QUE DEU PAU
					
					//Volta, vai, para no centro e volta
					//ret = pos * ( 4.14754098360655*tc*ts + 5.639344262295083*ts*ts + -21.573770491803273*tc + 14.81967213114754*ts + -2.0327868852459017* curtime);
					
					//Volta, vai, passadireto e volta
					//ret = pos * (-10.440972222222229*tc*ts + 27.39583333333333*ts*ts + -30.31249999999999*tc + 17.22222222222222*ts + -2.864583333333333*curtime);
					
					//Volta, vai, para no meio, passadireto, volta
					ret = pos * (-51.97008547008547*tc*ts + 132.4145299145299*ts*ts + -118.03418803418803*tc + 42.47863247863248*ts + -3.888888888888889*curtime);
					
					return ret;
				};
			jQuery.easing.def = "myease";
			//jQuery.easing.def = "easeOutElastic";
			
			
			//variaveis usadas internamente
			$.dHeight = 0;
			var idLast  = "";
			
			//Seta a posicao inicial, quando abre a pagina
			setPos();
			
			//Funçao que ajusta a div principal ao tamanho da janela	
			$(window).resize( function(){ 
					
					//$(".main").css("height", ($(window).height() - 123)+ "px");
					
					$("div.main").css( "height", "1px" );
					
					if( ($(window).height() - 10 ) >  $.dHeight){
						$("div.main").css( "height", ($(window).height() - 10) + "px" );
					} else {
						$("div.main").css( "height", ($.dHeight + 80) + "px" );
					}
					
				});
		
			
			//Botões de movimento da tela
			$(window).hashchange( function(){
					
					try{
						$( $.closeID ).click();
					} catch(e){}
					
					var duracao = 2000;
					var base    = 5000;    //Valor usado como base de calculo
					var dest    = location.hash.replace("#","").replace("!","").replace("/","");
					
					//Marca o evento no google analytics
					trackEvent( "hashChange", location.hash );
					trackPageView( location.hash );
					
					
					if( dest.length <= 0 ){
						dest = "home";
					}
					
					var dPos    = $("#" + dest).position();
					var cPos    = $(".container").position();
					var top     = 0;
					var left    = 0;
					
					if( !dest.replace(" /g","").length > 0 ){
						return false;
					}
									
					idLast = dest;
					moveRec( true );
					removeShared();
					
						
					
					function moveRec( l ){
						
						 var n;
						 var top;
						 var left;
						 
						 cPos = $("div.container").position();
						 
						 
						 //Primeiro passo, move para cima
						 if( Math.abs( cPos.left ) != dPos.left && l ){
							 
							 n = (Math.abs( cPos.top ) / base) * duracao;
							 $("div.container").animate({ top: 0 }, n,function(){ moveRec( false ); refreshMain( dPos, dest ); });
						 
						 
						 //Segundo passo, move na horizontal
						 } else if( Math.abs( cPos.left ) != dPos.left ){
							 
							 left = Math.abs( cPos.left ) - dPos.left;
							 n    = (Math.abs(left) / base) * duracao;
							 $("div.container").animate({ left: (left > 0 ? "+=" : "-=") + Math.abs( left ) },n, function(){ moveRec( false ); refreshMain( dPos, dest ); });
						 
						 //Terceiro passo, move para baixo, se nescessario
						 } else if( Math.abs( cPos.top ) != (dPos.top - 110) ) {
							 
							 top = Math.abs( cPos.top ) - (dPos.top - 110);
							 n   = (Math.abs(top) / base) * duracao * 2;
							 $("div.container").animate({ top: (top > 0 ? "+=" : "-=") + Math.abs( top ) },n, function(){ refreshMain( dPos, dest ); });
							 
						 }
						 
						 
					}
					
				});
				
			
				
			//Botão de fechar a barra do blog
			$(".button.close").bind( "click.freela",function( evt ){
					evt.preventDefault();
					$(".footer").animate({height: "-=34"}, 1000,function(){ $(".footer .posts").remove(); });
					$(this).fadeOut(500,function(){ $(this).remove(); });
				});
			
			
			
			//Botão que extende a tela
			$(".button.more a").bind( "click.freela", function( evt ){
					
					evt.preventDefault();
					
					var dest   = $(this).attr("dest");
					var id     = $(this).attr("base");
					var pos    = $("#" + id + " ." + dest).position();
					var height = $("#" + id + " ." + dest).height() + pos.top;
					
					
					if( $(this).attr('oldsize') > 0 ){
						
						$(this).html($(this).html().replace("less.png","more.png"));
						height = parseInt( $(this).attr('oldsize') ) - 25;
						$(this).removeAttr('oldsize');
						
					} else {
						
						//Marca o evento no google analytics
						trackEvent( "readMore", id );
						$(this).html($(this).html().replace("more.png","less.png"));
						$(this).attr('oldsize',$('#' + id).height());
						
					}
					
					$("#" + id).animate({ height: height + 25 },1000, function(){
							$.dHeight = height + $(this).offset().top + 210;
							$(window).resize();
						});
				});
			
			
			
			//Botão que faz o blog abrir.
			$(".button.blog").bind("click", function( evt ){
					evt.preventDefault();
					
					//Marca o evento no google analytics
					trackEvent( "open", "blog" );
					
					abrirBlog("http://blog.agenciafreela.com.br");
				});
			
			
			//Botões de next e preview que faz a tela girar entre os cursores
			$(".button.prev").bind( "click", function(evt){ evt.preventDefault(); move( 2 ); });
			$(".button.next").bind("click", function(evt){ evt.preventDefault(); move( 1 ); });
			
			
			//Cuida do efeit hover dos botões de interacao	
			$(".button.next img, .button.prev img").mouseenter(function(){
					$(this).attr("src",$(this).attr("src").replace("_off","_on"));
				}).mouseleave(function(){
						$(this).attr("src",$(this).attr("src").replace("_on","_off"));
					});
		
		});
	
	
	
	
	
	
	
	
	
