var initList = initList || []; 

initList.push(function(){

	var buttons = $(".buttons");
	var sections = $(".sections");
	var steps = $("#steps");
    var stage = 1;
    var num_sections = sections.children().length;
    var width_sections = 1210 + parseInt(sections.children().css("marginRight") )  + parseInt(sections.children().css("marginLeft") );
    console.log(sections.children().css("width"));
	var time_factor = 1.5 * width_sections;

	buttons.click(function(){
			$(".content_nav > .controls > span").css("border-color", "#A6A9AA").removeClass("active");
			var variation;

			if ($(this).is(".last")){
				variation = "+=";
				stage--;
			}else{
				variation = "-=";
				stage++;		
			}

			$(this).fadeOut(50,
				function(){ 
			    	sections.animate({
			    		marginLeft: variation+width_sections
			    	}, time_factor, function(){
						steps.removeClass().addClass("paso"+stage);
						if (stage > 1) {
							buttons.last().fadeIn();
						}
						if (stage < num_sections) {
							buttons.first().fadeIn();
						}
						var color = $(".content_nav .sections li:nth-child("+ stage +") strong").css("color");
						$(".content_nav > .controls > span:nth-child(" + stage + ")").css("border-color", color).addClass("active");
			    	});		
			    });			

	  });


	$(".controls span").click(function(){
		var index = $(this).index();
		var margin = index * width_sections *-1;

	    stage = index + 1;
		$(".content_nav > .controls > span").css("border-color", "#A6A9AA").removeClass("active");
		$(".buttons").fadeOut(50,
				function(){ 
			    	sections.animate({
			    		marginLeft: margin
			    	}, time_factor, function(){
						if (stage > 1) {
							buttons.last().fadeIn();
						}
						if (stage < num_sections) {
							buttons.first().fadeIn();
						}
						var color = $(".content_nav .sections li:nth-child("+ stage +") strong").css("color");
						$(".content_nav > .controls > span:nth-child(" + stage + ")").css("border-color", color).addClass("active");
						steps.removeClass().addClass("paso"+stage);
			    	});		
			    });
	})

});

