var initList = initList || []; 

initList.push(function(){

	var buttons = $(".content_nav .buttons");
	var sections = $(".content_nav .sections");
	var steps = $(".content_nav #steps");
	var carrito = $(".content_nav #carrito");
    var stage = 1;
    var num_sections = sections.children().length;
    var width_1 = 0;
    if ( sections.attr("data-sg-width") )
    	width_1 = parseInt(sections.attr("data-sg-width"));
    else
    	width_1 = 1210;
    var width_sections = width_1 + parseInt(sections.children().css("marginRight") )  + parseInt(sections.children().css("marginLeft") );
	var time_factor = 1.5 * width_sections;

	buttons.click(function(){
			$(".content_nav > .controls > span").removeClass("active");
			var variation;
			var timeStop = 0;

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

			$(this).fadeOut(50,
				function(){ 

					if(stage == 2){
						timeStop = 1400;
						$("#semaforo span").removeClass();
						$("#semaforo span:nth-child(2)").addClass("active");
						$(this).removeClass("ini").addClass("next");
						setTimeout(function() {					
							$('#semaforo span').removeClass();
							$('#semaforo span:nth-child(3)').addClass('active');			
							carrito.attr("src", "img/act2/parte2/SB_S_G10_U01_L03carroenmovimiento.gif");
						}, 1000);
					}else{
						timeStop = 0;
					}if ( sections.attr("data-sg-width") ){
						timeStop = 0;
					}


					$(".content_nav .poster").addClass("slideOutUp").removeClass("slideInDown").css("visibility", "hidden");
					$(".content_nav .clock").addClass("zoomOut").removeClass("zoomIn").css("opacity", 0);
					$(".content_nav .signal").addClass("fadeOutDown").removeClass("fadeInUp").css("opacity", 0);

					setTimeout(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();
							}else{
								$(".restart").fadeIn();
							}
							$(".content_nav .poster").removeClass("slideOutUp");
							$(".content_nav .clock").removeClass("zoomOut");
							$(".content_nav .signal").removeClass("fadeOutDown");

							carrito.attr("src", "img/act2/parte2/SB_S_G10_U01_L03carropara.gif");
							$(".content_nav .poster").addClass("slideInDown").removeClass("slideOutUp").css("visibility", "visible");
							$(".content_nav .clock").addClass("zoomIn").removeClass("zoomOut").css("opacity", 1);
							$(".content_nav .signal").addClass("fadeInUp").removeClass("fadeOutDown").css("opacity", 1);
							$(".content_nav > .controls > span:nth-child(" + stage + ")").addClass("active");
				    	});
			    	}, timeStop);		
			    });			

	  });

	$(".content_nav .restart").click(function(){
    	sections.css( "margin-left", 0);
    	buttons.first().removeClass("next").addClass("ini").fadeIn();
    	$("#semaforo span").removeClass();
		$("#semaforo span:nth-child(1)").addClass("active");  
		stage = 1;
    	$(this).fadeOut();
	})

	$(".content_nav .poster, .content_nav .clock, .content_nav .signal").addClass("animated");


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

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

});

