var next = 1;
var timeouts_slide= new Array();

function clear_slide_timeouts(){  
   for(key in timeouts_slide ){  
    	clearTimeout(timeouts_slide[key]);  
   }   
}  

function switch_step(cur,timeout) {

	var item	= $('.button').eq(cur);

	if(timeout == true) {
		next++;
	}
	else {
		next = cur + 1;
	}
	
	if(next == 7) {
		next = 0;
	}

	// hide all other 
	$('.button').removeClass('on left');
	$('.step-content').hide();
	
	//Switch button to on
	item.addClass('on');
	item.prev('.button').addClass('left');
	
	//Show slide
	$('.step-content').eq(cur).show();
	
	//IF THE SLIDE HAS A TIMEOUT THEN ADD IT
	if(timeout == true) {
		timeouts_slide['timeout'] = setTimeout("switch_step(" + next + ",true)",5000);
	}
	else {
		clear_slide_timeouts();
		timeouts_slide['timeout'] = setTimeout("switch_step(" + next + ",true)",5000);
	}
	
}

$(document).ready(function(){
	
	// Show first step
	$('.step-content').eq(0).show();
	$('.button').eq(0).addClass('on');
	
	// Click step
	$('.button').click(function(){
		var item = $(this).index('.button');
		switch_step(item,false);
	});
	
	
	//ONCE THE PAGE LOADS START TIMING OUT THE SLIDE
	timeouts_slide['timeout'] = setTimeout("switch_step(" + next + ",true)",5000);

});
