jQuery(function( $ ){
	//borrowed from jQuery easing plugin
	//http://gsgd.co.uk/sandbox/jquery.easing.php
	$.easing.elasout = function(x, t, b, c, d) {
		var s=0.58;var p=0;var a=c;
		if (t==0) return b;  if ((t/=d)==1) return b+c;  if (!p) p=d*.3;
		if (a < Math.abs(c)) { a=c; var s=p/4; }
		else var s = p/(2*Math.PI) * Math.asin (c/a);
		return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b;
	};	
	
	
	
	/***********   Código que hace deslizar la página    ******************************/

	$("#enlace_moto,#enlace_pueblo,#boton_bio,#boton_palmares,#boton_equipo,#boton_contratacion,#boton_contacto,#enlace_palmares_detallado,#enlace_directo_info,#enlace_directo_info_2,#enlace_directo_info_3,#enlace_directo_contacto,#enlace_directo_contacto_desde_contratacion").click(function(){	      
		var $c = $("#content"); 
		
		if($("#seccion").val() == "ex_centro")
			var numero = "0";				
		else if($("#seccion").val() == "ex_moto")
			var numero = "1";
		else if($("#seccion").val() == "ex_pueblo")
			var numero = "2";			
		else if($("#seccion").val() == "bio")
			var numero = "3";				
		else if($("#seccion").val() == "palmares")
			var numero = "4";		
		else if($("#seccion").val() == "palmaresdetalle")
			var numero = "5";			
		else if($("#seccion").val() == "equipo")
			var numero = "6";	
		else if($("#seccion").val() == "contratacion")
			var numero = "7";	
		else if($("#seccion").val() == "contacto")
			var numero = "8";
		
	     		
		$c.stop().scrollTo('h2:eq('+numero+')', {speed:500, easing:'elasout',axis:$c.attr('id')});
	});
	
	 /* Necesario para cuadrar el contenido ya que hay espacios para conseguir un rebote suave en las secciones de los extremos
	 $(document).ready(function() {
		var $c = $("#content");	
          $("#content").scrollTo('h2:eq(0)', {speed:500, easing:'elasout',axis:$c.attr('id')});
	    alert("Todo bien..");
      }); 					*/
	
	/*$("#boton_bio").click(function(){//this is not the cleanest way to do this, I'm just keeping it short.
		
		var index = parseInt( $(this).prev('input').val() ) || 0;
		index = 3;		
		var $c = $("#content");//$(this).parent().next();
		//	$(document.body).css( "background", "black" );
		//alert($("#content").attr("id"));		
		alert("Boton bio vale: " + $("#seccion").val());
		$c.stop().scrollTo('h2:eq('+$("#seccion").val()+')', {speed:2500, easing:'elasout',axis:$c.attr('id')});
	}); */
	
	
});
