var initList = initList || []; 

initList.push(function(){

	$(".content_nav").each(
		function(){
			var content=$(this);

			var buttons = $(".buttons");
			var sections =content.find(" .sections");
			var steps = content.find(" #steps");
		    var stage = 1;
		    var num_sections = sections.children().length;
		    var width_sections = sections.find('li').outerWidth(true);
			var time_factor = 1.5 * width_sections;

			buttons.click(function(){
					content.find(" > .controls > span").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();
								}
								content.find(" .controls > span:nth-child(" + stage + ")").addClass("active");
					    	});		
					    });			

			  });


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

			    stage = index + 1;
				content.find(" .controls > span").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();
								}
								content.find(" > .controls > span:nth-child(" + stage + ")").addClass("active");
								steps.removeClass().addClass("paso"+stage);
					    	});		
					    });
			})

		}
	);

	

});

